Fix multiple websocket connection issues. #58
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was testing the ws_server and ws_client examples and I hit multiple issues. I've attempted to fix them with these changes, but I'm not 100% sure if this is the "right" way. Thanks for the great library and for considering this change!
The websocket client sends two Connection headers:
HTTP/1.1 GET /
Host: 127.0.0.1
Origin: foo.com
Content-Length: 0
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: h57ZiKx+KAwmKbB+mxR8Ag==
Connection: Keep-Alive
The last "Connection: Keep-Alive" is added because the ConnectionType enum does not have an "Upgrade" variant. Adding the variant prevents this issue.
If the websocket client does not receive a "Content-Length: 0" header in the server's response, an error is returned stating "Unknown body type in a response with a Keep-Alive connection. This is not allowed." This occurs with the example client using the "websockets.chilkat.io/" service. This is corrected by assuming a "BodyType::ContentLen(0)" for the response when no other BodyType is provided and the "Connection: Upgrade" header is present.