summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/scripts/websocket_helper.py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-06-30 00:02:45 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-06-30 00:02:45 +0300
commit69074960168970979769fa227dfd928189eaf062 (patch)
treeb0e44ef651ea22a4b6d7ce478ff69e1090eec55b /esp8266/scripts/websocket_helper.py
parentf3636a7b46942b7141d75214015a00a4c4aa21d6 (diff)
downloadmicropython-69074960168970979769fa227dfd928189eaf062.tar.gz
micropython-69074960168970979769fa227dfd928189eaf062.zip
esp8266/websocket_helper.py: Avoid extra string allocations.
Diffstat (limited to 'esp8266/scripts/websocket_helper.py')
-rw-r--r--esp8266/scripts/websocket_helper.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/esp8266/scripts/websocket_helper.py b/esp8266/scripts/websocket_helper.py
index 22ac28592d..4c388a028b 100644
--- a/esp8266/scripts/websocket_helper.py
+++ b/esp8266/scripts/websocket_helper.py
@@ -36,21 +36,20 @@ def server_handshake(sock):
if DEBUG:
print("Sec-WebSocket-Key:", webkey, len(webkey))
- respkey = webkey + b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
- respkey = hashlib.sha1(respkey).digest()
+ d = hashlib.sha1(webkey)
+ d.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
+ respkey = d.digest()
respkey = binascii.b2a_base64(respkey)[:-1]
+ if DEBUG:
+ print("respkey:", resp)
- resp = b"""\
+ sock.send(b"""\
HTTP/1.1 101 Switching Protocols\r
Upgrade: websocket\r
Connection: Upgrade\r
-Sec-WebSocket-Accept: %s\r
-\r
-""" % respkey
-
- if DEBUG:
- print(resp)
- sock.send(resp)
+Sec-WebSocket-Accept: """)
+ sock.send(respkey)
+ sock.send("\r\n\r\n")
# Very simplified client handshake, works for MicroPython's