From 964fdfcc445506efad8ffacbd8c9dbf93e14a683 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Wed, 20 Feb 2019 05:27:34 +0000 Subject: [PATCH] #2149 / #853: fix websocket handler with python3: don't use flush() or close(), 'only_upgrade' attribute lives in websocket handler (so can't be used in do_HEAD of http handler), websocket handler now delegates to superclass methods rather than duplicating some of the code git-svn-id: https://xpra.org/svn/Xpra/trunk@21737 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/net/websockets/handler.py | 21 +++++++++------------ src/xpra/server/http_handler.py | 11 +---------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/xpra/net/websockets/handler.py b/src/xpra/net/websockets/handler.py index 91cc369cb2..bbc7ceceee 100644 --- a/src/xpra/net/websockets/handler.py +++ b/src/xpra/net/websockets/handler.py @@ -56,7 +56,6 @@ def handle_websocket(self): ): self.wfile.write(b"%s\r\n" % upgrade_string) self.wfile.flush() - self.wfile.close() self.new_websocket_client(self) def do_GET(self): @@ -64,8 +63,6 @@ def do_GET(self): if self.only_upgrade or upgrade_requested: if not upgrade_requested: self.send_error(403, "only websocket connections are allowed") - self.wfile.flush() - self.wfile.close() return try: self.handle_websocket() @@ -74,17 +71,17 @@ def do_GET(self): log.error("Error: cannot handle websocket upgrade:") log.error(" %s", e) self.send_error(403, "failed to handle websocket: %s" % e) - self.wfile.flush() - self.wfile.close() return - self.handle_request() + HTTPRequestHandler.do_GET(self) + + def do_HEAD(self): + if self.only_upgrade: + self.send_error(405, "Method Not Allowed") + return + HTTPRequestHandler.do_HEAD(self) def handle_request(self): if self.only_upgrade: self.send_error(405, "Method Not Allowed") - else: - content = self.send_head() - if content: - self.wfile.write(content) - self.wfile.flush() - self.wfile.close() + return + HTTPRequestHandler.handle_request(self) diff --git a/src/xpra/server/http_handler.py b/src/xpra/server/http_handler.py index 11bda04683..dd62470fdf 100644 --- a/src/xpra/server/http_handler.py +++ b/src/xpra/server/http_handler.py @@ -183,16 +183,9 @@ def handle_request(self): content = self.send_head() if content: self.wfile.write(content) - self.wfile.flush() - self.wfile.close() def do_HEAD(self): - if self.only_upgrade: - self.send_error(405, "Method Not Allowed") - else: - self.send_head() - self.wfile.flush() - self.wfile.close() + self.send_head() #code taken from MIT licensed code in GzipSimpleHTTPServer.py def send_head(self): @@ -206,8 +199,6 @@ def send_head(self): path = self.translate_path(self.path) if not path: self.send_error(404, "Path not found") - self.wfile.flush() - self.wfile.close() return None if os.path.isdir(path): if not path.endswith('/'):