From 801482be6aede1db31f8ee661f470de7036cbdd4 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Tue, 3 Aug 2010 13:21:00 -0500 Subject: [PATCH] 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) --- utils/wsproxy.c | 5 +++++ utils/wsproxy.py | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/wsproxy.c b/utils/wsproxy.c index 2035dc57..2802f91c 100644 --- a/utils/wsproxy.c +++ b/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); diff --git a/utils/wsproxy.py b/utils/wsproxy.py index 389e175e..1abdce9f 100755 --- a/utils/wsproxy.py +++ b/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("}")