Open
Conversation
WebSocket upgrade requests (Upgrade: websocket) are now proxied through to upstream backends instead of being rejected. Previously, the Connection and Upgrade headers were unconditionally stripped as hop-by-hop headers before forwarding. While this is correct per RFC 7230, RFC 6455 Section 4.1 requires these headers for the WebSocket handshake. Changes: - Detect WebSocket upgrade requests before header stripping - Preserve Connection and Upgrade headers for WS requests - Force HTTP/1.1 for WS requests (HTTP/2 does not support Upgrade) - On 101 from upstream, set up bidirectional byte relay via tokio::io::copy_bidirectional - Forward Sec-WebSocket-Accept and other upgrade headers from upstream Works because the HTTP listener already uses hyper serve_connection_with_upgrades. Fixes pingooio#23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds WebSocket upgrade proxying to the HTTP proxy service. Previously, WebSocket connections failed because
ConnectionandUpgradeheaders were stripped as hop-by-hop headers before forwarding.Changes
Upgrade: websocket) before header strippingConnectionandUpgradeheaders for WebSocket requests101 Switching Protocolsfrom upstream, establish bidirectional byte relay usingtokio::io::copy_bidirectionalSec-WebSocket-Acceptand other upgrade headers from upstream to clientHow it works
The HTTP listener already uses hyper's
serve_connection_with_upgrades(), so the server-side upgrade plumbing is in place. This PR adds the client-side:hyper::upgrade::on(&mut req)prepares the client upgrade futureConnection/Upgradeheaders intacthyper::upgrade::on(&mut res)prepares the upstream upgrade futureTesting
Tested against a Go reverse proxy (rpc-gateway-go) that itself proxies WebSocket connections to a VoIP call event stream. Verified:
Fixes #23