Ticket #2104: websockify-new-import.patch
File websockify-new-import.patch, 3.6 KB (added by , 2 years ago) |
---|
-
xpra/server/websocket.py
20 20 21 21 WEBSOCKIFY_NUMPY = envbool("XPRA_WEBSOCKIFY_NUMPY", False) 22 22 log("WEBSOCKIFY_NUMPY=%s", WEBSOCKIFY_NUMPY) 23 def import_websockify_request_handler(): 24 import websockify 25 assert websockify 26 try: 27 #websockify 0.8.0 and earlier: 28 from websockify.websocket import WebSocketRequestHandler #@UnusedImport 29 except ImportError: 30 from websockify.websocketserver import WebSocketRequestHandler #@UnusedImport 31 return WebSocketRequestHandler 23 32 if WEBSOCKIFY_NUMPY: 24 from websockify.websocket import WebSocketRequestHandler #@UnusedImport33 WebSocketRequestHandler = import_websockify_request_handler() 25 34 else: 35 import warnings 26 36 from xpra.codecs.xor.cyxor import hybi_unmask 27 37 with nomodule_context("numpy"): 28 from websockify.websocket import WebSocketRequestHandler #@Reimport 29 def unmask(buf, hlen, plen): 30 pstart = hlen + 4 31 pend = pstart + plen 32 mask = buf[hlen:hlen+4] 33 data = buf[pstart:pend] 34 return hybi_unmask(mask, data) 35 WebSocketRequestHandler.unmask = staticmethod(unmask) 38 with warnings.catch_warnings(record=True) as w: 39 warnings.simplefilter("always") 40 WebSocketRequestHandler = import_websockify_request_handler() 41 def unmask(buf, hlen, plen): 42 pstart = hlen + 4 43 pend = pstart + plen 44 mask = buf[hlen:hlen+4] 45 data = buf[pstart:pend] 46 return hybi_unmask(mask, data) 47 WebSocketRequestHandler.unmask = staticmethod(unmask) 48 #print warnings except for numpy: 49 for x in w: 50 message = getattr(x, "message", None) 51 if message: 52 if str(message).find("numpy")>0: 53 log("numpy warning suppressed: %s", message) 54 else: 55 log.warn("Warning: %s", message) 56 else: 57 log.warn("Warning: %s", x) 36 58 59 37 60 WEBSOCKET_TCP_NODELAY = envbool("WEBSOCKET_TCP_NODELAY", True) 38 61 WEBSOCKET_TCP_KEEPALIVE = envbool("WEBSOCKET_TCP_KEEPALIVE", True) 39 62 WEBSOCKET_DEBUG = envbool("XPRA_WEBSOCKET_DEBUG", False) … … 177 200 and web server is enabled, SimpleHTTPRequestHandler.do_GET will be called. 178 201 """ 179 202 if not self.handle_websocket(): 180 if self.only_upgrade:203 if getattr(self, "only_upgrade", False): 181 204 self.send_error(405, "Method Not Allowed") 182 205 else: 183 206 content = self.send_head() … … 215 238 else: 216 239 #self.send_error(403, "Directory listing forbidden") 217 240 return self.list_directory(path).read() 218 ctype = self.guess_type(path)219 241 _, ext = os.path.splitext(path) 220 242 f = None 221 243 try: … … 225 247 f = open(path, 'rb') 226 248 fs = os.fstat(f.fileno()) 227 249 content_length = fs[6] 228 headers = { 229 "Content-type" : ctype, 230 } 250 headers = {} 251 ctype = None #self.guess_type(path) 252 if ctype: 253 headers["Content-type"] = ctype 231 254 accept = self.headers.get('accept-encoding', '').split(",") 232 255 accept = [x.split(";")[0].strip() for x in accept] 233 256 content = None