Last active
December 18, 2021 01:23
-
-
Save arseniyturin/0af811b7a81f1dda65a699675d900c74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handshake(frame, client): | |
headers = http_message.decode('utf8').split('\n') | |
for header in headers: | |
if header.startswith('Sec-WebSocket-Key'): | |
key = header.replace('Sec-WebSocket-Key:', '').strip() | |
accept_key = generate_accept_key(key) | |
response = ( | |
"HTTP/1.1 101 Switching Protocols\r\n" | |
"Upgrade: websocket\r\n" | |
"Connection: Upgrade\r\n" | |
f"Sec-WebSocket-Accept: {accept_key}\r\n\r\n" | |
) | |
client.send(response.encode('utf8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment