From 9cd591db87407af997cfc34051dacb48955f1ae4 Mon Sep 17 00:00:00 2001 From: tomholford Date: Thu, 23 Apr 2026 11:04:10 -0700 Subject: [PATCH] reverseproxy: inline WebTransport protocol const and writer interface Francis pointed out in review of #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. --- .../reverseproxy/webtransport_transport.go | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/caddyhttp/reverseproxy/webtransport_transport.go b/modules/caddyhttp/reverseproxy/webtransport_transport.go index 594761dfe..02b0e6b9c 100644 --- a/modules/caddyhttp/reverseproxy/webtransport_transport.go +++ b/modules/caddyhttp/reverseproxy/webtransport_transport.go @@ -23,20 +23,35 @@ import ( "time" "github.com/quic-go/quic-go" + "github.com/quic-go/quic-go/http3" "github.com/quic-go/webtransport-go" "go.uber.org/zap" "go.uber.org/zap/zapcore" "github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2/modules/caddyhttp" - caddywt "github.com/caddyserver/caddy/v2/modules/caddyhttp/webtransport" ) +// webtransportProtocol is the :protocol pseudo-header value sent by a +// client that wants to establish a WebTransport session over an HTTP/3 +// Extended CONNECT. +const webtransportProtocol = "webtransport" + +// webtransportWriter is the naked HTTP/3 response-writer shape that +// webtransport.Server.Upgrade type-asserts on. Caddy's +// UnwrapResponseWriterAs walks the ResponseWriter wrapper chain to this +// type before calling Upgrade. +type webtransportWriter interface { + http.ResponseWriter + http3.Settingser + http3.HTTPStreamer +} + // isWebTransportExtendedConnect reports whether r is an HTTP/3 Extended // CONNECT that requests a WebTransport session. Does not check whether // WebTransport proxying is configured; callers gate on Handler state. func isWebTransportExtendedConnect(r *http.Request) bool { - return r.ProtoMajor == 3 && r.Method == http.MethodConnect && r.Proto == caddywt.Protocol + return r.ProtoMajor == 3 && r.Method == http.MethodConnect && r.Proto == webtransportProtocol } // serveWebTransport handles a WebTransport Extended CONNECT: selects an @@ -118,7 +133,7 @@ func (h *Handler) serveWebTransport(w http.ResponseWriter, r *http.Request) erro // Reach the naked http3 response writer so Upgrade's type assertions // succeed through Caddy's wrapper chain. Done before dialing so we // fail fast if the writer stack is unexpectedly incompatible. - naked, ok := caddyhttp.UnwrapResponseWriterAs[caddywt.Writer](w) + naked, ok := caddyhttp.UnwrapResponseWriterAs[webtransportWriter](w) if !ok { return caddyhttp.Error(http.StatusInternalServerError, errors.New("webtransport: response writer does not support WebTransport upgrade"))