Repository navigation
Add set_basic_auth and set_bearer_token_auth to WebSocketClient - #2652
Merged
Merged
Conversation
ClientImpl and SSLClient let callers set origin credentials with set_basic_auth()/set_bearer_token_auth(), but WebSocketClient could only take a fixed Authorization header through its constructor. Add both setters: each connect() adds the Authorization header to the upgrade request from the current credentials (Basic over Bearer), unless the constructor headers already carry one, and never to the proxy's CONNECT request.
Owner
|
Thanks again! |
Contributor
Author
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
Add
set_basic_auth()andset_bearer_token_auth()toWebSocketClient, the same origin credential settersClienthas.The credentials are sent as the
Authorizationheader of the upgrade request on everyconnect(). Through a proxy, they are sent only on the request inside the tunnel, never on theCONNECTrequest.Problem
ClientImplandSSLClientlet callers set origin credentials with setters, butWebSocketClientcould only take anAuthorizationheader through its constructor, and there is no other API to change its headers.This meant:
base64(user:pass)) themselves.Changes
WebSocketClient::set_basic_auth()andset_bearer_token_auth().Authorizationheader to the upgrade request inprepare_default_headers()throughdetail::add_authorization_header().ClientImpl, Basic is sent when a username or password is set, otherwise Bearer.Authorizationheader already in the constructor headers is kept as is.connect(), so a change takes effect on the next reconnect.CONNECTrequest built inconnect_with_proxy()is unchanged and still carries only theset_proxy_*_auth()credentials.README-websocket.mdand add an Authentication section.Authorizationon the upgrade request inside the tunnelCONNECTrequestset_bearer_token_auth("t")Bearer tset_basic_auth("u", "p")Basic dTpwAuthorization+ setterTests
Add coverage for:
WebSocketClientover a direct connection:Authorizationheader wins over the setters.WebSocketClientthrough a proxy:CONNECTrequest.The existing proxy credential tests are unchanged; the new ones use a separate helper.