fix: honor WithHTTPClient for WebSocket dial via coder/websocket DialOptions#248
Merged
philippseith merged 1 commit intoJun 21, 2026
Merged
Conversation
…Options When the supplied Doer is an *http.Client, populate DialOptions.HTTPClient so that coder/websocket uses the caller's transport (and therefore TLS configuration) for the WebSocket upgrade handshake instead of falling back to http.DefaultClient. Previously, custom TLS settings (e.g. InsecureSkipVerify or a non-default root CA pool) were silently dropped for WebSocket connections, causing x509 certificate errors against servers with non-system-trusted certs. The type assertion is required because httpConn.client is typed as Doer while DialOptions.HTTPClient requires *http.Client. Callers passing a non-*http.Client Doer continue to get the existing behaviour. Closes philippseith#246
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #248 +/- ##
==========================================
+ Coverage 78.56% 78.91% +0.34%
==========================================
Files 30 30
Lines 2431 2433 +2
==========================================
+ Hits 1910 1920 +10
+ Misses 386 380 -6
+ Partials 135 133 -2
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Contributor
Author
|
@philippseith ping |
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.
Fixes #246.
What changed
httpconnection.go: when the caller'sDoeris an*http.Client, populateDialOptions.HTTPClientbefore callingwebsocket.Dialso thatcoder/websocketuses the caller's transport for the WebSocket upgrade handshake.WithHTTPClientgodoc to reflect the new behaviour and document the*http.Clientrequirement for WebSocket propagation.httpserver_test.go: added a test that starts ahttptest.NewTLSServer, connects a client withWithHTTPClient(testServer.Client())andWithTransports(TransportWebSockets), and asserts a successfulInvokeround-trip.Background
Issue #136 removed the custom client from the WebSocket path (for
nhooyr.io/websocket) because custom transports that do not return writable response bodies broke the dial. The fix was correct for that library. Since the migration togithub.com/coder/websocket,DialOptions.HTTPClientis explicitly supported and its docs note the writable-body constraint (http.Transportsatisfies this since Go 1.12).The type assertion (
httpConn.client.(*http.Client)) is required becausehttpConn.clientis typed asDoerwhileDialOptions.HTTPClientis*http.Client. Callers passing a non-*http.ClientDoercontinue to fall back tohttp.DefaultClientfor the WebSocket dial, as before.