diff options
author | WeidiDeng <weidi_deng@icloud.com> | 2023-04-11 01:05:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 17:05:02 +0000 |
commit | d8d87a378f37d31cfe6502cc66ac3c95fc799489 (patch) | |
tree | 288b3b8622234fb5dd449200567c478e7e4f60ff /modules/caddyhttp/server.go | |
parent | f8b59e77f83c05da87bd5e3780fb7522b863d462 (diff) |
caddyhttp: Serve http2 when listener wrapper doesn't return *tls.Conn (#4929)
* Serve http2 when listener wrapper doesn't return *tls.Conn
* close conn when h2server serveConn returns
* merge from upstream
* rebase from latest
* run New and Closed ConnState hook for h2 conns
* go fmt
* fix lint
* Add comments
* reorder import
Diffstat (limited to 'modules/caddyhttp/server.go')
-rw-r--r-- | modules/caddyhttp/server.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go index 82fdbe5..9721007 100644 --- a/modules/caddyhttp/server.go +++ b/modules/caddyhttp/server.go @@ -198,6 +198,7 @@ type Server struct { server *http.Server h3server *http3.Server h3listeners []net.PacketConn // TODO: we have to hold these because quic-go won't close listeners it didn't create + h2listeners []*http2Listener addresses []caddy.NetworkAddress trustedProxies IPRangeSource @@ -213,6 +214,16 @@ type Server struct { // ServeHTTP is the entry point for all HTTP requests. func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // If there are listener wrappers that process tls connections but don't return a *tls.Conn, this field will be nil. + // Can be removed if https://github.com/golang/go/pull/56110 is ever merged. + if r.TLS == nil { + conn := r.Context().Value(ConnCtxKey).(net.Conn) + if csc, ok := conn.(connectionStateConn); ok { + r.TLS = new(tls.ConnectionState) + *r.TLS = csc.ConnectionState() + } + } + w.Header().Set("Server", "Caddy") // advertise HTTP/3, if enabled @@ -870,6 +881,9 @@ const ( // originally came into the server's entry handler OriginalRequestCtxKey caddy.CtxKey = "original_request" + // For referencing underlying net.Conn + ConnCtxKey caddy.CtxKey = "conn" + // For tracking whether the client is a trusted proxy TrustedProxyVarKey string = "trusted_proxy" |