Pithikos / python-websocket-server

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

WebSocketHandler.handshake doesn't deal with partial socket reads #26

Closed CMTaylor closed 6 years ago

CMTaylor commented 7 years ago

The original implementation had a single call to self.request.recv(1024).decode() which sometimes returns with only part of the GET... handshake message. Thus it fails OFTEN!

CMTaylor commented 7 years ago

A complete handshake message seems to always end in a double \r\n sequence, so I added a while to keep getting the message parts until it has a full handshake message. I also added the nParts counter so that in a debugger you can break on this and examine the number and content of each part that is recv'd.

CMTaylor commented 7 years ago

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

mboo2005 commented 6 years ago

self.request.recv(1024) get partial request content when socket connecting with large cookies info. So I changed the code to message = self.request.recv(1024*8).decode().strip() #read all the request header Has anyone better resolution?

Pithikos commented 6 years ago

This seems like a workaround but it won't work for larger size of headers. c3f0b00fbd29e478b814b4ea32b0b7d479e89841 should fix it.