Skip to content

Instantly share code, notes, and snippets.

@arseniyturin
Last active December 18, 2021 01:23
Show Gist options
  • Save arseniyturin/0af811b7a81f1dda65a699675d900c74 to your computer and use it in GitHub Desktop.
Save arseniyturin/0af811b7a81f1dda65a699675d900c74 to your computer and use it in GitHub Desktop.
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