Skip to content

derp/derphttp: pass the headers to the websocket dial #12

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

Merged
merged 3 commits into from
Mar 13, 2023

Conversation

JoshVee
Copy link

@JoshVee JoshVee commented Mar 12, 2023

This PR modifies the dialWebsocketFunc to allow any DERP HTTP headers to be also passed through when dialing the websocket.

This expands upon the changes introduced in #6 to avoid errors like the one below:

2023-03-12 06:11:38.503 [DEBUG]	(wgengine)	<./../../../tailscale.com/derp/derphttp/derphttp_client.go:328>	(*Client).connect	derphttp.Client.Recv: connecting websocket to https://coder.some-reverse-proxy.com/derp
2023/03/12 17:11:38 websocket Dial: failed to WebSocket dial: expected handshake response status code 101 but got 403, &{Status:403 Forbidden StatusCode:403 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Cf-Ray:[7a69e1879b37ab01-SYD] Connection:[keep-alive] Content-Length:[151] Content-Type:[text/html] Date:[Sun, 12 Mar 2023 06:11:38 GMT] Server:[cloudflare]] Body:{Reader:0x140019b6330} ContentLength:151 TransferEncoding:[] Close:false Uncompressed:false Trailer:map[] Request:0x140012edf00 TLS:0x1400164a4d0}
2023-03-12 06:11:38.832 [DEBUG]	(wgengine)	<./../../../tailscale.com/derp/derphttp/derphttp_client.go:331>	(*Client).connect	derphttp.Client.Recv: websocket to https://coder.some-reverse-proxy.com/derp error: failed to WebSocket dial: expected handshake response status code 101 but got 403
2023-03-12 06:11:38.832 [DEBUG]	(wgengine)	<./../../../tailscale.com/wgengine/magicsock/magicsock.go:1671>	(*Conn).runDerpReader	magicsock: [0x14000928200] derp.Recv(derp-999): derphttp.Client.Recv connect to region 999 (coder): failed to WebSocket dial: expected handshake response status code 101 but got 403

@JoshVee
Copy link
Author

JoshVee commented Mar 12, 2023

@kylecarbs this change is needed in order to use the Coder embedded DERP server behind proxies \ tunnels.

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, neat. Thank you!

@JoshVee
Copy link
Author

JoshVee commented Mar 12, 2023

Ahh, neat. Thank you!

Thanks for the quick review @kylecarbs! I've implemented this functionality in coder/coder#6572

@kylecarbs kylecarbs merged commit e2ae516 into coder:main Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants