瀏覽代碼

WebSockets orderly/clean close frame.

- When a packet with only '\xff\x00' is received, this means the
  client is doing an orderly shutdown. (WebSockets spec version 76)
Joel Martin 15 年之前
父節點
當前提交
801482be6a
共有 2 個文件被更改,包括 8 次插入1 次删除
  1. 5 0
      utils/wsproxy.c
  2. 3 1
      utils/wsproxy.py

+ 5 - 0
utils/wsproxy.c

@@ -169,6 +169,11 @@ void do_proxy(ws_ctx_t *ws_ctx, int target) {
             if (bytes <= 0) {
                 fprintf(stderr, "client closed connection\n");
                 break;
+            } else if ((bytes == 2) &&
+                       (tbuf_tmp[0] == '\xff') && 
+                       (tbuf_tmp[1] == '\x00')) {
+                fprintf(stderr, "client sent orderly close frame");
+                break;
             }
             if (recordfd) {
                 write(recordfd, "'", 1);

+ 3 - 1
utils/wsproxy.py

@@ -80,7 +80,9 @@ def do_proxy(client, target):
             buf = client.recv(buffer_size)
             if len(buf) == 0: raise Exception("Client closed")
 
-            if buf[-1] == '\xff':
+            if buf == '\xff\x00':
+                raise Exception("Client sent orderly close frame")
+            elif buf[-1] == '\xff':
                 if buf.count('\xff') > 1:
                     traffic(str(buf.count('\xff')))
                 traffic("}")