فهرست منبع

Sync with websockify.

Pull c33f0b52e7 from websockify.

- Fix for python2.4 with URL parsing.
- Set binaryType earlier in Opera 12.10 to avoid receiving a blob.
- Re-order client and target processing so that pending client data
  has an opportunity to be sent when the target closes.
Joel Martin 12 سال پیش
والد
کامیت
705c54edb6
3فایلهای تغییر یافته به همراه32 افزوده شده و 24 حذف شده
  1. 3 3
      include/websock.js
  2. 5 0
      utils/websocket.py
  3. 24 21
      utils/websockify

+ 3 - 3
include/websock.js

@@ -331,6 +331,9 @@ function open(uri, protocols) {
         websocket = {};
         websocket = {};
     } else {
     } else {
         websocket = new WebSocket(uri, protocols);
         websocket = new WebSocket(uri, protocols);
+        if (protocols.indexOf('binary') >= 0) {
+            websocket.binaryType = 'arraybuffer';
+        }
     }
     }
 
 
     websocket.onmessage = recv_message;
     websocket.onmessage = recv_message;
@@ -343,9 +346,6 @@ function open(uri, protocols) {
             mode = 'base64';
             mode = 'base64';
             Util.Error("Server select no sub-protocol!: " + websocket.protocol);
             Util.Error("Server select no sub-protocol!: " + websocket.protocol);
         }
         }
-        if (mode === 'binary') {
-            websocket.binaryType = 'arraybuffer';
-        }
         eventHandlers.open();
         eventHandlers.open();
         Util.Debug("<< WebSock.onopen");
         Util.Debug("<< WebSock.onopen");
     };
     };

+ 5 - 0
utils/websocket.py

@@ -941,6 +941,11 @@ Sec-WebSocket-Accept: %s\r
                 if startsock:
                 if startsock:
                     startsock.close()
                     startsock.close()
 
 
+        # Close listen port
+        self.vmsg("Closing socket listening at %s:%s"
+                % (self.listen_host, self.listen_port))
+        lsock.close()
+
 
 
 # HTTP handler with WebSocket upgrade support
 # HTTP handler with WebSocket upgrade support
 class WSRequestHandler(SimpleHTTPRequestHandler):
 class WSRequestHandler(SimpleHTTPRequestHandler):

+ 24 - 21
utils/websockify

@@ -14,8 +14,11 @@ as taken from http://docs.python.org/dev/library/ssl.html#certificates
 import signal, socket, optparse, time, os, sys, subprocess
 import signal, socket, optparse, time, os, sys, subprocess
 from select import select
 from select import select
 import websocket
 import websocket
-try:    from urllib.parse import parse_qs, urlparse
-except: from urlparse import parse_qs, urlparse
+try:
+    from urllib.parse import parse_qs, urlparse
+except:
+    from cgi import parse_qs
+    from urlparse import urlparse
 
 
 class WebSocketProxy(websocket.WebSocketServer):
 class WebSocketProxy(websocket.WebSocketServer):
     """
     """
@@ -205,7 +208,7 @@ Traffic Legend:
         # Extract the token parameter from url
         # Extract the token parameter from url
         args = parse_qs(urlparse(path)[4]) # 4 is the query from url
         args = parse_qs(urlparse(path)[4]) # 4 is the query from url
 
 
-        if not len(args['token']):
+        if not args.has_key('token') or not len(args['token']):
             raise self.EClose("Token not present")
             raise self.EClose("Token not present")
 
 
         token = args['token'][0].rstrip('\n')
         token = args['token'][0].rstrip('\n')
@@ -249,6 +252,24 @@ Traffic Legend:
             ins, outs, excepts = select(rlist, wlist, [], 1)
             ins, outs, excepts = select(rlist, wlist, [], 1)
             if excepts: raise Exception("Socket exception")
             if excepts: raise Exception("Socket exception")
 
 
+            if self.client in outs:
+                # Send queued target data to the client
+                c_pend = self.send_frames(cqueue)
+
+                cqueue = []
+
+            if self.client in ins:
+                # Receive client data, decode it, and queue for target
+                bufs, closed = self.recv_frames()
+                tqueue.extend(bufs)
+
+                if closed:
+                    # TODO: What about blocking on client socket?
+                    self.vmsg("%s:%s: Client closed connection" %(
+                        self.target_host, self.target_port))
+                    raise self.CClose(closed['code'], closed['reason'])
+
+
             if target in outs:
             if target in outs:
                 # Send queued client data to the target
                 # Send queued client data to the target
                 dat = tqueue.pop(0)
                 dat = tqueue.pop(0)
@@ -273,24 +294,6 @@ Traffic Legend:
                 self.traffic("{")
                 self.traffic("{")
 
 
 
 
-            if self.client in outs:
-                # Send queued target data to the client
-                c_pend = self.send_frames(cqueue)
-
-                cqueue = []
-
-
-            if self.client in ins:
-                # Receive client data, decode it, and queue for target
-                bufs, closed = self.recv_frames()
-                tqueue.extend(bufs)
-
-                if closed:
-                    # TODO: What about blocking on client socket?
-                    self.vmsg("%s:%s: Client closed connection" %(
-                        self.target_host, self.target_port))
-                    raise self.CClose(closed['code'], closed['reason'])
-
 
 
 def _subprocess_setup():
 def _subprocess_setup():
     # Python installs a SIGPIPE handler by default. This is usually not what
     # Python installs a SIGPIPE handler by default. This is usually not what