Repository navigation
caddyhttp, reverseproxy: experimental WebTransport passthrough - #7669
Conversation
|
@marten-seemann This wouldn't have been possible without your hard work on |
|
Well this is a bit scary from a blast-radius perspective. Francis seems to be covering the implementation and maintenance issues well already, my separate concern is the architectural one. This appears to put experimental WebTransport handling directly into Caddy’s core HTTP/3 accept path, not just behind an opt-in reverse-proxy feature. That makes me think this wants splitting or at least a much stronger justification for why the core H3-path change is low risk. Right now it looks like an experimental feature is being paid for by every HTTP/3 deployment, not only the ones that opt into WebTransport. |
|
Thank you for the feedback. Will review and address. |
The WebTransport proxy path in serveWebTransport duplicated the
dynamic-upstream-fallback block and the {http.reverse_proxy.upstream.*}
replacer-variable block from proxyLoopIteration. Francis flagged this
as a maintenance burden in review of caddyserver#7669.
Extract two helpers:
* resolveUpstreams(r) returns the candidate upstream set — dynamic
when configured (with provisioning + fallback-on-error), static
otherwise. Caller runs the LB selection policy, since the two call
sites diverge on how selection failure is reported (retry loop vs.
fast 502 for long-lived WT sessions).
* setUpstreamReplacerVars(repl, up, di) publishes the seven
placeholders describing the selected upstream.
Both are used by proxyLoopIteration and serveWebTransport with
identical semantics to the inlined code they replace. No behavior
change for either path.
Francis pointed out in review of caddyserver#7669 that importing the whole modules/caddyhttp/webtransport package solely to pull in one constant and one interface wasn't worthwhile. Move both into webtransport_transport.go as unexported identifiers (webtransportProtocol, webtransportWriter). This removes reverseproxy's dependency on the caddywt package and clears the way for moving the echo handler itself out of the production module tree. No behavior change.
Francis pointed out in review of caddyserver#7669 that the echo handler — which exists solely as a test upstream for the WebTransport reverse-proxy tests — should not be a full-fledged module registered in every Caddy binary. Mirroring the mockdns_test.go pattern, move it into a _test.go file under caddytest/integration/. The module ID http.handlers.webtransport is now registered only when the integration test binary is built, which is when caddytest/integration/webtransport_test.go references it by ID string in its JSON configs. Production Caddy builds no longer include it. Changes: * New file: caddytest/integration/webtransport_echo_test.go — contains the WebTransportEcho handler, its types and interface guards, the isWebTransportEchoUpgrade helper, and the unit tests that used to live in the deleted package's handler_test.go. * Deleted: modules/caddyhttp/webtransport/ (handler.go + handler_test.go). * Removed the blank import from modules/caddyhttp/standard/imports.go. The Protocol const and Writer interface that this package used to export were inlined into reverseproxy's own files in a preceding commit, so nothing else depends on the deleted package.
… server flag steadytao raised an architectural concern in review of caddyserver#7669: the PR put experimental WebTransport handling directly into Caddy's core HTTP/3 accept path, so every HTTP/3 deployment paid for the feature whether or not they used it. Collapse the enablement surface to a single server-level opt-in that matches Caddy's existing precedent for protocol-level features (`protocols`, `allow_0rtt`, `enable_full_duplex`), and detect the request shape at the handler the same way `reverse_proxy` detects a WebSocket upgrade today — no per-handler config flag. Core HTTP/3 path changes (modules/caddyhttp/server.go): * New `EnableWebTransport bool` field on Server, marked EXPERIMENTAL. * buildHTTP3Server now only calls webtransport.ConfigureHTTP3Server and sets EnableStreamResetPartialDelivery when the flag is true. When false, the constructed http3.Server is bit-for-bit identical to the pre-WebTransport implementation. * wtServer is constructed only when the flag is true. * serveH3AcceptLoop falls back to http3.Server.ServeListener when the flag is false — no varint peek, no per-connection dispatch. Caddyfile wiring (caddyconfig/httpcaddyfile/serveroptions.go): * New `enable_webtransport` global server option, modeled on `enable_full_duplex`. Reverse-proxy simplifications (modules/caddyhttp/reverseproxy/): * Removed HTTPTransport.WebTransport field and its Provision-time exclusivity check (no longer needed; H3 is validated separately). * Removed the `webtransport` Caddyfile subdirective under `transport http { }` — this neutralizes the prior commit that introduced it. * Removed Handler.webtransportEnabled cache. ServeHTTP now branches on isWebTransportExtendedConnect(r) alone, matching how the WebSocket upgrade branch works. * serveWebTransport gains fail-fast guards with clear errors when the parent server has enable_webtransport=false or when the handler's transport does not include HTTP/3. Tests: * Existing TestServer_BuildHTTP3ServerEnablesWebTransport now sets EnableWebTransport=true explicitly; new TestServer_BuildHTTP3ServerWithoutWebTransport locks in the regression guard that flag-off produces the pre-PR http3.Server. * Integration tests updated: enable_webtransport: true added to every H3 server block; "webtransport": true dropped from the reverse_proxy transport JSON (auto-detected now). * Caddyfile adapt test for the deleted `webtransport` subdirective is removed; `enable_webtransport` is added to the existing global_server_options_single adapt test alongside its peers. No runtime behavior change when enable_webtransport is false. Diff against master on the core HTTP/3 path is effectively zero in that configuration.
|
@steadytao Thanks for flagging; I've pushed commits that fully address this: bb8b3ee ( Same commit also drops the per-handler {
servers {
enable_webtransport
}
}
example.com {
reverse_proxy https://backend:9443 {
transport http {
versions 3
}
}
}d67425d adds a pair of hermetic benchmarks to quantify the delta: Off is about half the cost on every dimension, which is exactly the work skipped when the flag is false ( The |
|
@francislavoie @steadytao ready for re-review when you have time. Summary of what landed since the last pass:
|
|
I will allow francis to continue with the review. But from a brief checkover, it seems much better, thank you! |
b9ead19 to
a9cc909
Compare
The WebTransport proxy path in serveWebTransport duplicated the
dynamic-upstream-fallback block and the {http.reverse_proxy.upstream.*}
replacer-variable block from proxyLoopIteration. Francis flagged this
as a maintenance burden in review of caddyserver#7669.
Extract two helpers:
* resolveUpstreams(r) returns the candidate upstream set — dynamic
when configured (with provisioning + fallback-on-error), static
otherwise. Caller runs the LB selection policy, since the two call
sites diverge on how selection failure is reported (retry loop vs.
fast 502 for long-lived WT sessions).
* setUpstreamReplacerVars(repl, up, di) publishes the seven
placeholders describing the selected upstream.
Both are used by proxyLoopIteration and serveWebTransport with
identical semantics to the inlined code they replace. No behavior
change for either path.
Francis pointed out in review of caddyserver#7669 that importing the whole modules/caddyhttp/webtransport package solely to pull in one constant and one interface wasn't worthwhile. Move both into webtransport_transport.go as unexported identifiers (webtransportProtocol, webtransportWriter). This removes reverseproxy's dependency on the caddywt package and clears the way for moving the echo handler itself out of the production module tree. No behavior change.
Francis pointed out in review of caddyserver#7669 that the echo handler — which exists solely as a test upstream for the WebTransport reverse-proxy tests — should not be a full-fledged module registered in every Caddy binary. Mirroring the mockdns_test.go pattern, move it into a _test.go file under caddytest/integration/. The module ID http.handlers.webtransport is now registered only when the integration test binary is built, which is when caddytest/integration/webtransport_test.go references it by ID string in its JSON configs. Production Caddy builds no longer include it. Changes: * New file: caddytest/integration/webtransport_echo_test.go — contains the WebTransportEcho handler, its types and interface guards, the isWebTransportEchoUpgrade helper, and the unit tests that used to live in the deleted package's handler_test.go. * Deleted: modules/caddyhttp/webtransport/ (handler.go + handler_test.go). * Removed the blank import from modules/caddyhttp/standard/imports.go. The Protocol const and Writer interface that this package used to export were inlined into reverseproxy's own files in a preceding commit, so nothing else depends on the deleted package.
… server flag steadytao raised an architectural concern in review of caddyserver#7669: the PR put experimental WebTransport handling directly into Caddy's core HTTP/3 accept path, so every HTTP/3 deployment paid for the feature whether or not they used it. Collapse the enablement surface to a single server-level opt-in that matches Caddy's existing precedent for protocol-level features (`protocols`, `allow_0rtt`, `enable_full_duplex`), and detect the request shape at the handler the same way `reverse_proxy` detects a WebSocket upgrade today — no per-handler config flag. Core HTTP/3 path changes (modules/caddyhttp/server.go): * New `EnableWebTransport bool` field on Server, marked EXPERIMENTAL. * buildHTTP3Server now only calls webtransport.ConfigureHTTP3Server and sets EnableStreamResetPartialDelivery when the flag is true. When false, the constructed http3.Server is bit-for-bit identical to the pre-WebTransport implementation. * wtServer is constructed only when the flag is true. * serveH3AcceptLoop falls back to http3.Server.ServeListener when the flag is false — no varint peek, no per-connection dispatch. Caddyfile wiring (caddyconfig/httpcaddyfile/serveroptions.go): * New `enable_webtransport` global server option, modeled on `enable_full_duplex`. Reverse-proxy simplifications (modules/caddyhttp/reverseproxy/): * Removed HTTPTransport.WebTransport field and its Provision-time exclusivity check (no longer needed; H3 is validated separately). * Removed the `webtransport` Caddyfile subdirective under `transport http { }` — this neutralizes the prior commit that introduced it. * Removed Handler.webtransportEnabled cache. ServeHTTP now branches on isWebTransportExtendedConnect(r) alone, matching how the WebSocket upgrade branch works. * serveWebTransport gains fail-fast guards with clear errors when the parent server has enable_webtransport=false or when the handler's transport does not include HTTP/3. Tests: * Existing TestServer_BuildHTTP3ServerEnablesWebTransport now sets EnableWebTransport=true explicitly; new TestServer_BuildHTTP3ServerWithoutWebTransport locks in the regression guard that flag-off produces the pre-PR http3.Server. * Integration tests updated: enable_webtransport: true added to every H3 server block; "webtransport": true dropped from the reverse_proxy transport JSON (auto-detected now). * Caddyfile adapt test for the deleted `webtransport` subdirective is removed; `enable_webtransport` is added to the existing global_server_options_single adapt test alongside its peers. No runtime behavior change when enable_webtransport is false. Diff against master on the core HTTP/3 path is effectively zero in that configuration.
…loop The earlier caddyserver#7669 revision extracted resolveUpstreams and setUpstreamReplacerVars to share between the WebTransport path and the normal proxy path. A later commit collapsed the WebTransport path into the main proxy loop, so the helpers became single-callers — they no longer earn their abstraction. Inline both back into proxyLoopIteration. The dynamic-upstream block absorbs the CachingUpstreamSource cache-reset logic added by caddyserver#7662, which was preserved through the rebase. No behavior change.
|
@WeidiDeng thanks for the review — addressed all six points. Branch rebased onto current master and force-pushed; commits below.
Re-ran the manual e2e from the appendix against a binary built from the new tip:
|
francislavoie
left a comment
There was a problem hiding this comment.
Looking really good to me now, glad we managed to simplify the integration to not mess with existing code too much!
The WebTransport proxy path in serveWebTransport duplicated the
dynamic-upstream-fallback block and the {http.reverse_proxy.upstream.*}
replacer-variable block from proxyLoopIteration. Francis flagged this
as a maintenance burden in review of caddyserver#7669.
Extract two helpers:
* resolveUpstreams(r) returns the candidate upstream set — dynamic
when configured (with provisioning + fallback-on-error), static
otherwise. Caller runs the LB selection policy, since the two call
sites diverge on how selection failure is reported (retry loop vs.
fast 502 for long-lived WT sessions).
* setUpstreamReplacerVars(repl, up, di) publishes the seven
placeholders describing the selected upstream.
Both are used by proxyLoopIteration and serveWebTransport with
identical semantics to the inlined code they replace. No behavior
change for either path.
Francis pointed out in review of caddyserver#7669 that importing the whole modules/caddyhttp/webtransport package solely to pull in one constant and one interface wasn't worthwhile. Move both into webtransport_transport.go as unexported identifiers (webtransportProtocol, webtransportWriter). This removes reverseproxy's dependency on the caddywt package and clears the way for moving the echo handler itself out of the production module tree. No behavior change.
A wrapper whose Unwrap returns itself would spin forever. Restore the cycle-break mholt applied on caddyserver#7669, without bringing back the nil-pointer guard Weidi asked to drop.
ServeQUICConn waits for active WT sessions, and with the default eternal grace period HTTP/3 Shutdown would hang until every client disconnected. Close the WebTransport server first so stop/reload can drain.
A pooled QUIC listener created without DATAGRAMs cannot upgrade WT sessions. Falling back on the WT-configured http3.Server still advertised SETTINGS the socket cannot honor. Build a separate plain HTTP/3 server for that listener and assert it omits WT SETTINGS.
Comparing writers with == panics on uncomparable types and only catches a one-node cycle. Track pointer identity, bound the walk, and add tests for an uncomparable self-unwrap and an A→B→A cycle. RecordHijackedStatus lets Upgrade write through the naked HTTP/3 writer while the access-log recorder still observes the 200.
Dialer.Dial always sets Host from the URL, so header_up Host never reached the upstream. Dial the real address via DialAddr and put the prepared Host on the CONNECT. Parse WT-Available-Protocols from the prepared request so header_up applies to negotiation. Copy filtered upstream response headers before header_down, record the hijacked 200 for access logs, and run the same latency / circuit-breaker / passive-health path as a normal round-trip.
Reload with an eternal grace period must close an in-flight session. Access logs must record 200 after Upgrade. header_up Host and WT-Available-Protocols must reach the upstream; header_down and non-hop upstream headers must reach the client.
webtransport-go v0.13.0 renames Dialer to Transport. v0.11.1 does not compile against quic-go v0.63.
Dial can return a response with an error when the peer rejects the CONNECT. Close that body before the error is returned.
webtransport.Server.Close also closes the shared HTTP/3 server and aborts every QUIC connection before the grace period applies. Close the registered sessions, then let HTTP/3 shutdown drain ordinary requests.
Signed-off-by: Zen Dodd <[email protected]>
The proxy loop reuses the request and only recopies headers when header ops are configured. Deleting the offer on that map hid it from the next upstream.
Eternal grace leaves an active session until the peer ends it. A configured grace period closes it at the deadline, while the socket is still up, so the close capsule can be delivered.
The proxy-loop collapse renamed roundtripSucceededError to terminalError. Master's Incremental refusal still returned the old type, so the rebased package did not compile.
- Count in-flight requests on ServeQUICConn connections and close idle ones when shutdown starts - Delay that close by a second so a just-finished response can be read - Retain plain HTTP/3 fallbacks for listeners without datagrams and shut them down with the same grace period
- Join bidi and uni splice workers after the accept loops return - Cancel the opposite copy on a hard splice error
|
@steadytao Thanks again for the feedback. I rebased #7976 on master, and then rebased this branch on it. Then, per your feedback, addressed the following:
|
|
Much appreciated. Also, thank you for the congratulations on the medal; completely missed that earlier. Also. @WeidiDeng Could you take a final pass over the HTTP/3 lifecycle when you get the chance please? |
|
There are conflicts to be resolved. Other than that, LGTM. |
Resolve the server_test.go conflict by retaining both the WebTransport tests and the log-level test unchanged. Validated with go test -race -short ./..., go build -buildvcs=false ./..., and golangci-lint run --timeout 10m. AI-assisted conflict resolution using OpenAI Codex (GPT-6).
|
FYI @tomholford quic-go 0.65.0 changed the |
@francislavoie On it, thanks for the heads up |
|
@francislavoie Waiting on this upstream PR quic-go/webtransport-go#377 . Once it's in, will raise a PR to bump caddy's dep. |
Depends on #7976 (ListenQUIC options). This PR targets
mastersoGitHub can open it from the fork; the extra ListenQUIC commit is #7976.
Summary
Experimental WebTransport (
draft-ietf-webtrans-http3) reverse-proxypassthrough. HTTP/3 Extended CONNECT with
:protocol=webtransport/webtransport-h3is upgraded on the client, re-dialed upstream, andthe two sessions are bridged (bidi streams, uni streams, datagrams).
Opt-in at the server.
reverse_proxyauto-detects the CONNECT thesame way it auto-detects WebSocket.
JSON:
Caddyfile:
{ servers { webtransport } } example.com { reverse_proxy https://backend:9443 { transport http { versions 3 } } }Requires HTTP/3 on the server and
versions 3on the proxy transport.Off by default: HTTP/3 without
webtransportis unchanged.Validation (manual e2e)
Production
caddybinary (da759cb3) on:9443("webtransport": {}) proxying to a standalone WT echo server on:9444. Realwebtransport.Transportclient (wt-poke, webtransport-go v0.13.0), notcaddytest.Tester. Apple Silicon, loopback.moqt-19+ Origin (elee / MediaMTX)"moqt-19",WT-Protocolheader, 3/3 streamswebtransportkey removed (hot reload)server didn't enable HTTP/3 datagram supportSIGTERM: Caddy exit 0; echo stopped.
AI-assisted with multiple models and harnesses (Claude Fable, Grok 4.6, Grok 4.7). I applied my judgment and experience while steering the agent, and pushed back or redirected when appropriate.