diff options
author | Damien George <damien.p.george@gmail.com> | 2017-09-06 13:40:51 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-09-06 13:40:51 +1000 |
commit | 01dd7804b87d60b2deab16712eccb3b97351a9b7 (patch) | |
tree | 1aa21f38a872b8e62a3d4e4f74f68033c6f827e4 /esp8266/modules/websocket_helper.py | |
parent | a9862b30068fc9df1022f08019fb35aaa5085f64 (diff) |
ports: Make new ports/ sub-directory and move all ports there.
This is to keep the top-level directory clean, to make it clear what is
core and what is a port, and to allow the repository to grow with new ports
in a sustainable way.
Diffstat (limited to 'esp8266/modules/websocket_helper.py')
-rw-r--r-- | esp8266/modules/websocket_helper.py | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/esp8266/modules/websocket_helper.py b/esp8266/modules/websocket_helper.py deleted file mode 100644 index 9c06db502..000000000 --- a/esp8266/modules/websocket_helper.py +++ /dev/null @@ -1,74 +0,0 @@ -import sys -try: - import ubinascii as binascii -except: - import binascii -try: - import uhashlib as hashlib -except: - import hashlib - -DEBUG = 0 - -def server_handshake(sock): - clr = sock.makefile("rwb", 0) - l = clr.readline() - #sys.stdout.write(repr(l)) - - webkey = None - - while 1: - l = clr.readline() - if not l: - raise OSError("EOF in headers") - if l == b"\r\n": - break - # sys.stdout.write(l) - h, v = [x.strip() for x in l.split(b":", 1)] - if DEBUG: - print((h, v)) - if h == b'Sec-WebSocket-Key': - webkey = v - - if not webkey: - raise OSError("Not a websocket request") - - if DEBUG: - print("Sec-WebSocket-Key:", webkey, len(webkey)) - - 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:", respkey) - - sock.send(b"""\ -HTTP/1.1 101 Switching Protocols\r -Upgrade: websocket\r -Connection: Upgrade\r -Sec-WebSocket-Accept: """) - sock.send(respkey) - sock.send("\r\n\r\n") - - -# Very simplified client handshake, works for MicroPython's -# websocket server implementation, but probably not for other -# servers. -def client_handshake(sock): - cl = sock.makefile("rwb", 0) - cl.write(b"""\ -GET / HTTP/1.1\r -Host: echo.websocket.org\r -Connection: Upgrade\r -Upgrade: websocket\r -Sec-WebSocket-Key: foo\r -\r -""") - l = cl.readline() -# print(l) - while 1: - l = cl.readline() - if l == b"\r\n": - break -# sys.stdout.write(l) |