Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirects to wss://... don't work #333

Closed
SoMuchForSubtlety opened this issue Mar 7, 2022 · 7 comments
Closed

Redirects to wss://... don't work #333

SoMuchForSubtlety opened this issue Mar 7, 2022 · 7 comments
Labels
Milestone

Comments

@SoMuchForSubtlety
Copy link

If the server responds with 302 https://test.com/ws the redirect works, but if the response is 302 wss://test.com/ws the redirect fails with failed to WebSocket dial: failed to send handshake request: Get "wss://test.com/ws": unsupported protocol scheme "wss"

I was able to fix the issue by specifying a custom http.Client in the DialOptions

HTTPClient: &http.Client{
	CheckRedirect: func(req *http.Request, via []*http.Request) error {
		switch req.URL.Scheme {
		case "ws":
			req.URL.Scheme = "http"
		case "wss":
			req.URL.Scheme = "https"
		case "http", "https":
		default:
			return fmt.Errorf("unexpected url scheme: %q", req.URL.Scheme)
		}
		return nil
	},
},

Do you think this should be included in the default client? I would be happy to open a PR with the functionality,

SoMuchForSubtlety added a commit to SoMuchForSubtlety/ws-stomp that referenced this issue Mar 7, 2022
handle redirects that point to ws:// or wss://
details: nhooyr/websocket#333
@nhooyr
Copy link
Owner

nhooyr commented Mar 5, 2023

Hmm interesting. I'm not sure what browsers do here. Do they accept both on redirect? If so, we should too. I was under the impression they only used http and https.

@SoMuchForSubtlety
Copy link
Author

From the WebSocket spec1

Once the client's opening handshake has been sent, the client MUST
wait for a response from the server before sending any further data.
The client MUST validate the server's response as follows:

  1. If the status code received from the server is not 101, the
    client handles the response per HTTP [RFC2616] procedures. In
    particular, the client might perform authentication if it
    receives a 401 status code; the server might redirect the client
    using a 3xx status code
    (but clients are not required to follow
    them), etc. Otherwise, proceed as follows.

Footnotes

  1. https://www.rfc-editor.org/rfc/rfc6455

@nhooyr
Copy link
Owner

nhooyr commented Mar 7, 2023

I don't see how that clarifies the issue at hand? It doesn't speak on whether the redirect URL should use http or https.

@nhooyr
Copy link
Owner

nhooyr commented Mar 7, 2023

Sorry I mean wss or https.

@nhooyr nhooyr added this to the v1.8.8 milestone Sep 28, 2023
@nhooyr
Copy link
Owner

nhooyr commented Sep 28, 2023

I'll make it work anyway.

nhooyr added a commit that referenced this issue Oct 14, 2023
@nhooyr
Copy link
Owner

nhooyr commented Oct 14, 2023

Done in dev but still needs a test.

@nhooyr
Copy link
Owner

nhooyr commented Oct 15, 2023

Done.

@nhooyr nhooyr closed this as completed Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants