Pithikos / python-websocket-server

A simple fully working websocket-server in Python with no external dependencies
MIT License
1.15k stars 385 forks source link

WebSocketHandler.handshake strips \r\n from the recv'd message, then looks for \r\n #27

Closed CMTaylor closed 6 years ago

CMTaylor commented 7 years ago

I'm not sure why this message is being "strip"ped, but it messes up the key regular expression since the terminating \r\n is stripped off and the re.search will ALWAYS fail if the Sec-WebSocket-Key message is the last line in the handshake sequence: key = re.search('\n[sS]ec-[wW]eb[sS]ocket-[kK]ey[\s]:[\s](.*)\r\n', message)

CMTaylor commented 7 years ago

My somewhat kludgy fix is to put the terminating \r\n back on message after stripping it.

CMTaylor commented 7 years ago

@Pithikos Any chance of getting the PR for this merged into your master?

AndyLee1024 commented 6 years ago

change message = self.request.recv(1024).decode().strip() to message = self.request.recv(2048).decode().strip()

Pithikos commented 6 years ago

Fixed with c3f0b00fbd29e478b814b4ea32b0b7d479e89841