reverse proxy: rewrite requests and responses for websocket over http2
Supports reverse proxying h2 websockets to backends. Fix 5565.
Requires upstream support, but can be tested with xcaddy build reverse-proxy-h2-websocket --replace golang.org/x/net=github.com/WeidiDeng/net@websocket-http2
Very neat, nice work @WeidiDeng :100:
I'm not 100% sure but a regular HTTP/2 GET request should contain the new setting parameter as outlined in RFC8441 Section 3?
[0-0] == Info: [HTTP/2] [0] ingress: read 45 bytes
[0-0] == Info: [HTTP/2] [0] <- FRAME[SETTINGS, len=36]
[0-0] == Info: [HTTP/2] [0] MAX_CONCURRENT_STREAMS: 250
[0-0] == Info: [HTTP/2] [0] ENABLE_PUSH: TRUE
[0-0] == Info: [HTTP/2] [0] notify MAX_CONCURRENT_STREAMS: 250
[0-0] == Info: [HTTP/2] [0] -> FRAME[SETTINGS, len=18]
[0-0] == Info: [HTTP/2] [0] -> FRAME[SETTINGS, ack=1]
[0-0] == Info: [HTTP/2] [0] -> FRAME[WINDOW_UPDATE, incr=1048510465]
[0-0] => Send SSL data, 5 bytes (0x5)
0000: 17 03 03 00 5a ....Z
[0-0] => Send SSL data, 1 bytes (0x1)
0000: 17 .
[0-0] == Info: [HTTP/2] [0] egress: wrote 73 bytes
[0-0] == Info: [HTTP/2] cf_connect() -> 0, 1,
[0-0] == Info: using HTTP/2
[0-0] == Info: [HTTP/2] [1] OPENED stream for https://xxxxxxx.xxx/
Tested via curl:
curl --trace request.dump --trace-config http/2 https://example.com
i'm not sure about curl debug dump. But I tested this with my Chrome and it works. The setting frame is send at the start of a new http2 connection, so it's sent regardless of the method client uses.
Even without my patch, golang http2 sends the following settings:
The output doesn't list all of them.
Successfully tested in Firefox :+1:
Upstream merged in 9a51899. Waiting for the next release.
golang/x/net v0.32.0 is out.
Is this a simple version bump which could be done in this PR or are there any side effects?
It's in another pr.
So this is ready to merge @WeidiDeng ?
Yes @francislavoie
I updated to latest master which included this commit, and it broke WebSocket reverse-proxying towards an HTTP/1.1 backend on Firefox for me.
The connection to wss://[...] was interrupted while the page was loading.
See #6733
@JeDaYoshi try xcaddy build encode-connect to see if it's fixed, or use the following request matchers
@not_h2_ws not {
header :protocol *
method CONNECT
protocol http/2
}
encode @not_h2_ws zstd gzip
I should check PRs/issues properly before commenting things.. My apologies.
@WeidiDeng encode-connect / #6738 seems to be working for me.