Repository navigation
Expose upgrade response headers to WebSocket client onUpgrade - #164
Open
awaisdev5765 wants to merge 1 commit into
Open
awaisdev5765 wants to merge 1 commit into
awaisdev5765 wants to merge 1 commit into
Conversation
The NIOWebSocketClientUpgrader's upgradePipelineHandler already receives the 101 Switching Protocols response head, but it was not accessible to client code. This prevented clients from reading headers the server sends during the upgrade - e.g. an authentication token minted server-side in the shouldUpgrade/upgrade flow. Add connect overloads whose onUpgrade closure also receives the HTTPResponseHead: - WebSocket.connect(to:scheme:...) with onUpgradeWithResponse - WebSocketClient.connect(...) with onUpgradeWithResponse (including proxy variants) - async/await variants Existing onUpgrade APIs are unchanged (they forward through to the new variants, discarding the head), so this is fully source-compatible. Fixes vapor#151
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.
Motivation
Fixes #151 — clients currently cannot read the headers a server sends in the
101 Switching Protocolsupgrade response (e.g. an auth token minted server-side during the upgrade flow).Changes
connectoverloads whoseonUpgradeWithResponseclosure receives theHTTPResponseHeadalongside theWebSocket:WebSocket.connect(to:scheme:...)WebSocketClient.connect(...)(incl. proxy variants)onUpgradeAPIs are unchanged — they forward through to the new variants and discard the head, so this is fully source-compatible.testUpgradeResponseHeadersAreReceived,testUpgradeResponseHeadersAreReceivedAsync).Result
Full suite passes: 27 tests, 0 failures. A client can now do: