Repository: caddyserver/caddy
File: modules/caddyhttp/server.go (Go)

Code before:
	//
	// Default: `[h1 h2 h3]`
	Protocols []string `json:"protocols,omitempty"`

	// If set, metrics observations will be enabled.
	// This setting is EXPERIMENTAL and subject to change.
	Metrics *Metrics `json:"metrics,omitempty"`

	name string

	primaryHandlerChain Handler
	errorHandlerChain   Handler
	listenerWrappers    []caddy.ListenerWrapper
	listeners           []net.Listener

	tlsApp       *caddytls.TLS
	events       *caddyevents.App
	logger       *zap.Logger
	accessLogger *zap.Logger
	errorLogger  *zap.Logger
	ctx          caddy.Context

	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
	http2listeners []*http2Listener
	addresses      []caddy.NetworkAddress

	trustedProxies IPRangeSource

	shutdownAt   time.Time
	shutdownAtMu *sync.RWMutex

	// registered callback functions
	connStateFuncs   []func(net.Conn, http.ConnState)
	connContextFuncs []func(ctx context.Context, c net.Conn) context.Context
	onShutdownFuncs  []func()
}

// ServeHTTP is the entry point for all HTTP requests.
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	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")


Review comment (suggestion):
```suggestion
	h2listeners []*http2Listener
```

Just for symmetry with `h3` vars I guess :)

Code after:
	//
	// Default: `[h1 h2 h3]`
	Protocols []string `json:"protocols,omitempty"`

	// If set, metrics observations will be enabled.
	// This setting is EXPERIMENTAL and subject to change.
	Metrics *Metrics `json:"metrics,omitempty"`

	name string

	primaryHandlerChain Handler
	errorHandlerChain   Handler
	listenerWrappers    []caddy.ListenerWrapper
	listeners           []net.Listener

	tlsApp       *caddytls.TLS
	events       *caddyevents.App
	logger       *zap.Logger
	accessLogger *zap.Logger
	errorLogger  *zap.Logger
	ctx          caddy.Context

	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

	shutdownAt   time.Time
	shutdownAtMu *sync.RWMutex

	// registered callback functions
	connStateFuncs   []func(net.Conn, http.ConnState)
	connContextFuncs []func(ctx context.Context, c net.Conn) context.Context
	onShutdownFuncs  []func()
}

// 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()
		}
	}