1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

templates: Fix httpInclude (fix #5698)

Allowable during feature freeze because this is a simple, non-invasive
bug fix only.
This commit is contained in:
Matthew Holt 2023-08-07 12:53:21 -06:00
parent a8cc5d1a7d
commit 431adc0980
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -245,14 +245,16 @@ type Server struct {
// ServeHTTP is the entry point for all HTTP requests. // ServeHTTP is the entry point for all HTTP requests.
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { 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. // 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. // TODO: Can be removed if https://github.com/golang/go/pull/56110 is ever merged.
if r.TLS == nil { if r.TLS == nil {
conn := r.Context().Value(ConnCtxKey).(net.Conn) // not all requests have a conn (like virtual requests) - see #5698
if conn, ok := r.Context().Value(ConnCtxKey).(net.Conn); ok {
if csc, ok := conn.(connectionStateConn); ok { if csc, ok := conn.(connectionStateConn); ok {
r.TLS = new(tls.ConnectionState) r.TLS = new(tls.ConnectionState)
*r.TLS = csc.ConnectionState() *r.TLS = csc.ConnectionState()
} }
} }
}
w.Header().Set("Server", "Caddy") w.Header().Set("Server", "Caddy")