Debian Codegraph @

modules/caddyhttp/server.go

raw symbols SCIP
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/
16
17 import (
18 "contextscip-go gomod github.com/golang/go/src go1.25.1 context/"
19 "crypto/tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/"
20 "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/"
21 "errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/"
22 "fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/"
23 "ioscip-go gomod github.com/golang/go/src go1.25.1 io/"
24 "netscip-go gomod github.com/golang/go/src go1.25.1 net/"
25 "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/"
26 "net/netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/"
27 "net/urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/"
28 "runtimescip-go gomod github.com/golang/go/src go1.25.1 runtime/"
29 "slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/"
30 "stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/"
31 "sync/atomicscip-go gomod github.com/golang/go/src go1.25.1 `sync/atomic`/"
32 "timescip-go gomod github.com/golang/go/src go1.25.1 time/"
33
34 "github.com/caddyserver/certmagicscip-go gomod github.com/caddyserver/certmagic v0.25.3 `github.com/caddyserver/certmagic`/"
35 "github.com/quic-go/quic-goscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/"
36 "github.com/quic-go/quic-go/http3scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/"
37 h3qlogscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3/qlog`/ "github.com/quic-go/quic-go/http3/qlogscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3/qlog`/"
38 "go.uber.org/zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/"
39 "go.uber.org/zap/zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/"
40
41 "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/"
42 "github.com/caddyserver/caddy/v2/modules/caddyeventsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyevents`/"
43 "github.com/caddyserver/caddy/v2/modules/caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/"
44 )
45
46 // Server describes an HTTP server.
47 type Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server# struct {
48 // Socket addresses to which to bind listeners. Accepts
49 // [network addresses](/docs/conventions#network-addresses)
50 // that may include port ranges. Listener addresses must
51 // be unique; they cannot be repeated across all defined
52 // servers.
53 Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen. []string `json:"listen,omitempty"`
54
55 // A list of listener wrapper modules, which can modify the behavior
56 // of the base listener. They are applied in the given order.
57 ListenerWrappersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenerWrappersRaw. []jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/RawMessage# `json:"listener_wrappers,omitempty" caddy:"namespace=caddy.listeners inline_key=wrapper"`
58
59 // A list of packet conn wrapper modules, which can modify the behavior
60 // of the base packet conn. They are applied in the given order.
61 PacketConnWrappersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#PacketConnWrappersRaw. []jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/RawMessage# `json:"packet_conn_wrappers,omitempty" caddy:"namespace=caddy.packetconns inline_key=wrapper"`
62
63 // How long to allow a read from a client's upload. Setting this
64 // to a short, non-zero value can mitigate slowloris attacks, but
65 // may also affect legitimately slow clients.
66 ReadTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ReadTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"read_timeout,omitempty"`
67
68 // ReadHeaderTimeout is like ReadTimeout but for request headers.
69 // Default is 1 minute.
70 ReadHeaderTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ReadHeaderTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"read_header_timeout,omitempty"`
71
72 // WriteTimeout is how long to allow a write to a client. Note
73 // that setting this to a small value when serving large files
74 // may negatively affect legitimately slow clients.
75 WriteTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#WriteTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"write_timeout,omitempty"`
76
77 // IdleTimeout is the maximum time to wait for the next request
78 // when keep-alives are enabled. If zero, a default timeout of
79 // 5m is applied to help avoid resource exhaustion.
80 IdleTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#IdleTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"idle_timeout,omitempty"`
81
82 // KeepAliveInterval is the interval at which TCP keepalive packets
83 // are sent to keep the connection alive at the TCP layer when no other
84 // data is being transmitted.
85 // If zero, the default is 15s.
86 // If negative, keepalive packets are not sent and other keepalive parameters
87 // are ignored.
88 KeepAliveIntervalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#KeepAliveInterval. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"keepalive_interval,omitempty"`
89
90 // KeepAliveIdle is the time that the connection must be idle before
91 // the first TCP keep-alive probe is sent when no other data is being
92 // transmitted.
93 // If zero, the default is 15s.
94 // If negative, underlying socket value is unchanged.
95 KeepAliveIdlescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#KeepAliveIdle. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"keepalive_idle,omitempty"`
96
97 // KeepAliveCount is the maximum number of TCP keep-alive probes that
98 // should be sent before dropping a connection.
99 // If zero, the default is 9.
100 // If negative, underlying socket value is unchanged.
101 KeepAliveCountscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#KeepAliveCount. int `json:"keepalive_count,omitempty"`
102
103 // MaxHeaderBytes is the maximum size to parse from a client's
104 // HTTP request headers.
105 MaxHeaderBytesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#MaxHeaderBytes. int `json:"max_header_bytes,omitempty"`
106
107 // Enable full-duplex communication for HTTP/1 requests.
108 // Only has an effect if Caddy was built with Go 1.21 or later.
109 //
110 // For HTTP/1 requests, the Go HTTP server by default consumes any
111 // unread portion of the request body before beginning to write the
112 // response, preventing handlers from concurrently reading from the
113 // request and writing the response. Enabling this option disables
114 // this behavior and permits handlers to continue to read from the
115 // request while concurrently writing the response.
116 //
117 // For HTTP/2 requests, the Go HTTP server always permits concurrent
118 // reads and responses, so this option has no effect.
119 //
120 // Test thoroughly with your HTTP clients, as some older clients may
121 // not support full-duplex HTTP/1 which can cause them to deadlock.
122 // See https://github.com/golang/go/issues/57786 for more info.
123 //
124 // TODO: This is an EXPERIMENTAL feature. Subject to change or removal.
125 EnableFullDuplexscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#EnableFullDuplex. bool `json:"enable_full_duplex,omitempty"`
126
127 // Routes describes how this server will handle requests.
128 // Routes are executed sequentially. First a route's matchers
129 // are evaluated, then its grouping. If it matches and has
130 // not been mutually-excluded by its grouping, then its
131 // handlers are executed sequentially. The sequence of invoked
132 // handlers comprises a compiled middleware chain that flows
133 // from each matching route and its handlers to the next.
134 //
135 // By default, all unrouted requests receive a 200 OK response
136 // to indicate the server is working.
137 Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Routes. RouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RouteList# `json:"routes,omitempty"`
138
139 // Errors is how this server will handle errors returned from any
140 // of the handlers in the primary routes. If the primary handler
141 // chain returns an error, the error along with its recommended
142 // status code are bubbled back up to the HTTP server which
143 // executes a separate error route, specified using this property.
144 // The error routes work exactly like the normal routes.
145 Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Errors. *HTTPErrorConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig# `json:"errors,omitempty"`
146
147 // NamedRoutes describes a mapping of reusable routes that can be
148 // invoked by their name. This can be used to optimize memory usage
149 // when the same route is needed for many subroutes, by having
150 // the handlers and matchers be only provisioned once, but used from
151 // many places. These routes are not executed unless they are invoked
152 // from another route.
153 //
154 // EXPERIMENTAL: Subject to change or removal.
155 NamedRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#NamedRoutes. map[string]*Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route# `json:"named_routes,omitempty"`
156
157 // How to handle TLS connections. At least one policy is
158 // required to enable HTTPS on this server if automatic
159 // HTTPS is disabled or does not apply.
160 TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies. caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.ConnectionPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicies# `json:"tls_connection_policies,omitempty"`
161
162 // AutoHTTPS configures or disables automatic HTTPS within this server.
163 // HTTPS is enabled automatically and by default when qualifying names
164 // are present in a Host matcher and/or when the server is listening
165 // only on the HTTPS port.
166 AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. *AutoHTTPSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig# `json:"automatic_https,omitempty"`
167
168 // If true, will require that a request's Host header match
169 // the value of the ServerName sent by the client's TLS
170 // ClientHello; often a necessary safeguard when using TLS
171 // client authentication.
172 StrictSNIHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#StrictSNIHost. *bool `json:"strict_sni_host,omitempty"`
173
174 // A module which provides a source of IP ranges, from which
175 // requests should be trusted. By default, no proxies are
176 // trusted.
177 //
178 // On its own, this configuration will not do anything,
179 // but it can be used as a default set of ranges for
180 // handlers or matchers in routes to pick up, instead
181 // of needing to configure each of them. See the
182 // `reverse_proxy` handler for example, which uses this
183 // to trust sensitive incoming `X-Forwarded-*` headers.
184 TrustedProxiesRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TrustedProxiesRaw. jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/RawMessage# `json:"trusted_proxies,omitempty" caddy:"namespace=http.ip_sources inline_key=source"`
185
186 // The headers from which the client IP address could be
187 // read from. These will be considered in order, with the
188 // first good value being used as the client IP.
189 // By default, only `X-Forwarded-For` is considered.
190 //
191 // This depends on `trusted_proxies` being configured and
192 // the request being validated as coming from a trusted
193 // proxy, otherwise the client IP will be set to the direct
194 // remote IP address.
195 ClientIPHeadersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ClientIPHeaders. []string `json:"client_ip_headers,omitempty"`
196
197 // If greater than zero, enables strict ClientIPHeaders
198 // (default X-Forwarded-For) parsing. If enabled, the
199 // ClientIPHeaders will be parsed from right to left, and
200 // the first value that is both valid and doesn't match the
201 // trusted proxy list will be used as client IP. If zero,
202 // the ClientIPHeaders will be parsed from left to right,
203 // and the first value that is a valid IP address will be
204 // used as client IP.
205 //
206 // This depends on `trusted_proxies` being configured.
207 // This option is disabled by default.
208 TrustedProxiesStrictscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TrustedProxiesStrict. int `json:"trusted_proxies_strict,omitempty"`
209
210 // If greater than zero, enables trusting socket connections
211 // (e.g. Unix domain sockets) as coming from a trusted
212 // proxy.
213 //
214 // This option is disabled by default.
215 TrustedProxiesUnixscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TrustedProxiesUnix. bool `json:"trusted_proxies_unix,omitempty"`
216
217 // Enables access logging and configures how access logs are handled
218 // in this server. To minimally enable access logs, simply set this
219 // to a non-null, empty struct.
220 Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. *ServerLogConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig# `json:"logs,omitempty"`
221
222 // Protocols specifies which HTTP protocols to enable.
223 // Supported values are:
224 //
225 // - `h1` (HTTP/1.1)
226 // - `h2` (HTTP/2)
227 // - `h2c` (cleartext HTTP/2)
228 // - `h3` (HTTP/3)
229 //
230 // If enabling `h2` or `h2c`, `h1` must also be enabled;
231 // this is due to current limitations in the Go standard
232 // library.
233 //
234 // HTTP/2 operates only over TLS (HTTPS). HTTP/3 opens
235 // a UDP socket to serve QUIC connections.
236 //
237 // H2C operates over plain TCP if the client supports it;
238 // however, because this is not implemented by the Go
239 // standard library, other server options are not compatible
240 // and will not be applied to H2C requests. Do not enable this
241 // only to achieve maximum client compatibility. In practice,
242 // very few clients implement H2C, and even fewer require it.
243 // Enabling H2C can be useful for serving/proxying gRPC
244 // if encryption is not possible or desired.
245 //
246 // We recommend for most users to simply let Caddy use the
247 // default settings.
248 //
249 // Default: `[h1 h2 h3]`
250 Protocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Protocols. []string `json:"protocols,omitempty"`
251
252 // ListenProtocols overrides Protocols for each parallel address in Listen.
253 // A nil value or element indicates that Protocols will be used instead.
254 ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols. [][]string `json:"listen_protocols,omitempty"`
255
256 // If set, overrides whether QUIC listeners allow 0-RTT (early data).
257 // If nil, the default behavior is used (currently allowed).
258 //
259 // One reason to disable 0-RTT is if a remote IP matcher is used,
260 // which introduces a dependency on the remote address being verified
261 // if routing happens before the TLS handshake completes. An HTTP 425
262 // response is written in that case, but some clients misbehave and
263 // don't perform a retry, so disabling 0-RTT can smooth it out.
264 Allow0RTTscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Allow0RTT. *bool `json:"allow_0rtt,omitempty"`
265
266 // If set, metrics observations will be enabled.
267 // This setting is EXPERIMENTAL and subject to change.
268 // DEPRECATED: Use the app-level `metrics` field.
269 Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Metrics. *Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Metrics# `json:"metrics,omitempty"`
270
271 namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#name. string
272
273 primaryHandlerChainscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#primaryHandlerChain. Handlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler#
274 errorHandlerChainscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#errorHandlerChain. Handlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler#
275 listenerWrappersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#listenerWrappers. []caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ListenerWrapperscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ListenerWrapper#
276 packetConnWrappersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#packetConnWrappers. []caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.PacketConnWrapperscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/PacketConnWrapper#
277 listenersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#listeners. []netscip-go gomod github.com/golang/go/src go1.25.1 net/.Listenerscip-go gomod github.com/golang/go/src go1.25.1 net/Listener#
278 quicListenersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#quicListeners. []http3scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/.QUICListenerscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/QUICListener# // http3 now leave the quic.Listener management to us
279
280 tlsAppscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#tlsApp. *caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/TLS#
281 eventsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#events. *caddyeventsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyevents`/.Appscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyevents`/App#
282 loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#logger. *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#
283 accessLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#accessLogger. *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#
284 errorLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#errorLogger. *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#
285 traceLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#traceLogger. *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#
286 ctxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ctx. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#
287
288 serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#server. *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Serverscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#
289 h3serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#h3server. *http3scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/.Serverscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#
290 addressesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#addresses. []caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NetworkAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#
291
292 trustedProxiesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#trustedProxies. IPRangeSourcescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/IPRangeSource#
293
294 shutdownAtscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#shutdownAt. atomicscip-go gomod github.com/golang/go/src go1.25.1 `sync/atomic`/.Pointerscip-go gomod github.com/golang/go/src go1.25.1 `sync/atomic`/Pointer#[timescip-go gomod github.com/golang/go/src go1.25.1 time/.Timescip-go gomod github.com/golang/go/src go1.25.1 time/Time#]
295
296 // registered callback functions
297 connStateFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connStateFuncs. []func(netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#, httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ConnStatescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ConnState#)
298 connContextFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connContextFuncs. []func(ctx contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#, c netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#) contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#
299 onShutdownFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#onShutdownFuncs. []func()
300 onStopFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#onStopFuncs. []func(contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#) error // TODO: Experimental (Nov. 2023)
301 }
302
303 var defaultProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/defaultProtocols. = []string{"h1", "h2", "h3"}
304
305 var (
306 ServerHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerHeader. = "Caddy"
307 serverHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/serverHeader. = []string{ServerHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerHeader.}
308 )
309
310 // ServeHTTP is the entry point for all HTTP requests.
311 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ServeHTTP().(w httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) {
312 start := timescip-go gomod github.com/golang/go/src go1.25.1 time/.Nowscip-go gomod github.com/golang/go/src go1.25.1 time/Now().()
313
314 // If there are listener wrappers that process tls connections but don't return a *tls.Conn, this field will be nil.
315 if r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS. == nil {
316 if tlsConnStateFunc, ok := r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().().Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(tlsConnectionStateFuncCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/tlsConnectionStateFuncCtxKey.).(func() *tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.ConnectionStatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/ConnectionState#); ok {
317 r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS. = tlsConnStateFunc()
318 }
319 }
320
321 // enable full-duplex for HTTP/1, ensuring the entire
322 // request body gets consumed before writing the response
323 if s.EnableFullDuplexscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#EnableFullDuplex. && r.ProtoMajorscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#ProtoMajor. == 1 {
324 if err := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewResponseControllerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewResponseController().(w).EnableFullDuplexscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseController#EnableFullDuplex().(); err != nil { //nolint:bodyclose
325 if c := s.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.WarnLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/WarnLevel., "failed to enable full duplex"); c != nil {
326 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Errorscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Error().(err))
327 }
328 }
329 }
330
331 // set the Server header
332 h := w.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#Header().()
333 h["Server"] = serverHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/serverHeader.
334
335 // advertise HTTP/3, if enabled
336 if s.h3serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#h3server. != nil && r.ProtoMajorscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#ProtoMajor. < 3 {
337 if err := s.h3serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#h3server..SetQUICHeadersscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#SetQUICHeaders().(h); err != nil {
338 if c := s.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel., "setting HTTP/3 Alt-Svc header"); c != nil {
339 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Errorscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Error().(err))
340 }
341 }
342 }
343
344 // prepare internals of the request for the handler pipeline
345 repl := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NewReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewReplacer().()
346 r = PrepareRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/PrepareRequest().(r, repl, w, s)
347
348 // clone the request for logging purposes before it enters any handler chain;
349 // this is necessary to capture the original request in case it gets modified
350 // during handling (cloning the request and using .WithLazy is considerably
351 // faster than using .With, which will JSON-encode the request immediately)
352 shouldLogCredentials := s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. != nil && s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..ShouldLogCredentialsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#ShouldLogCredentials.
353 loggableReq := zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Objectscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Object().("request", LoggableHTTPRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/LoggableHTTPRequest#{
354 Requestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/LoggableHTTPRequest#Request.: r.Clonescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Clone().(r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().()),
355 ShouldLogCredentialsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/LoggableHTTPRequest#ShouldLogCredentials.: shouldLogCredentials,
356 })
357 errLog := s.errorLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#errorLogger..WithLazyscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#WithLazy().(loggableReq)
358
359 var duration timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#
360
361 if s.shouldLogRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#shouldLogRequest().(r) {
362 wrec := NewResponseRecorderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/NewResponseRecorder().(w, nil, nil)
363 w = wrec
364
365 // wrap the request body in a LengthReader
366 // so we can track the number of bytes read from it
367 var bodyReader *lengthReaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#
368 if r.Bodyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Body. != nil {
369 bodyReader = &lengthReaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#{Sourcescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Source.: r.Bodyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Body.}
370 r.Bodyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Body. = bodyReader
371
372 // should always be true, private interface can only be referenced in the same package
373 if setReadSizer, ok := wrec.(interface{ setReadSize(*int) }); ok {
374 setReadSizer.setReadSize(&bodyReader.Lengthscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Length.)
375 }
376 }
377
378 // capture the original version of the request
379 accLog := s.accessLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#accessLogger..WithLazyscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#WithLazy().(loggableReq)
380
381 defer s.logRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#logRequest().(accLog, r, wrec, &duration, repl, bodyReader, shouldLogCredentials)
382 }
383
384 // guarantee ACME HTTP challenges; handle them separately from any user-defined handlers
385 if s.tlsAppscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#tlsApp..HandleHTTPChallengescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/TLS#HandleHTTPChallenge().(w, r) {
386 duration = timescip-go gomod github.com/golang/go/src go1.25.1 time/.Sincescip-go gomod github.com/golang/go/src go1.25.1 time/Since().(start)
387 return
388 }
389
390 err := s.serveHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#serveHTTP().(w, r)
391 duration = timescip-go gomod github.com/golang/go/src go1.25.1 time/.Sincescip-go gomod github.com/golang/go/src go1.25.1 time/Since().(start)
392
393 if err == nil {
394 return
395 }
396
397 // restore original request before invoking error handler chain (issue #3717)
398 // NOTE: this does not restore original headers if modified (for efficiency)
399 origReq, ok := r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().().Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(OriginalRequestCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/OriginalRequestCtxKey.).(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#)
400 if ok {
401 r.Methodscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Method. = origReq.Methodscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Method.
402 r.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = origReq.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr.
403 r.RequestURIscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RequestURI. = origReq.RequestURIscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RequestURI.
404 cloneURLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/cloneURL().(origReq.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL., r.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL.)
405 }
406
407 // prepare the error log
408 errLog = errLog.Withscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#With().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Durationscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Duration().("duration", duration))
409 errLoggers := []*zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#{errLog}
410 if s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. != nil {
411 errLoggers = s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..wrapLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#wrapLogger().(errLog, r)
412 }
413
414 // get the values that will be used to log the error
415 errStatus, errMsg, errFields := errLogValuesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/errLogValues().(err)
416
417 // add HTTP error information to request context
418 r = s.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Errors..WithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig#WithError().(r, err)
419
420 var fields []zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.Fieldscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/Field#
421 if s.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Errors. != nil && len(s.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Errors..Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig#Routes.) > 0 {
422 // execute user-defined error handling route
423 if err2 := s.errorHandlerChainscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#errorHandlerChain..ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler#ServeHTTP.(w, r); err2 == nil {
424 // user's error route handled the error response successfully, so now just log the error
425 for _, logger := range errLoggers {
426 if c := logger.Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/DebugLevel., errMsg); c != nil {
427 if fields == nil {
428 fields = errFields()
429 }
430 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(fields...)
431 }
432 }
433 } else {
434 // well... this is awkward
435 for _, logger := range errLoggers {
436 if c := logger.Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel., "error handling handler error"); c != nil {
437 if fields == nil {
438 fields = errFields()
439 fields = append([]zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.Fieldscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/Field#{
440 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("error", err2.Error()),
441 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Namespacescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Namespace().("first_error"),
442 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("msg", errMsg),
443 }, fields...)
444 }
445 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(fields...)
446 }
447 }
448 if handlerErr, ok := err.(HandlerErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#); ok {
449 w.WriteHeaderscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#WriteHeader().(handlerErr.StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode.)
450 } else {
451 w.WriteHeaderscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusInternalServerError.)
452 }
453 }
454 } else {
455 logLevel := zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/DebugLevel.
456 if errStatus >= 500 {
457 logLevel = zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel.
458 }
459
460 for _, logger := range errLoggers {
461 if c := logger.Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(logLevel, errMsg); c != nil {
462 if fields == nil {
463 fields = errFields()
464 }
465 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(fields...)
466 }
467 }
468 w.WriteHeaderscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#WriteHeader().(errStatus)
469 }
470 }
471
472 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) serveHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#serveHTTP().(w httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) error {
473 // reject very long methods; probably a mistake or an attack
474 if len(r.Methodscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Method.) > 32 {
475 if s.shouldLogRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#shouldLogRequest().(r) {
476 if c := s.accessLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#accessLogger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/DebugLevel., "rejecting request with long method"); c != nil {
477 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(
478 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("method_trunc", r.Methodscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Method.[:32]),
479 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("remote_addr", r.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr.),
480 )
481 }
482 }
483 return HandlerErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#{StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode.: httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusMethodNotAllowedscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusMethodNotAllowed.}
484 }
485
486 // RFC 9112 section 3.2: "A server MUST respond with a 400 (Bad Request) status
487 // code to any HTTP/1.1 request message that lacks a Host header field and to any
488 // request message that contains more than one Host header field line or a Host
489 // header field with an invalid field value."
490 if r.ProtoMajorscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#ProtoMajor. == 1 && r.ProtoMinorscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#ProtoMinor. == 1 && r.Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host. == "" {
491 return HandlerErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#{
492 Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#Err.: errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/.Newscip-go gomod github.com/golang/go/src go1.25.1 errors/New().("rfc9112 forbids empty Host"),
493 StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode.: httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusBadRequest.,
494 }
495 }
496
497 // Drop headers whose names contain `_`: once FastCGI/CGI/FrankenPHP etc. rewrites `-` to
498 // `_`, an underscore alias collides with the legitimate hyphenated header
499 // and can bypass `forward_auth copy_headers` (GHSA-f59h-q822-g45g).
500 for k := range r.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header. {
501 if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ContainsRunescip-go gomod github.com/golang/go/src go1.25.1 strings/ContainsRune().(k, '_') {
502 delete(r.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header., k)
503
504 if c := s.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/DebugLevel., "dropping header containing underscore"); c != nil {
505 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("header", k))
506 }
507 }
508 }
509
510 // execute the primary handler chain
511 return s.primaryHandlerChainscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#primaryHandlerChain..ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler#ServeHTTP.(w, r)
512 }
513
514 // wrapPrimaryRoute wraps stack (a compiled middleware handler chain)
515 // in s.enforcementHandler which performs crucial security checks, etc.
516 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) wrapPrimaryRoutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#wrapPrimaryRoute().(stack Handlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler#) Handlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler# {
517 return HandlerFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) error {
518 return s.enforcementHandlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#enforcementHandler().(w, r, stack)
519 })
520 }
521
522 // enforcementHandler is an implicit middleware which performs
523 // standard checks before executing the HTTP middleware chain.
524 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) enforcementHandlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#enforcementHandler().(w httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, next Handlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler#) error {
525 // enforce strict host matching, which ensures that the SNI
526 // value (if any), matches the Host header; essential for
527 // servers that rely on TLS ClientAuth sharing a listener
528 // with servers that do not; if not enforced, client could
529 // bypass by sending benign SNI then restricted Host header
530 if s.StrictSNIHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#StrictSNIHost. != nil && *s.StrictSNIHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#StrictSNIHost. && r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS. != nil {
531 hostname, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(r.Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host.)
532 if err != nil {
533 hostname = r.Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host. // OK; probably lacked port
534 }
535 if !stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.25.1 strings/EqualFold().(r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS..ServerNamescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/ConnectionState#ServerName., hostname) {
536 err := fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("strict host matching: TLS ServerName (%s) and HTTP Host (%s) values differ",
537 r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS..ServerNamescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/ConnectionState#ServerName., hostname)
538 r.Closescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Close. = true
539 return Errorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Error().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusMisdirectedRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusMisdirectedRequest., err)
540 }
541 }
542 return next.ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Handler#ServeHTTP.(w, r)
543 }
544
545 // listenersUseAnyPortOtherThan returns true if there are any
546 // listeners in s that use a port which is not otherPort.
547 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) listenersUseAnyPortOtherThanscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#listenersUseAnyPortOtherThan().(otherPort int) bool {
548 for _, lnAddr := range s.Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen. {
549 laddrs, err := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ParseNetworkAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ParseNetworkAddress().(lnAddr)
550 if err != nil {
551 continue
552 }
553 if uint(otherPort) > laddrs.EndPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#EndPort. || uint(otherPort) < laddrs.StartPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#StartPort. {
554 return true
555 }
556 }
557 return false
558 }
559
560 // hasListenerAddress returns true if s has a listener
561 // at the given address fullAddr. Currently, fullAddr
562 // must represent exactly one socket address (port
563 // ranges are not supported)
564 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) hasListenerAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#hasListenerAddress().(fullAddr string) bool {
565 laddrs, err := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ParseNetworkAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ParseNetworkAddress().(fullAddr)
566 if err != nil {
567 return false
568 }
569 if laddrs.PortRangeSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#PortRangeSize().() != 1 {
570 return false // TODO: support port ranges
571 }
572
573 for _, lnAddr := range s.Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen. {
574 thisAddrs, err := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ParseNetworkAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ParseNetworkAddress().(lnAddr)
575 if err != nil {
576 continue
577 }
578 if thisAddrs.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network. != laddrs.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network. {
579 continue
580 }
581
582 // Apparently, Linux requires all bound ports to be distinct
583 // *regardless of host interface* even if the addresses are
584 // in fact different; binding "192.168.0.1:9000" and then
585 // ":9000" will fail for ":9000" because "address is already
586 // in use" even though it's not, and the same bindings work
587 // fine on macOS. I also found on Linux that listening on
588 // "[::]:9000" would fail with a similar error, except with
589 // the address "0.0.0.0:9000", as if deliberately ignoring
590 // that I specified the IPv6 interface explicitly. This seems
591 // to be a major bug in the Linux network stack and I don't
592 // know why it hasn't been fixed yet, so for now we have to
593 // special-case ourselves around Linux like a doting parent.
594 // The second issue seems very similar to a discussion here:
595 // https://github.com/nodejs/node/issues/9390
596 //
597 // However, binding to *different specific* interfaces
598 // (e.g. 127.0.0.2:80 and 127.0.0.3:80) IS allowed on Linux.
599 // The conflict only happens when mixing specific IPs with
600 // wildcards (0.0.0.0 or ::).
601
602 // Hosts match exactly (e.g. 127.0.0.2 == 127.0.0.2) -> Conflict.
603 hostMatch := thisAddrs.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Host. == laddrs.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Host.
604
605 // On Linux, specific IP vs Wildcard fails to bind.
606 // So if we are on Linux AND either host is empty (wildcard), we treat
607 // it as a match (conflict). But if both are specific and different
608 // (127.0.0.2 vs 127.0.0.3), this remains false (no conflict).
609 linuxWildcardConflict := runtimescip-go gomod github.com/golang/go/src go1.25.1 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.1 runtime/GOOS. == "linux" && (thisAddrs.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Host. == "" || laddrs.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Host. == "")
610
611 if (hostMatch || linuxWildcardConflict) &&
612 (laddrs.StartPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#StartPort. <= thisAddrs.EndPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#EndPort.) &&
613 (laddrs.StartPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#StartPort. >= thisAddrs.StartPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#StartPort.) {
614 return true
615 }
616 }
617 return false
618 }
619
620 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) hasTLSClientAuthscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#hasTLSClientAuth().() bool {
621 return slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.ContainsFuncscip-go gomod github.com/golang/go/src go1.25.1 slices/ContainsFunc().(s.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies., func(cp *caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.ConnectionPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#) bool {
622 return cp.ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication. != nil && cp.ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication..Activescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ClientAuthentication#Active().()
623 })
624 }
625
626 // findLastRouteWithHostMatcher returns the index of the last route
627 // in the server which has a host matcher. Used during Automatic HTTPS
628 // to determine where to insert the HTTP->HTTPS redirect route, such
629 // that it is after any other host matcher but before any "catch-all"
630 // route without a host matcher.
631 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) findLastRouteWithHostMatcherscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#findLastRouteWithHostMatcher().() int {
632 foundHostMatcher := false
633 lastIndex := len(s.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Routes.)
634
635 for i, route := range s.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Routes. {
636 // since we want to break out of an inner loop, use a closure
637 // to allow us to use 'return' when we found a host matcher
638 found := (func() bool {
639 for _, sets := range route.MatcherSetsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSets. {
640 for _, matcher := range sets {
641 switch matcher.(type) {
642 case *MatchHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchHost#:
643 foundHostMatcher = true
644 return true
645 }
646 }
647 }
648 return false
649 })()
650
651 // if we found the host matcher, change the lastIndex to
652 // just after the current route
653 if found {
654 lastIndex = i + 1
655 }
656 }
657
658 // If we didn't actually find a host matcher, return 0
659 // because that means every defined route was a "catch-all".
660 // See https://caddy.community/t/how-to-set-priority-in-caddyfile/13002/8
661 if !foundHostMatcher {
662 return 0
663 }
664
665 return lastIndex
666 }
667
668 // serveHTTP3 creates a QUIC listener, configures an HTTP/3 server if
669 // not already done, and then uses that server to serve HTTP/3 over
670 // the listener, with Server s as the handler.
671 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) serveHTTP3scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#serveHTTP3().(addr caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NetworkAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#, tlsCfg *tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#) error {
672 h3net, err := getHTTP3Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/getHTTP3Network().(addr.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network.)
673 if err != nil {
674 return fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("starting HTTP/3 QUIC listener: %v", err)
675 }
676 addr.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network. = h3net
677 h3ln, err := addr.ListenQUICscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#ListenQUIC().(s.ctxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ctx., 0, netscip-go gomod github.com/golang/go/src go1.25.1 net/.ListenConfigscip-go gomod github.com/golang/go/src go1.25.1 net/ListenConfig#{}, tlsCfg, s.packetConnWrappersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#packetConnWrappers., s.Allow0RTTscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Allow0RTT.)
678 if err != nil {
679 return fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("starting HTTP/3 QUIC listener: %v", err)
680 }
681
682 // create HTTP/3 server if not done already
683 if s.h3serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#h3server. == nil {
684 s.h3serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#h3server. = &http3scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/.Serverscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#{
685 Handlerscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#Handler.: s,
686 TLSConfigscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#TLSConfig.: tlsCfg,
687 MaxHeaderBytesscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#MaxHeaderBytes.: s.MaxHeaderBytesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#MaxHeaderBytes.,
688 QUICConfigscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#QUICConfig.: &quicscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/.Configscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/Config#{
689 Versionsscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/Config#Versions.: []quicscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/.Versionscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/Version#{quicscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/.Version1scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/Version1., quicscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/.Version2scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/Version2.},
690 Tracerscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go`/Config#Tracer.: h3qlogscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3/qlog`/.DefaultConnectionTracerscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3/qlog`/DefaultConnectionTracer().,
691 },
692 IdleTimeoutscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#IdleTimeout.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(s.IdleTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#IdleTimeout.),
693 }
694 }
695
696 s.quicListenersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#quicListeners. = append(s.quicListenersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#quicListeners., h3ln)
697
698 //nolint:errcheck
699 go s.h3serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#h3server..ServeListenerscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Server#ServeListener().(h3ln)
700
701 return nil
702 }
703
704 // configureServer applies/binds the registered callback functions to the server.
705 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) configureServerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#configureServer().(server *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Serverscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#) {
706 for _, f := range s.connStateFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connStateFuncs. {
707 if server.ConnStatescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnState. != nil {
708 baseConnStateFunc := server.ConnStatescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnState.
709 server.ConnStatescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnState. = func(conn netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#, state httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ConnStatescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ConnState#) {
710 baseConnStateFunc(conn, state)
711 f(conn, state)
712 }
713 } else {
714 server.ConnStatescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnState. = f
715 }
716 }
717
718 for _, f := range s.connContextFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connContextFuncs. {
719 if server.ConnContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnContext. != nil {
720 baseConnContextFunc := server.ConnContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnContext.
721 server.ConnContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnContext. = func(ctx contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#, c netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#) contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context# {
722 return f(baseConnContextFunc(ctx, c), c)
723 }
724 } else {
725 server.ConnContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#ConnContext. = f
726 }
727 }
728
729 for _, f := range s.onShutdownFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#onShutdownFuncs. {
730 server.RegisterOnShutdownscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Server#RegisterOnShutdown().(f)
731 }
732 }
733
734 // RegisterConnState registers f to be invoked on s.ConnState.
735 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) RegisterConnStatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#RegisterConnState().(f func(netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#, httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ConnStatescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ConnState#)) {
736 s.connStateFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connStateFuncs. = append(s.connStateFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connStateFuncs., f)
737 }
738
739 // RegisterConnContext registers f to be invoked as part of s.ConnContext.
740 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) RegisterConnContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#RegisterConnContext().(f func(ctx contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#, c netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#) contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#) {
741 s.connContextFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connContextFuncs. = append(s.connContextFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#connContextFuncs., f)
742 }
743
744 // RegisterOnShutdown registers f to be invoked when the server begins to shut down.
745 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) RegisterOnShutdownscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#RegisterOnShutdown().(f func()) {
746 s.onShutdownFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#onShutdownFuncs. = append(s.onShutdownFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#onShutdownFuncs., f)
747 }
748
749 // RegisterOnStop registers f to be invoked after the server has shut down completely.
750 //
751 // EXPERIMENTAL: Subject to change or removal.
752 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) RegisterOnStopscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#RegisterOnStop().(f func(contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#) error) {
753 s.onStopFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#onStopFuncs. = append(s.onStopFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#onStopFuncs., f)
754 }
755
756 // HTTPErrorConfig determines how to handle errors
757 // from the HTTP handlers.
758 type HTTPErrorConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig# struct {
759 // The routes to evaluate after the primary handler
760 // chain returns an error. In an error route, extra
761 // placeholders are available:
762 //
763 // Placeholder | Description
764 // ------------|---------------
765 // `{http.error.status_code}` | The recommended HTTP status code
766 // `{http.error.status_text}` | The status text associated with the recommended status code
767 // `{http.error.message}` | The error message
768 // `{http.error.trace}` | The origin of the error
769 // `{http.error.id}` | An identifier for this occurrence of the error
770 Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig#Routes. RouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RouteList# `json:"routes,omitempty"`
771 }
772
773 // WithError makes a shallow copy of r to add the error to its
774 // context, and sets placeholders on the request's replacer
775 // related to err. It returns the modified request which has
776 // the error information in its context and replacer. It
777 // overwrites any existing error values that are stored.
778 func (*HTTPErrorConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig#) WithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig#WithError().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, err error) *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request# {
779 // add the raw error value to the request context
780 // so it can be accessed by error handlers
781 c := contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), ErrorCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ErrorCtxKey., err)
782 r = r.WithContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#WithContext().(c)
783
784 // add error values to the replacer
785 repl := r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().().Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ReplacerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ReplacerCtxKey.).(*caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#)
786 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.error", err)
787 if handlerErr, ok := err.(HandlerErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#); ok {
788 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.error.status_code", handlerErr.StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode.)
789 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.error.status_text", httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusTextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusText().(handlerErr.StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode.))
790 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.error.id", handlerErr.IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#ID.)
791 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.error.trace", handlerErr.Tracescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#Trace.)
792 if handlerErr.Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#Err. != nil {
793 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.error.message", handlerErr.Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#Err..Error())
794 } else {
795 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.error.message", httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusTextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusText().(handlerErr.StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode.))
796 }
797 }
798
799 return r
800 }
801
802 // shouldLogRequest returns true if this request should be logged.
803 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) shouldLogRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#shouldLogRequest().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) bool {
804 if s.accessLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#accessLogger. == nil || s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. == nil {
805 // logging is disabled
806 return false
807 }
808
809 // strip off the port if any, logger names are host only
810 hostWithoutPort, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(r.Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host.)
811 if err != nil {
812 hostWithoutPort = r.Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host.
813 }
814
815 for loggerName := range s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..LoggerNamesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#LoggerNames. {
816 if certmagicscip-go gomod github.com/caddyserver/certmagic v0.25.3 `github.com/caddyserver/certmagic`/.MatchWildcardscip-go gomod github.com/caddyserver/certmagic v0.25.3 `github.com/caddyserver/certmagic`/MatchWildcard().(hostWithoutPort, loggerName) {
817 // this host is mapped to a particular logger name
818 return true
819 }
820 }
821 for _, dh := range s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..SkipHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#SkipHosts. {
822 // logging for this particular host is disabled
823 if certmagicscip-go gomod github.com/caddyserver/certmagic v0.25.3 `github.com/caddyserver/certmagic`/.MatchWildcardscip-go gomod github.com/caddyserver/certmagic v0.25.3 `github.com/caddyserver/certmagic`/MatchWildcard().(hostWithoutPort, dh) {
824 return false
825 }
826 }
827 // if configured, this host is not mapped and thus must not be logged
828 return !s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..SkipUnmappedHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#SkipUnmappedHosts.
829 }
830
831 // logTrace will log that this middleware handler is being invoked.
832 // It emits at DEBUG level.
833 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) logTracescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#logTrace().(mh MiddlewareHandlerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MiddlewareHandler#) {
834 if s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. == nil || !s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..Tracescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#Trace. {
835 return
836 }
837 if c := s.traceLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#traceLogger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/DebugLevel., caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.GetModuleNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/GetModuleName().(mh)); c != nil {
838 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Anyscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Any().("module", mh))
839 }
840 }
841
842 // logRequest logs the request to access logs, unless skipped.
843 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) logRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#logRequest().(
844 accLog *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#, r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, wrec ResponseRecorderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ResponseRecorder#, duration *timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#,
845 repl *caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#, bodyReader *lengthReaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#, shouldLogCredentials bool,
846 ) {
847 ctx := r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().()
848
849 // this request may be flagged as omitted from the logs
850 if skip, ok := GetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/GetVar().(ctx, LogSkipVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/LogSkipVar.).(bool); ok && skip {
851 return
852 }
853
854 status := wrec.Statusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ResponseRecorder#Status.()
855 size := wrec.Sizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ResponseRecorder#Size.()
856
857 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.response.status", status) // will be 0 if no response is written by us (Go will write 200 to client)
858 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.response.size", size)
859 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.response.duration", duration)
860 repl.Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#Set().("http.response.duration_ms", duration.Secondsscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#Seconds().()*1e3) // multiply seconds to preserve decimal (see #4666)
861
862 loggers := []*zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#{accLog}
863 if s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. != nil {
864 loggers = s.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..wrapLoggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#wrapLogger().(accLog, r)
865 }
866
867 message := "handled request"
868 if nop, ok := GetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/GetVar().(ctx, "unhandled").(bool); ok && nop {
869 message = "NOP"
870 }
871
872 logLevel := zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.InfoLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/InfoLevel.
873 if status >= 500 {
874 logLevel = zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel.
875 }
876
877 var fields []zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.Fieldscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/Field#
878 for _, logger := range loggers {
879 c := logger.Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(logLevel, message)
880 if c == nil {
881 continue
882 }
883
884 if fields == nil {
885 userID, _ := repl.GetStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#GetString().("http.auth.user.id")
886
887 reqBodyLength := 0
888 if bodyReader != nil {
889 reqBodyLength = bodyReader.Lengthscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Length.
890 }
891
892 extra := ctx.Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(ExtraLogFieldsCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ExtraLogFieldsCtxKey.).(*ExtraLogFieldsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ExtraLogFields#)
893
894 fieldCount := 6
895 fields = make([]zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.Fieldscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/Field#, 0, fieldCount+len(extra.fieldsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ExtraLogFields#fields.))
896 fields = append(fields,
897 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Intscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Int().("bytes_read", reqBodyLength),
898 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("user_id", userID),
899 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Durationscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Duration().("duration", *duration),
900 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Intscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Int().("size", size),
901 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Intscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Int().("status", status),
902 zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Objectscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Object().("resp_headers", LoggableHTTPHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/LoggableHTTPHeader#{
903 Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/internal`/LoggableHTTPHeader#Header.: wrec.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#Header().(),
904 ShouldLogCredentialsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/internal`/LoggableHTTPHeader#ShouldLogCredentials.: shouldLogCredentials,
905 }),
906 )
907 fields = append(fields, extra.fieldsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ExtraLogFields#fields....)
908 }
909
910 c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(fields...)
911 }
912 }
913
914 // protocol returns true if the protocol proto is configured/enabled.
915 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) protocolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#protocol().(proto string) bool {
916 if s.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols. == nil {
917 return slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(s.protocolsWithDefaultsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#protocolsWithDefaults().(), proto)
918 }
919
920 for _, lnProtocols := range s.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols. {
921 if slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(s.listenerProtocolsWithDefaultsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#listenerProtocolsWithDefaults().(lnProtocols), proto) {
922 return true
923 }
924 }
925
926 return false
927 }
928
929 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) protocolsWithDefaultsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#protocolsWithDefaults().() []string {
930 if len(s.Protocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Protocols.) == 0 {
931 return defaultProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/defaultProtocols.
932 }
933 return s.Protocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Protocols.
934 }
935
936 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) listenerProtocolsWithDefaultsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#listenerProtocolsWithDefaults().(lnProtocols []string) []string {
937 serverProtocols := s.protocolsWithDefaultsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#protocolsWithDefaults().()
938 if len(lnProtocols) == 0 {
939 return serverProtocols
940 }
941
942 lnProtocolsDefault := false
943 lnProtocolsInclude := make([]string, 0, len(lnProtocols)+len(serverProtocols))
944 srvProtocolsInclude := make(map[string]struct{}, len(serverProtocols))
945 for _, srvProtocol := range serverProtocols {
946 srvProtocolsInclude[srvProtocol] = struct{}{}
947 }
948
949 for _, lnProtocol := range lnProtocols {
950 if lnProtocol == "" {
951 lnProtocolsDefault = true
952 continue
953 }
954 lnProtocolsInclude = append(lnProtocolsInclude, lnProtocol)
955 delete(srvProtocolsInclude, lnProtocol)
956 }
957
958 if lnProtocolsDefault {
959 for _, srvProtocol := range serverProtocols {
960 if _, ok := srvProtocolsInclude[srvProtocol]; ok {
961 lnProtocolsInclude = append(lnProtocolsInclude, srvProtocol)
962 }
963 }
964 }
965
966 return lnProtocolsInclude
967 }
968
969 // Listeners returns the server's listeners. These are active listeners,
970 // so calling Accept() or Close() on them will probably break things.
971 // They are made available here for read-only purposes (e.g. Addr())
972 // and for type-asserting for purposes where you know what you're doing.
973 //
974 // EXPERIMENTAL: Subject to change or removal.
975 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) Listenersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listeners().() []netscip-go gomod github.com/golang/go/src go1.25.1 net/.Listenerscip-go gomod github.com/golang/go/src go1.25.1 net/Listener# { return s.listenersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#listeners. }
976
977 // Name returns the server's name.
978 func (s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Name().() string { return s.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#name. }
979
980 // PrepareRequest fills the request r for use in a Caddy HTTP handler chain. w and s can
981 // be nil, but the handlers will lose response placeholders and access to the server.
982 func PrepareRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/PrepareRequest().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, repl *caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#, w httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request# {
983 // set up the context for the request
984 ctx := contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ReplacerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ReplacerCtxKey., repl)
985 ctx = contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(ctx, ServerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerCtxKey., s)
986
987 trusted, clientIP := determineTrustedProxyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/determineTrustedProxy().(r, s)
988 ctx = contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(ctx, VarsCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/VarsCtxKey., map[string]any{
989 TrustedProxyVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/TrustedProxyVarKey.: trusted,
990 ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey.: clientIP,
991 })
992
993 ctx = contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(ctx, routeGroupCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/routeGroupCtxKey., make(map[string]struct{}))
994
995 var url2 urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL# // avoid letting this escape to the heap
996 ctx = contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(ctx, OriginalRequestCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/OriginalRequestCtxKey., originalRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/originalRequest().(r, &url2))
997
998 ctx = contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(ctx, ExtraLogFieldsCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ExtraLogFieldsCtxKey., new(ExtraLogFieldsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ExtraLogFields#))
999 r = r.WithContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#WithContext().(ctx)
1000
1001 // once the pointer to the request won't change
1002 // anymore, finish setting up the replacer
1003 addHTTPVarsToReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/addHTTPVarsToReplacer().(repl, r, w)
1004
1005 return r
1006 }
1007
1008 // originalRequest returns a partial, shallow copy of
1009 // req, including: req.Method, deep copy of req.URL
1010 // (into the urlCopy parameter, which should be on the
1011 // stack), req.RequestURI, and req.RemoteAddr. Notably,
1012 // headers are not copied. This function is designed to
1013 // be very fast and efficient, and useful primarily for
1014 // read-only/logging purposes.
1015 func originalRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/originalRequest().(req *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, urlCopy *urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#) httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request# {
1016 cloneURLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/cloneURL().(req.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL., urlCopy)
1017 return httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#{
1018 Methodscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Method.: req.Methodscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Method.,
1019 RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr.: req.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr.,
1020 RequestURIscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RequestURI.: req.RequestURIscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RequestURI.,
1021 URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL.: urlCopy,
1022 }
1023 }
1024
1025 // determineTrustedProxy parses the remote IP address of
1026 // the request, and determines (if the server configured it)
1027 // if the client is a trusted proxy. If trusted, also returns
1028 // the real client IP if possible.
1029 func determineTrustedProxyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/determineTrustedProxy().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, s *Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#) (bool, string) {
1030 // If there's no server, then we can't check anything
1031 if s == nil {
1032 return false, ""
1033 }
1034
1035 if s.TrustedProxiesUnixscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TrustedProxiesUnix. && r.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. == "@" {
1036 if s.TrustedProxiesStrictscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TrustedProxiesStrict. > 0 {
1037 ipRanges := []netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#{}
1038 if s.trustedProxiesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#trustedProxies. != nil {
1039 ipRanges = s.trustedProxiesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#trustedProxies..GetIPRangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/IPRangeSource#GetIPRanges.(r)
1040 }
1041 return true, strictUntrustedClientIpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/strictUntrustedClientIp().(r, s.ClientIPHeadersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ClientIPHeaders., ipRanges, "@")
1042 } else {
1043 return true, trustedRealClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/trustedRealClientIP().(r, s.ClientIPHeadersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ClientIPHeaders., "@")
1044 }
1045 }
1046 // Parse the remote IP, ignore the error as non-fatal,
1047 // but the remote IP is required to continue, so we
1048 // just return early. This should probably never happen
1049 // though, unless some other module manipulated the request's
1050 // remote address and used an invalid value.
1051 clientIP, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(r.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr.)
1052 if err != nil {
1053 return false, ""
1054 }
1055
1056 // Client IP may contain a zone if IPv6, so we need
1057 // to pull that out before parsing the IP
1058 clientIP, _, _ = stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Cutscip-go gomod github.com/golang/go/src go1.25.1 strings/Cut().(clientIP, "%")
1059 ipAddr, err := netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/ParseAddr().(clientIP)
1060 if err != nil {
1061 return false, ""
1062 }
1063
1064 // Check if the client is a trusted proxy
1065 if s.trustedProxiesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#trustedProxies. == nil {
1066 return false, ipAddr.Stringscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#String().()
1067 }
1068
1069 if isTrustedClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/isTrustedClientIP().(ipAddr, s.trustedProxiesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#trustedProxies..GetIPRangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/IPRangeSource#GetIPRanges.(r)) {
1070 if s.TrustedProxiesStrictscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TrustedProxiesStrict. > 0 {
1071 return true, strictUntrustedClientIpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/strictUntrustedClientIp().(r, s.ClientIPHeadersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ClientIPHeaders., s.trustedProxiesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#trustedProxies..GetIPRangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/IPRangeSource#GetIPRanges.(r), ipAddr.Stringscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#String().())
1072 }
1073 return true, trustedRealClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/trustedRealClientIP().(r, s.ClientIPHeadersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ClientIPHeaders., ipAddr.Stringscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#String().())
1074 }
1075
1076 return false, ipAddr.Stringscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#String().()
1077 }
1078
1079 // isTrustedClientIP returns true if the given IP address is
1080 // in the list of trusted IP ranges.
1081 func isTrustedClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/isTrustedClientIP().(ipAddr netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Addrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#, trusted []netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#) bool {
1082 return slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.ContainsFuncscip-go gomod github.com/golang/go/src go1.25.1 slices/ContainsFunc().(trusted, func(prefix netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#) bool {
1083 return prefix.Containsscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#Contains().(ipAddr)
1084 })
1085 }
1086
1087 // trustedRealClientIP finds the client IP from the request assuming it is
1088 // from a trusted client. If there is no client IP headers, then the
1089 // direct remote address is returned. If there are client IP headers,
1090 // then the first value from those headers is used.
1091 func trustedRealClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/trustedRealClientIP().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, headers []string, clientIP string) string {
1092 // Read all the values of the configured client IP headers, in order
1093 // nolint:prealloc
1094 var values []string
1095 for _, field := range headers {
1096 values = append(values, r.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header..Valuesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Values().(field)...)
1097 }
1098
1099 // If we don't have any values, then give up
1100 if len(values) == 0 {
1101 return clientIP
1102 }
1103
1104 // Since there can be many header values, we need to
1105 // join them together before splitting to get the full list
1106 allValues := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.SplitSeqscip-go gomod github.com/golang/go/src go1.25.1 strings/SplitSeq().(stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.1 strings/Join().(values, ","), ",")
1107
1108 // Get first valid left-most IP address
1109 for part := range allValues {
1110 // Some proxies may retain the port number, so split if possible
1111 host, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(part)
1112 if err != nil {
1113 host = part
1114 }
1115
1116 // Remove any zone identifier from the IP address
1117 host, _, _ = stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Cutscip-go gomod github.com/golang/go/src go1.25.1 strings/Cut().(stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.1 strings/TrimSpace().(host), "%")
1118
1119 // Parse the IP address
1120 ipAddr, err := netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/ParseAddr().(host)
1121 if err != nil {
1122 continue
1123 }
1124 return ipAddr.Stringscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#String().()
1125 }
1126
1127 // We didn't find a valid IP
1128 return clientIP
1129 }
1130
1131 // strictUntrustedClientIp iterates through the list of client IP headers,
1132 // parses them from right-to-left, and returns the first valid IP address
1133 // that is untrusted. If no valid IP address is found, then the direct
1134 // remote address is returned.
1135 func strictUntrustedClientIpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/strictUntrustedClientIp().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, headers []string, trusted []netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#, clientIP string) string {
1136 for _, headerName := range headers {
1137 parts := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.1 strings/Split().(stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.1 strings/Join().(r.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header..Valuesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Values().(headerName), ","), ",")
1138
1139 for _, part := range slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Backwardscip-go gomod github.com/golang/go/src go1.25.1 slices/Backward().(parts) {
1140 // Some proxies may retain the port number, so split if possible
1141 host, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(part)
1142 if err != nil {
1143 host = part
1144 }
1145
1146 // Remove any zone identifier from the IP address
1147 host, _, _ = stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Cutscip-go gomod github.com/golang/go/src go1.25.1 strings/Cut().(stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.1 strings/TrimSpace().(host), "%")
1148
1149 // Parse the IP address
1150 ipAddr, err := netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/ParseAddr().(host)
1151 if err != nil {
1152 continue
1153 }
1154 if !isTrustedClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/isTrustedClientIP().(ipAddr, trusted) {
1155 return ipAddr.Stringscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#String().()
1156 }
1157 }
1158 }
1159
1160 return clientIP
1161 }
1162
1163 // cloneURL makes a copy of r.URL and returns a
1164 // new value that doesn't reference the original.
1165 func cloneURLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/cloneURL().(from, to *urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#) {
1166 *to = *from
1167 if from.Userscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#User. != nil {
1168 userInfo := new(urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.Userinfoscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/Userinfo#)
1169 *userInfo = *from.Userscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#User.
1170 to.Userscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#User. = userInfo
1171 }
1172 }
1173
1174 // lengthReader is an io.ReadCloser that keeps track of the
1175 // number of bytes read from the request body.
1176 type lengthReaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader# struct {
1177 Sourcescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Source. ioscip-go gomod github.com/golang/go/src go1.25.1 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.25.1 io/ReadCloser#
1178 Lengthscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Length. int
1179 }
1180
1181 func (r *lengthReaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#) Readscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Read().(b []byte) (int, error) {
1182 n, err := r.Sourcescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Source..Readscip-go gomod github.com/golang/go/src go1.25.1 io/Reader#Read().(b)
1183 r.Lengthscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Length. += n
1184 return n, err
1185 }
1186
1187 func (r *lengthReaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#) Closescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Close().() error {
1188 return r.Sourcescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/lengthReader#Source..Closescip-go gomod github.com/golang/go/src go1.25.1 io/Closer#Close().()
1189 }
1190
1191 // Context keys for HTTP request context values.
1192 const (
1193 // For referencing the server instance
1194 ServerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerCtxKey. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CtxKey# = "server"
1195
1196 // For the request's variable table
1197 VarsCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/VarsCtxKey. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CtxKey# = "vars"
1198
1199 // For a partial copy of the unmodified request that
1200 // originally came into the server's entry handler
1201 OriginalRequestCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/OriginalRequestCtxKey. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CtxKey# = "original_request"
1202
1203 // DEPRECATED: not used anymore.
1204 // To refer to the underlying connection, implement a middleware plugin
1205 // that RegisterConnContext during provisioning.
1206 ConnCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ConnCtxKey. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CtxKey# = "conn"
1207
1208 // used to get the tls connection state in the context, if available
1209 tlsConnectionStateFuncCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/tlsConnectionStateFuncCtxKey. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CtxKey# = "tls_connection_state_func"
1210
1211 // For tracking whether the client is a trusted proxy
1212 TrustedProxyVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/TrustedProxyVarKey. string = "trusted_proxy"
1213
1214 // For tracking the real client IP (affected by trusted_proxy)
1215 ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey. string = "client_ip"
1216 )
1217
1218 var networkTypesHTTP3scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/networkTypesHTTP3. = map[string]string{
1219 "unixgram": "unixgram",
1220 "udp": "udp",
1221 "udp4": "udp4",
1222 "udp6": "udp6",
1223 "tcp": "udp",
1224 "tcp4": "udp4",
1225 "tcp6": "udp6",
1226 "fdgram": "fdgram",
1227 }
1228
1229 // RegisterNetworkHTTP3 registers a mapping from non-HTTP/3 network to HTTP/3
1230 // network. This should be called during init() and will panic if the network
1231 // type is standard, reserved, or already registered.
1232 //
1233 // EXPERIMENTAL: Subject to change.
1234 func RegisterNetworkHTTP3scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RegisterNetworkHTTP3().(originalNetwork, h3Network string) {
1235 if _, ok := networkTypesHTTP3scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/networkTypesHTTP3.[stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(originalNetwork)]; ok {
1236 panic("network type " + originalNetwork + " is already registered")
1237 }
1238 networkTypesHTTP3scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/networkTypesHTTP3.[originalNetwork] = h3Network
1239 }
1240
1241 func getHTTP3Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/getHTTP3Network().(originalNetwork string) (string, error) {
1242 h3Network, ok := networkTypesHTTP3scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/networkTypesHTTP3.[stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.1 strings/ToLower().(originalNetwork)]
1243 if !ok {
1244 return "", fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("network '%s' cannot handle HTTP/3 connections", originalNetwork)
1245 }
1246 return h3Network, nil
1247 }