Enhanced WebSocket Protocol Handling in Proxy Server Connections #304
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.
Problem:
Previously, the proxy server's handling of WebSocket connections overlooked the sec-websocket-protocol header, which is critical for specifying subprotocols. For example, when a client requested to establish a WebSocket connection with a specific protocol (e.g., json.reliable.webpubsub.azure.v1 for chatgpt), the proxy would initiate the connection without passing along the requested protocol. This oversight could lead to connection failures or incorrect server behaviors, as the server might not respond with the necessary connection message if the expected protocol was not specified. An example of this issue was observed on the "chatgpt" page, where omitting the protocol led to malfunctioning due to the server's expectation for a specific subprotocol to establish a WebSocket connection.
Solution:
The modifications entail capturing the protocol specifications from client requests and incorporating these details into the connection options. Subsequently, these options are passed to the WebSocket constructor, thereby ensuring that the connection process is fully compliant with the protocol requirements.