Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit 6907496

Browse files
committed
esp8266/websocket_helper.py: Avoid extra string allocations.
1 parent f3636a7 commit 6907496

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

esp8266/scripts/websocket_helper.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,20 @@ def server_handshake(sock):
3636
if DEBUG:
3737
print("Sec-WebSocket-Key:", webkey, len(webkey))
3838

39-
respkey = webkey + b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
40-
respkey = hashlib.sha1(respkey).digest()
39+
d = hashlib.sha1(webkey)
40+
d.update(b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
41+
respkey = d.digest()
4142
respkey = binascii.b2a_base64(respkey)[:-1]
43+
if DEBUG:
44+
print("respkey:", resp)
4245

43-
resp = b"""\
46+
sock.send(b"""\
4447
HTTP/1.1 101 Switching Protocols\r
4548
Upgrade: websocket\r
4649
Connection: Upgrade\r
47-
Sec-WebSocket-Accept: %s\r
48-
\r
49-
""" % respkey
50-
51-
if DEBUG:
52-
print(resp)
53-
sock.send(resp)
50+
Sec-WebSocket-Accept: """)
51+
sock.send(respkey)
52+
sock.send("\r\n\r\n")
5453

5554

5655
# Very simplified client handshake, works for MicroPython's

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy