Debian Codegraph @

caddyconfig/httpcaddyfile/httptype.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 httpcaddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/
16
17 import (
18 "cmpscip-go gomod github.com/golang/go/src go1.25.1 cmp/"
19 "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/"
20 "fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/"
21 "netscip-go gomod github.com/golang/go/src go1.25.1 net/"
22 "reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/"
23 "slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/"
24 "sortscip-go gomod github.com/golang/go/src go1.25.1 sort/"
25 "strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/"
26 "stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/"
27
28 "go.uber.org/zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/"
29
30 "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/"
31 "github.com/caddyserver/caddy/v2/caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/"
32 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/"
33 "github.com/caddyserver/caddy/v2/modules/caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/"
34 "github.com/caddyserver/caddy/v2/modules/caddypkiscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/"
35 "github.com/caddyserver/caddy/v2/modules/caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/"
36 )
37
38 func initscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/init().() {
39 caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.RegisterAdapterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/RegisterAdapter().("caddyfile", caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Adapterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Adapter#{ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Adapter#ServerType.: ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#{}})
40 }
41
42 // App represents the configuration for a non-standard
43 // Caddy app module (e.g. third-party plugin) which was
44 // parsed from a global options block.
45 type Appscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/App# struct {
46 // The JSON key for the app being configured
47 Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/App#Name. string
48
49 // The raw app config as JSON
50 Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/App#Value. 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#
51 }
52
53 // ServerType can set up a config from an HTTP Caddyfile.
54 type ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType# struct{}
55
56 // Setup makes a config from the tokens.
57 func (st ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#) Setupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#Setup().(
58 inputServerBlocks []caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.ServerBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#,
59 options map[string]any,
60 ) (*caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#, []caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#, error) {
61 var warnings []caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#
62 gc := counterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#{new(int)}
63 state := make(map[string]any)
64
65 // load all the server blocks and associate them with a "pile" of config values
66 originalServerBlocks := make([]serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#, 0, len(inputServerBlocks))
67 for _, sblock := range inputServerBlocks {
68 for j, k := range sblock.Keysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Keys. {
69 if j == 0 && stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.1 strings/HasPrefix().(k.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text., "@") {
70 return nil, warnings, 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().("%s:%d: cannot define a matcher outside of a site block: '%s'", k.Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#File., k.Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Line., k.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text.)
71 }
72 if _, ok := registeredDirectivesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/registeredDirectives.[k.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text.]; ok {
73 return nil, warnings, 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().("%s:%d: parsed '%s' as a site address, but it is a known directive; directives must appear in a site block", k.Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#File., k.Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Line., k.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text.)
74 }
75 }
76 originalServerBlocks = append(originalServerBlocks, serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#{
77 blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block.: sblock,
78 pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.: make(map[string][]ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#),
79 })
80 }
81
82 // apply any global options
83 var err error
84 originalServerBlocks, err = st.evaluateGlobalOptionsBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#evaluateGlobalOptionsBlock().(originalServerBlocks, options)
85 if err != nil {
86 return nil, warnings, err
87 }
88
89 // this will replace both static and user-defined placeholder shorthands
90 // with actual identifiers used by Caddy
91 replacer := NewShorthandReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/NewShorthandReplacer().()
92
93 originalServerBlocks, err = st.extractNamedRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#extractNamedRoutes().(originalServerBlocks, options, &warnings, replacer)
94 if err != nil {
95 return nil, warnings, err
96 }
97
98 for _, sb := range originalServerBlocks {
99 for i := range sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments. {
100 replacer.ApplyToSegmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ShorthandReplacer#ApplyToSegment().(&sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments.[i])
101 }
102
103 if len(sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Keysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Keys.) == 0 {
104 return nil, warnings, 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().("server block without any key is global configuration, and if used, it must be first")
105 }
106
107 // extract matcher definitions
108 matcherDefs := make(map[string]caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#)
109 for _, segment := range sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments. {
110 if dir := segment.Directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Segment#Directive().(); stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.1 strings/HasPrefix().(dir, matcherPrefixscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/matcherPrefix.) {
111 d := caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(segment)
112 err := parseMatcherDefinitionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/parseMatcherDefinitions().(d, matcherDefs)
113 if err != nil {
114 return nil, warnings, err
115 }
116 }
117 }
118
119 // evaluate each directive ("segment") in this block
120 for _, segment := range sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments. {
121 dir := segment.Directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Segment#Directive().()
122
123 if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.1 strings/HasPrefix().(dir, matcherPrefixscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/matcherPrefix.) {
124 // matcher definitions were pre-processed
125 continue
126 }
127
128 dirFunc, ok := registeredDirectivesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/registeredDirectives.[dir]
129 if !ok {
130 tkn := segment[0]
131 message := "%s:%d: unrecognized directive: %s"
132 if !sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..HasBracesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#HasBraces. {
133 message += "\nDid you mean to define a second site? If so, you must use curly braces around each site to separate their configurations."
134 }
135 return nil, warnings, 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().(message, tkn.Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#File., tkn.Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Line., dir)
136 }
137
138 h := Helperscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#{
139 Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#Dispenser.: caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(segment),
140 optionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#options.: options,
141 warningsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#warnings.: &warnings,
142 matcherDefsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#matcherDefs.: matcherDefs,
143 parentBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#parentBlock.: sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block.,
144 groupCounterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#groupCounter.: gc,
145 Statescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#State.: state,
146 BlockStatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#BlockState.: state,
147 }
148
149 results, err := dirFunc(h)
150 if err != nil {
151 return nil, warnings, 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().("parsing caddyfile tokens for '%s': %v", dir, err)
152 }
153
154 dir = normalizeDirectiveNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/normalizeDirectiveName().(dir)
155
156 for _, result := range results {
157 result.directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#directive. = dir
158 sb.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.[result.Classscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Class.] = append(sb.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.[result.Classscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Class.], result)
159 }
160
161 // specially handle named routes that were pulled out from
162 // the invoke directive, which could be nested anywhere within
163 // some subroutes in this directive; we add them to the pile
164 // for this server block
165 if state[namedRouteKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedRouteKey.] != nil {
166 for name := range state[namedRouteKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedRouteKey.].(map[string]struct{}) {
167 result := ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#{Classscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Class.: namedRouteKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedRouteKey., Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value.: name}
168 sb.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.[result.Classscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Class.] = append(sb.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.[result.Classscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Class.], result)
169 }
170 state[namedRouteKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedRouteKey.] = nil
171 }
172 }
173 }
174
175 // map
176 sbmap, err := st.mapAddressToProtocolToServerBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#mapAddressToProtocolToServerBlocks().(originalServerBlocks, options)
177 if err != nil {
178 return nil, warnings, err
179 }
180
181 // reduce
182 pairings := st.consolidateAddrMappingsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#consolidateAddrMappings().(sbmap)
183
184 // each pairing of listener addresses to list of server
185 // blocks is basically a server definition
186 servers, err := st.serversFromPairingsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#serversFromPairings().(pairings, options, &warnings, gc)
187 if err != nil {
188 return nil, warnings, err
189 }
190
191 // hoist the metrics config from per-server to global
192 metrics, _ := options["metrics"].(*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Metrics#)
193 for _, s := range servers {
194 if s.Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Metrics. != nil {
195 metrics = cmpscip-go gomod github.com/golang/go/src go1.25.1 cmp/.Orscip-go gomod github.com/golang/go/src go1.25.1 cmp/Or().(metrics, &caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Metrics#{})
196 metrics = &caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Metrics#{
197 PerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Metrics#PerHost.: metrics.PerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Metrics#PerHost. || s.Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Metrics..PerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Metrics#PerHost.,
198 }
199 s.Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Metrics. = nil // we don't need it anymore
200 }
201 }
202
203 // now that each server is configured, make the HTTP app
204 httpApp := caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Appscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#{
205 HTTPPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#HTTPPort.: tryIntscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryInt().(options["http_port"], &warnings),
206 HTTPSPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#HTTPSPort.: tryIntscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryInt().(options["https_port"], &warnings),
207 GracePeriodscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#GracePeriod.: tryDurationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryDuration().(options["grace_period"], &warnings),
208 ShutdownDelayscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#ShutdownDelay.: tryDurationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryDuration().(options["shutdown_delay"], &warnings),
209 Metricsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#Metrics.: metrics,
210 Serversscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#Servers.: servers,
211 }
212
213 // then make the TLS app
214 tlsApp, warnings, err := st.buildTLSAppscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#buildTLSApp().(pairings, options, warnings)
215 if err != nil {
216 return nil, warnings, err
217 }
218
219 // then make the PKI app
220 pkiApp, warnings, err := st.buildPKIAppscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#buildPKIApp().(pairings, options, warnings)
221 if err != nil {
222 return nil, warnings, err
223 }
224
225 // extract any custom logs, and enforce configured levels
226 var customLogs []namedCustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#
227 var hasDefaultLog bool
228 addCustomLog := func(ncl namedCustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#) {
229 if ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name. == "" {
230 return
231 }
232 if ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name. == caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName. {
233 hasDefaultLog = true
234 }
235 if _, ok := options["debug"]; ok && ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log. != nil && ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log..Levelscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/BaseLog#Level. == "" {
236 ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log..Levelscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/BaseLog#Level. = zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/DebugLevel..CapitalStringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/Level#CapitalString().()
237 }
238 customLogs = append(customLogs, ncl)
239 }
240
241 // Apply global log options, when set
242 if options["log"] != nil {
243 for _, logValue := range options["log"].([]ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#) {
244 addCustomLog(logValue.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(namedCustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#))
245 }
246 }
247
248 if !hasDefaultLog {
249 // if the default log was not customized, ensure we
250 // configure it with any applicable options
251 if _, ok := options["debug"]; ok {
252 customLogs = append(customLogs, namedCustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#{
253 namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name.: caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName.,
254 logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log.: &caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#{
255 BaseLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#BaseLog.: caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.BaseLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/BaseLog#{Levelscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/BaseLog#Level.: zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/DebugLevel..CapitalStringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/Level#CapitalString().()},
256 },
257 })
258 }
259 }
260
261 // Apply server-specific log options
262 for _, p := range pairings {
263 for _, sb := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. {
264 for _, clVal := range sb.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["custom_log"] {
265 addCustomLog(clVal.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(namedCustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#))
266 }
267 }
268 }
269
270 // annnd the top-level config, then we're done!
271 cfg := &caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#{AppsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#AppsRaw.: make(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#)}
272
273 // loop through the configured options, and if any of
274 // them are an httpcaddyfile App, then we insert them
275 // into the config as raw Caddy apps
276 for _, opt := range options {
277 if app, ok := opt.(Appscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/App#); ok {
278 cfg.AppsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#AppsRaw.[app.Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/App#Name.] = app.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/App#Value.
279 }
280 }
281
282 // insert the standard Caddy apps into the config
283 if len(httpApp.Serversscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/App#Servers.) > 0 {
284 cfg.AppsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#AppsRaw.["http"] = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(httpApp, &warnings)
285 }
286 if !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(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#{CertificatesRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/TLS#CertificatesRaw.: make(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#)}) {
287 cfg.AppsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#AppsRaw.["tls"] = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(tlsApp, &warnings)
288 }
289 if !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(pkiApp, &caddypkiscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/.PKIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/PKI#{CAsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/PKI#CAs.: make(map[string]*caddypkiscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/.CAscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddypki`/CA#)}) {
290 cfg.AppsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#AppsRaw.["pki"] = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(pkiApp, &warnings)
291 }
292 if filesystems, ok := options["filesystem"].(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Modulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module#); ok {
293 cfg.AppsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#AppsRaw.["caddy.filesystems"] = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(
294 filesystems,
295 &warnings)
296 }
297
298 if storageCvtr, ok := options["storage"].(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.StorageConverterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/StorageConverter#); ok {
299 cfg.StorageRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#StorageRaw. = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONModuleObjectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSONModuleObject().(storageCvtr,
300 "module",
301 storageCvtr.(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Modulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module#).CaddyModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module#CaddyModule.().IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#ID..Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleID#Name().(),
302 &warnings)
303 }
304 if adminConfig, ok := options["admin"].(*caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.AdminConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/AdminConfig#); ok && adminConfig != nil {
305 cfg.Adminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Admin. = adminConfig
306 }
307 if pc, ok := options["persist_config"].(string); ok && pc == "off" {
308 if cfg.Adminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Admin. == nil {
309 cfg.Adminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Admin. = new(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.AdminConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/AdminConfig#)
310 }
311 if cfg.Adminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Admin..Configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/AdminConfig#Config. == nil {
312 cfg.Adminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Admin..Configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/AdminConfig#Config. = new(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ConfigSettingsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ConfigSettings#)
313 }
314 cfg.Adminscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Admin..Configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/AdminConfig#Config..Persistscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ConfigSettings#Persist. = new(bool)
315 }
316
317 if len(customLogs) > 0 {
318 if cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging. == nil {
319 cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging. = &caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Logging#{
320 Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Logging#Logs.: make(map[string]*caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#),
321 }
322 }
323
324 // Add the default log first if defined, so that it doesn't
325 // accidentally get re-created below due to the Exclude logic
326 for _, ncl := range customLogs {
327 if ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name. == caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName. && ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log. != nil {
328 cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging..Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Logging#Logs.[caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName.] = ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log.
329 break
330 }
331 }
332
333 // Add the rest of the custom logs
334 for _, ncl := range customLogs {
335 if ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log. == nil || ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name. == caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName. {
336 continue
337 }
338 if ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name. != "" {
339 cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging..Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Logging#Logs.[ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name.] = ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log.
340 }
341 // most users seem to prefer not writing access logs
342 // to the default log when they are directed to a
343 // file or have any other special customization
344 if ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name. != caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName. && len(ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log..Includescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#Include.) > 0 {
345 defaultLog, ok := cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging..Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Logging#Logs.[caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName.]
346 if !ok {
347 defaultLog = new(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#)
348 cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging..Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Logging#Logs.[caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/DefaultLoggerName.] = defaultLog
349 }
350 defaultLog.Excludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#Exclude. = append(defaultLog.Excludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#Exclude., ncl.logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log..Includescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#Include....)
351
352 // avoid duplicates by sorting + compacting
353 sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Stringsscip-go gomod github.com/golang/go/src go1.25.1 sort/Strings().(defaultLog.Excludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#Exclude.)
354 defaultLog.Excludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#Exclude. = slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Compactscip-go gomod github.com/golang/go/src go1.25.1 slices/Compact().(defaultLog.Excludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#Exclude.)
355 }
356 }
357 // we may have not actually added anything, so remove if empty
358 if len(cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging..Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Logging#Logs.) == 0 {
359 cfg.Loggingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Config#Logging. = nil
360 }
361 }
362
363 return cfg, warnings, nil
364 }
365
366 // evaluateGlobalOptionsBlock evaluates the global options block,
367 // which is expected to be the first server block if it has zero
368 // keys. It returns the updated list of server blocks with the
369 // global options block removed, and updates options accordingly.
370 func (ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#) evaluateGlobalOptionsBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#evaluateGlobalOptionsBlock().(serverBlocks []serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#, options map[string]any) ([]serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#, error) {
371 if len(serverBlocks) == 0 || len(serverBlocks[0].blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Keysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Keys.) > 0 {
372 return serverBlocks, nil
373 }
374
375 for _, segment := range serverBlocks[0].blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments. {
376 opt := segment.Directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Segment#Directive().()
377 var val any
378 var err error
379 disp := caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(segment)
380
381 optFunc, ok := registeredGlobalOptionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/registeredGlobalOptions.[opt]
382 if !ok {
383 tkn := segment[0]
384 return nil, 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().("%s:%d: unrecognized global option: %s", tkn.Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#File., tkn.Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Line., opt)
385 }
386
387 val, err = optFunc(disp, options[opt])
388 if err != nil {
389 return nil, 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().("parsing caddyfile tokens for '%s': %v", opt, err)
390 }
391
392 // As a special case, fold multiple "servers" options together
393 // in an array instead of overwriting a possible existing value
394 if opt == "servers" {
395 existingOpts, ok := options[opt].([]serverOptionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#)
396 if !ok {
397 existingOpts = []serverOptionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#{}
398 }
399 serverOpts, ok := val.(serverOptionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#)
400 if !ok {
401 return nil, 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().("unexpected type from 'servers' global options: %T", val)
402 }
403 options[opt] = append(existingOpts, serverOpts)
404 continue
405 }
406 // Additionally, fold multiple "log" options together into an
407 // array so that multiple loggers can be configured.
408 if opt == "log" {
409 existingOpts, ok := options[opt].([]ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#)
410 if !ok {
411 existingOpts = []ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#{}
412 }
413 logOpts, ok := val.([]ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#)
414 if !ok {
415 return nil, 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().("unexpected type from 'log' global options: %T", val)
416 }
417 options[opt] = append(existingOpts, logOpts...)
418 continue
419 }
420 // Also fold multiple "default_bind" options together into an
421 // array so that server blocks can have multiple binds by default.
422 if opt == "default_bind" {
423 existingOpts, ok := options[opt].([]ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#)
424 if !ok {
425 existingOpts = []ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#{}
426 }
427 defaultBindOpts, ok := val.([]ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#)
428 if !ok {
429 return nil, 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().("unexpected type from 'default_bind' global options: %T", val)
430 }
431 options[opt] = append(existingOpts, defaultBindOpts...)
432 continue
433 }
434
435 options[opt] = val
436 }
437
438 // If we got "servers" options, we'll sort them by their listener address
439 if serverOpts, ok := options["servers"].([]serverOptionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#); ok {
440 sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Slicescip-go gomod github.com/golang/go/src go1.25.1 sort/Slice().(serverOpts, func(i, j int) bool {
441 return len(serverOpts[i].ListenerAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#ListenerAddress.) > len(serverOpts[j].ListenerAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#ListenerAddress.)
442 })
443
444 // Reject the config if there are duplicate listener address
445 seen := make(map[string]bool)
446 for _, entry := range serverOpts {
447 if _, alreadySeen := seen[entry.ListenerAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#ListenerAddress.]; alreadySeen {
448 return nil, 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().("cannot have 'servers' global options with duplicate listener addresses: %s", entry.ListenerAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#ListenerAddress.)
449 }
450 seen[entry.ListenerAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverOptions#ListenerAddress.] = true
451 }
452 }
453
454 return serverBlocks[1:], nil
455 }
456
457 // extractNamedRoutes pulls out any named route server blocks
458 // so they don't get parsed as sites, and stores them in options
459 // for later.
460 func (ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#) extractNamedRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#extractNamedRoutes().(
461 serverBlocks []serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#,
462 options map[string]any,
463 warnings *[]caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#,
464 replacer ShorthandReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ShorthandReplacer#,
465 ) ([]serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#, error) {
466 namedRoutes := map[string]*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#{}
467
468 gc := counterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#{new(int)}
469 state := make(map[string]any)
470
471 // copy the server blocks so we can
472 // splice out the named route ones
473 filtered := append([]serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#{}, serverBlocks...)
474 index := -1
475
476 for _, sb := range serverBlocks {
477 index++
478 if !sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..IsNamedRoutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#IsNamedRoute. {
479 continue
480 }
481
482 // splice out this block, because we know it's not a real server
483 filtered = append(filtered[:index], filtered[index+1:]...)
484 index--
485
486 if len(sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments.) == 0 {
487 continue
488 }
489
490 wholeSegment := caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Segmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Segment#{}
491 for i := range sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments. {
492 // replace user-defined placeholder shorthands in extracted named routes
493 replacer.ApplyToSegmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ShorthandReplacer#ApplyToSegment().(&sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments.[i])
494
495 // zip up all the segments since ParseSegmentAsSubroute
496 // was designed to take a directive+
497 wholeSegment = append(wholeSegment, sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Segmentsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Segments.[i]...)
498 }
499
500 h := Helperscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#{
501 Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#Dispenser.: caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(wholeSegment),
502 optionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#options.: options,
503 warningsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#warnings.: warnings,
504 matcherDefsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#matcherDefs.: nil,
505 parentBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#parentBlock.: sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block.,
506 groupCounterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#groupCounter.: gc,
507 Statescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#State.: state,
508 BlockStatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#BlockState.: state,
509 }
510
511 handler, err := ParseSegmentAsSubroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ParseSegmentAsSubroute().(h)
512 if err != nil {
513 return nil, err
514 }
515 subroute := handler.(*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#)
516 route := caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#{}
517
518 if len(subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.) == 1 && len(subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.[0].MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw.) == 0 {
519 // if there's only one route with no matcher, then we can simplify
520 route.HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw. = append(route.HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw., subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.[0].HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw.[0])
521 } else {
522 // otherwise we need the whole subroute
523 route.HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw. = []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#{caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONModuleObjectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSONModuleObject().(handler, "handler", subroute.CaddyModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#CaddyModule().().IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#ID..Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleID#Name().(), h.warningsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Helper#warnings.)}
524 }
525
526 namedRoutes[sb.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..GetKeysTextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#GetKeysText().()[0]] = &route
527 }
528 options["named_routes"] = namedRoutes
529
530 return filtered, nil
531 }
532
533 // serversFromPairings creates the servers for each pairing of addresses
534 // to server blocks. Each pairing is essentially a server definition.
535 func (st *ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#) serversFromPairingsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#serversFromPairings().(
536 pairings []sbAddrAssociationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#,
537 options map[string]any,
538 warnings *[]caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#,
539 groupCounter counterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#,
540 ) (map[string]*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#, error) {
541 servers := make(map[string]*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#)
542 defaultSNI := tryStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryString().(options["default_sni"], warnings)
543 fallbackSNI := tryStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryString().(options["fallback_sni"], warnings)
544
545 httpPort := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.DefaultHTTPPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/DefaultHTTPPort.)
546 if hp, ok := options["http_port"].(int); ok {
547 httpPort = strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(hp)
548 }
549 httpsPort := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.DefaultHTTPSPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/DefaultHTTPSPort.)
550 if hsp, ok := options["https_port"].(int); ok {
551 httpsPort = strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(hsp)
552 }
553 autoHTTPS := []string{}
554 if ah, ok := options["auto_https"].([]string); ok {
555 autoHTTPS = ah
556 }
557
558 for i, p := range pairings {
559 // detect ambiguous site definitions: server blocks which
560 // have the same host bound to the same interface (listener
561 // address), otherwise their routes will improperly be added
562 // to the same server (see issue #4635)
563 for j, sblock1 := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. {
564 for _, key := range sblock1.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..GetKeysTextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#GetKeysText().() {
565 for k, sblock2 := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. {
566 if k == j {
567 continue
568 }
569 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().(sblock2.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..GetKeysTextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#GetKeysText().(), key) {
570 return nil, 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().("ambiguous site definition: %s", key)
571 }
572 }
573 }
574 }
575
576 var (
577 addresses []string
578 protocols [][]string
579 )
580
581 for _, addressWithProtocols := range p.addressesWithProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#addressesWithProtocols. {
582 addresses = append(addresses, addressWithProtocols.addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/addressWithProtocols#address.)
583 protocols = append(protocols, addressWithProtocols.protocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/addressWithProtocols#protocols.)
584 }
585
586 srv := &caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#{
587 Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen.: addresses,
588 ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols.: protocols,
589 }
590
591 // remove srv.ListenProtocols[j] if it only contains the default protocols
592 for j, lnProtocols := range srv.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols. {
593 srv.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols.[j] = nil
594 for _, lnProtocol := range lnProtocols {
595 if lnProtocol != "" {
596 srv.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols.[j] = lnProtocols
597 break
598 }
599 }
600 }
601
602 // remove srv.ListenProtocols if it only contains the default protocols for all listen addresses
603 listenProtocols := srv.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols.
604 srv.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols. = nil
605 for _, lnProtocols := range listenProtocols {
606 if lnProtocols != nil {
607 srv.ListenProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenProtocols. = listenProtocols
608 break
609 }
610 }
611
612 // handle the auto_https global option
613 for _, val := range autoHTTPS {
614 switch val {
615 case "off":
616 if srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. == nil {
617 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. = new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.AutoHTTPSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#)
618 }
619 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..Disabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#Disabled. = true
620
621 case "disable_redirects":
622 if srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. == nil {
623 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. = new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.AutoHTTPSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#)
624 }
625 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..DisableRedirscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#DisableRedir. = true
626
627 case "disable_certs":
628 if srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. == nil {
629 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. = new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.AutoHTTPSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#)
630 }
631 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..DisableCertsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#DisableCerts. = true
632
633 case "ignore_loaded_certs":
634 if srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. == nil {
635 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. = new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.AutoHTTPSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#)
636 }
637 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..IgnoreLoadedCertsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#IgnoreLoadedCerts. = true
638 }
639 }
640
641 // Using paths in site addresses is deprecated
642 // See ParseAddress() where parsing should later reject paths
643 // See https://github.com/caddyserver/caddy/pull/4728 for a full explanation
644 for _, sblock := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. {
645 for _, addr := range sblock.parsedKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#parsedKeys. {
646 if addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path. != "" {
647 caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Log().().Namedscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Named().("caddyfile").Warnscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Warn().("Using a path in a site address is deprecated; please use the 'handle' directive instead", 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().("address", addr.Stringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#String().()))
648 }
649 }
650 }
651
652 // sort server blocks by their keys; this is important because
653 // only the first matching site should be evaluated, and we should
654 // attempt to match most specific site first (host and path), in
655 // case their matchers overlap; we do this somewhat naively by
656 // descending sort by length of host then path
657 sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.SliceStablescip-go gomod github.com/golang/go/src go1.25.1 sort/SliceStable().(p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks., func(i, j int) bool {
658 // TODO: we could pre-process the specificities for efficiency,
659 // but I don't expect many blocks will have THAT many keys...
660 var iLongestPath, jLongestPath string
661 var iLongestHost, jLongestHost string
662 var iWildcardHost, jWildcardHost bool
663 for _, addr := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks.[i].parsedKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#parsedKeys. {
664 if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.1 strings/Contains().(addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host., "*") || addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. == "" {
665 iWildcardHost = true
666 }
667 if specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.) > specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(iLongestHost) {
668 iLongestHost = addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.
669 }
670 if specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.) > specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(iLongestPath) {
671 iLongestPath = addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.
672 }
673 }
674 for _, addr := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks.[j].parsedKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#parsedKeys. {
675 if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.1 strings/Contains().(addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host., "*") || addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. == "" {
676 jWildcardHost = true
677 }
678 if specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.) > specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(jLongestHost) {
679 jLongestHost = addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.
680 }
681 if specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.) > specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(jLongestPath) {
682 jLongestPath = addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.
683 }
684 }
685 // catch-all blocks (blocks with no hostname) should always go
686 // last, even after blocks with wildcard hosts
687 if specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(iLongestHost) == 0 {
688 return false
689 }
690 if specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(jLongestHost) == 0 {
691 return true
692 }
693 if iWildcardHost != jWildcardHost {
694 // site blocks that have a key with a wildcard in the hostname
695 // must always be less specific than blocks without one; see
696 // https://github.com/caddyserver/caddy/issues/3410
697 return jWildcardHost && !iWildcardHost
698 }
699 if specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(iLongestHost) == specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(jLongestHost) {
700 return len(iLongestPath) > len(jLongestPath)
701 }
702 return specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(iLongestHost) > specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(jLongestHost)
703 })
704
705 var hasCatchAllTLSConnPolicy, addressQualifiesForTLS bool
706 autoHTTPSWillAddConnPolicy := srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. == nil || !srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..Disabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#Disabled.
707
708 // if needed, the ServerLogConfig is initialized beforehand so
709 // that all server blocks can populate it with data, even when not
710 // coming with a log directive
711 for _, sblock := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. {
712 if len(sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["custom_log"]) != 0 {
713 srv.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. = new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ServerLogConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#)
714 break
715 }
716 }
717
718 // add named routes to the server if 'invoke' was used inside of it
719 configuredNamedRoutes := options["named_routes"].(map[string]*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#)
720 for _, sblock := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. {
721 if len(sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.[namedRouteKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedRouteKey.]) == 0 {
722 continue
723 }
724 for _, value := range sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.[namedRouteKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedRouteKey.] {
725 if srv.NamedRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#NamedRoutes. == nil {
726 srv.NamedRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#NamedRoutes. = map[string]*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#{}
727 }
728 name := value.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(string)
729 if configuredNamedRoutes[name] == nil {
730 return nil, 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().("cannot invoke named route '%s', which was not defined", name)
731 }
732 srv.NamedRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#NamedRoutes.[name] = configuredNamedRoutes[name]
733 }
734 }
735
736 // create a subroute for each site in the server block
737 for _, sblock := range p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. {
738 matcherSetsEnc, err := st.compileEncodedMatcherSetsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#compileEncodedMatcherSets().(sblock)
739 if err != nil {
740 return nil, 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().("server block %v: compiling matcher sets: %v", sblock.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Keysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Keys., err)
741 }
742
743 hosts := sblock.hostsFromKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#hostsFromKeys().(false)
744
745 // emit warnings if user put unspecified IP addresses; they probably want the bind directive
746 for _, h := range hosts {
747 if h == "0.0.0.0" || h == "::" {
748 caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Log().().Namedscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Named().("caddyfile").Warnscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Warn().("Site block has an unspecified IP address which only matches requests having that Host header; you probably want the 'bind' directive to configure the socket", 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().("address", h))
749 }
750 }
751
752 // collect hosts that are forced to be automated
753 forceAutomatedNames := make(map[string]struct{})
754 if _, ok := sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["tls.force_automate"]; ok {
755 for _, host := range hosts {
756 forceAutomatedNames[host] = struct{}{}
757 }
758 }
759
760 // tls: connection policies
761 if cpVals, ok := sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["tls.connection_policy"]; ok {
762 // tls connection policies
763 for _, cpVal := range cpVals {
764 cp := cpVal.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(*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#)
765
766 // make sure the policy covers all hostnames from the block
767 for _, h := range hosts {
768 if h == defaultSNI {
769 hosts = append(hosts, "")
770 cp.DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. = defaultSNI
771 break
772 }
773 if h == fallbackSNI {
774 hosts = append(hosts, "")
775 cp.FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. = fallbackSNI
776 break
777 }
778 }
779
780 if len(hosts) > 0 {
781 slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Sortscip-go gomod github.com/golang/go/src go1.25.1 slices/Sort().(hosts) // for deterministic JSON output
782 cp.MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw. = caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#{
783 "sni": caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(hosts, warnings), // make sure to match all hosts, not just auto-HTTPS-qualified ones
784 }
785 } else {
786 cp.DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. = defaultSNI
787 cp.FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. = fallbackSNI
788 }
789
790 // only append this policy if it actually changes something,
791 // or if the configuration explicitly automates certs for
792 // these names (this is necessary to hoist a connection policy
793 // above one that may manually load a wildcard cert that would
794 // otherwise clobber the automated one; the code that appends
795 // policies that manually load certs comes later, so they're
796 // lower in the list)
797 if !cp.SettingsEmptyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#SettingsEmpty().() || mapContainsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/mapContains().(forceAutomatedNames, hosts) {
798 srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies. = append(srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies., cp)
799 hasCatchAllTLSConnPolicy = len(hosts) == 0
800 }
801 }
802 }
803
804 for _, addr := range sblock.parsedKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#parsedKeys. {
805 // if server only uses HTTP port, auto-HTTPS will not apply
806 if listenersUseAnyPortOtherThanscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/listenersUseAnyPortOtherThan().(srv.Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen., httpPort) {
807 // exclude any hosts that were defined explicitly with "http://"
808 // in the key from automated cert management (issue #2998)
809 if addr.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. == "http" && addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. != "" {
810 if srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. == nil {
811 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. = new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.AutoHTTPSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#)
812 }
813 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().(srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..Skipscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#Skip., addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.) {
814 srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..Skipscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#Skip. = append(srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..Skipscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#Skip., addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.)
815 }
816 }
817 }
818
819 // If TLS is specified as directive, it will also result in 1 or more connection policy being created
820 // Thus, catch-all address with non-standard port, e.g. :8443, can have TLS enabled without
821 // specifying prefix "https://"
822 // Second part of the condition is to allow creating TLS conn policy even though `auto_https` has been disabled
823 // ensuring compatibility with behavior described in below link
824 // https://caddy.community/t/making-sense-of-auto-https-and-why-disabling-it-still-serves-https-instead-of-http/9761
825 createdTLSConnPolicies, ok := sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["tls.connection_policy"]
826 hasTLSEnabled := (ok && len(createdTLSConnPolicies) > 0) ||
827 (addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. != "" && (srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS. == nil || !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().(srv.AutoHTTPSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#AutoHTTPS..Skipscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/AutoHTTPSConfig#Skip., addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.)))
828
829 // we'll need to remember if the address qualifies for auto-HTTPS, so we
830 // can add a TLS conn policy if necessary
831 if addr.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. == "https" ||
832 (addr.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. != "http" && addr.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. != httpPort && hasTLSEnabled) {
833 addressQualifiesForTLS = true
834 }
835
836 // predict whether auto-HTTPS will add the conn policy for us; if so, we
837 // may not need to add one for this server
838 autoHTTPSWillAddConnPolicy = autoHTTPSWillAddConnPolicy &&
839 (addr.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. == httpsPort || (addr.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. != httpPort && addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. != ""))
840 }
841
842 // Look for any config values that provide listener wrappers on the server block
843 for _, listenerConfig := range sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["listener_wrapper"] {
844 listenerWrapper, ok := listenerConfig.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(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#)
845 if !ok {
846 return nil, 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().("config for a listener wrapper did not provide a value that implements caddy.ListenerWrapper")
847 }
848 jsonListenerWrapper := caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONModuleObjectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSONModuleObject().(
849 listenerWrapper,
850 "wrapper",
851 listenerWrapper.(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Modulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module#).CaddyModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module#CaddyModule.().IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#ID..Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleID#Name().(),
852 warnings)
853 srv.ListenerWrappersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenerWrappersRaw. = append(srv.ListenerWrappersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#ListenerWrappersRaw., jsonListenerWrapper)
854 }
855
856 // Look for any config values that provide packet conn wrappers on the server block
857 for _, listenerConfig := range sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["packet_conn_wrapper"] {
858 packetConnWrapper, ok := listenerConfig.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(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#)
859 if !ok {
860 return nil, 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().("config for a packet conn wrapper did not provide a value that implements caddy.PacketConnWrapper")
861 }
862 jsonPacketConnWrapper := caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONModuleObjectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSONModuleObject().(
863 packetConnWrapper,
864 "wrapper",
865 packetConnWrapper.(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Modulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module#).CaddyModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module#CaddyModule.().IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#ID..Namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleID#Name().(),
866 warnings)
867 srv.PacketConnWrappersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#PacketConnWrappersRaw. = append(srv.PacketConnWrappersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#PacketConnWrappersRaw., jsonPacketConnWrapper)
868 }
869
870 // set up each handler directive, making sure to honor directive order
871 dirRoutes := sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["route"]
872 siteSubroute, err := buildSubroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/buildSubroute().(dirRoutes, groupCounter, true)
873 if err != nil {
874 return nil, err
875 }
876
877 // add the site block's route(s) to the server
878 srv.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Routes. = appendSubrouteToRouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/appendSubrouteToRouteList().(srv.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Routes., siteSubroute, matcherSetsEnc, p, warnings)
879
880 // if error routes are defined, add those too
881 if errorSubrouteVals, ok := sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["error_route"]; ok {
882 if srv.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Errors. == nil {
883 srv.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Errors. = new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.HTTPErrorConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HTTPErrorConfig#)
884 }
885 sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.SliceStablescip-go gomod github.com/golang/go/src go1.25.1 sort/SliceStable().(errorSubrouteVals, func(i, j int) bool {
886 sri, srj := errorSubrouteVals[i].Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#), errorSubrouteVals[j].Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#)
887 if len(sri.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.[0].MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw.) == 0 && len(srj.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.[0].MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw.) != 0 {
888 return false
889 }
890 return true
891 })
892 errorsSubroute := &caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#{}
893 for _, val := range errorSubrouteVals {
894 sr := val.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#)
895 errorsSubroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes. = append(errorsSubroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes., sr.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes....)
896 }
897 srv.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. = appendSubrouteToRouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/appendSubrouteToRouteList().(srv.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., errorsSubroute, matcherSetsEnc, p, warnings)
898 }
899
900 // add log associations
901 // see https://github.com/caddyserver/caddy/issues/3310
902 sblockLogHosts := sblock.hostsFromKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#hostsFromKeys().(true)
903 for _, cval := range sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["custom_log"] {
904 ncl := cval.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(namedCustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#)
905
906 // if `no_hostname` is set, then this logger will not
907 // be associated with any of the site block's hostnames,
908 // and only be usable via the `log_name` directive
909 // or the `access_logger_names` variable
910 if ncl.noHostnamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#noHostname. {
911 continue
912 }
913
914 if sblock.hasHostCatchAllKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#hasHostCatchAllKey().() && len(ncl.hostnamesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#hostnames.) == 0 {
915 // all requests for hosts not able to be listed should use
916 // this log because it's a catch-all-hosts server block
917 srv.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs..DefaultLoggerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerLogConfig#DefaultLoggerName. = ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name.
918 } else if len(ncl.hostnamesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#hostnames.) > 0 {
919 // if the logger overrides the hostnames, map that to the logger name
920 for _, h := range ncl.hostnamesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#hostnames. {
921 if srv.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. == nil {
922 srv.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. = make(map[string]caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.StringArrayscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/StringArray#)
923 }
924 srv.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.[h] = append(srv.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.[h], ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name.)
925 }
926 } else {
927 // otherwise, map each host to the logger name
928 for _, h := range sblockLogHosts {
929 // strip the port from the host, if any
930 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().(h)
931 if err != nil {
932 host = h
933 }
934 if srv.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. == nil {
935 srv.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. = make(map[string]caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.StringArrayscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/StringArray#)
936 }
937 srv.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.[host] = append(srv.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.[host], ncl.namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name.)
938 }
939 }
940 }
941 if srv.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. != nil && len(sblock.pilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#pile.["custom_log"]) == 0 {
942 // server has access logs enabled, but this server block does not
943 // enable access logs; therefore, all hosts of this server block
944 // should not be access-logged
945 if len(hosts) == 0 {
946 // if the server block has a catch-all-hosts key, then we should
947 // not log reqs to any host unless it appears in the map
948 srv.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. = true
949 }
950 srv.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. = append(srv.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., sblockLogHosts...)
951 }
952 }
953
954 // sort for deterministic JSON output
955 if srv.Logsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Logs. != nil {
956 slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Sortscip-go gomod github.com/golang/go/src go1.25.1 slices/Sort().(srv.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.)
957 }
958
959 // a server cannot (natively) serve both HTTP and HTTPS at the
960 // same time, so make sure the configuration isn't in conflict
961 err := detectConflictingSchemesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/detectConflictingSchemes().(srv, p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks., options)
962 if err != nil {
963 return nil, err
964 }
965
966 // a catch-all TLS conn policy is necessary to ensure TLS can
967 // be offered to all hostnames of the server; even though only
968 // one policy is needed to enable TLS for the server, that
969 // policy might apply to only certain TLS handshakes; but when
970 // using the Caddyfile, user would expect all handshakes to at
971 // least have a matching connection policy, so here we append a
972 // catch-all/default policy if there isn't one already (it's
973 // important that it goes at the end) - see issue #3004:
974 // https://github.com/caddyserver/caddy/issues/3004
975 // TODO: maybe a smarter way to handle this might be to just make the
976 // auto-HTTPS logic at provision-time detect if there is any connection
977 // policy missing for any HTTPS-enabled hosts, if so, add it... maybe?
978 if addressQualifiesForTLS &&
979 !hasCatchAllTLSConnPolicy &&
980 (len(srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies.) > 0 || !autoHTTPSWillAddConnPolicy || defaultSNI != "" || fallbackSNI != "") {
981 srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies. = append(srv.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`/.ConnectionPolicyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#{
982 DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI.: defaultSNI,
983 FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI.: fallbackSNI,
984 })
985 }
986
987 // tidy things up a bit
988 srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies., err = consolidateConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/consolidateConnPolicies().(srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies.)
989 if err != nil {
990 return nil, 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().("consolidating TLS connection policies for server %d: %v", i, err)
991 }
992 srv.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Routes. = consolidateRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/consolidateRoutes().(srv.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Routes.)
993
994 servers[fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Sprintf().("srv%d", i)] = srv
995 }
996
997 if err := applyServerOptionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/applyServerOptions().(servers, options, warnings); err != nil {
998 return nil, 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().("applying global server options: %v", err)
999 }
1000
1001 return servers, nil
1002 }
1003
1004 func detectConflictingSchemesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/detectConflictingSchemes().(srv *caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Serverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#, serverBlocks []serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#, options map[string]any) error {
1005 httpPort := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.DefaultHTTPPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/DefaultHTTPPort.)
1006 if hp, ok := options["http_port"].(int); ok {
1007 httpPort = strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(hp)
1008 }
1009 httpsPort := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.DefaultHTTPSPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/DefaultHTTPSPort.)
1010 if hsp, ok := options["https_port"].(int); ok {
1011 httpsPort = strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(hsp)
1012 }
1013
1014 var httpOrHTTPS string
1015 checkAndSetHTTP := func(addr Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#) error {
1016 if httpOrHTTPS == "HTTPS" {
1017 errMsg := 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().("server listening on %v is configured for HTTPS and cannot natively multiplex HTTP and HTTPS: %s",
1018 srv.Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen., addr.Originalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Original.)
1019 if addr.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. == "" && addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. == "" {
1020 errMsg = 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().("%s (try specifying https:// in the address)", errMsg)
1021 }
1022 return errMsg
1023 }
1024 if len(srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies.) > 0 {
1025 // any connection policies created for an HTTP server
1026 // is a logical conflict, as it would enable HTTPS
1027 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().("server listening on %v is HTTP, but attempts to configure TLS connection policies", srv.Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen.)
1028 }
1029 httpOrHTTPS = "HTTP"
1030 return nil
1031 }
1032 checkAndSetHTTPS := func(addr Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#) error {
1033 if httpOrHTTPS == "HTTP" {
1034 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().("server listening on %v is configured for HTTP and cannot natively multiplex HTTP and HTTPS: %s",
1035 srv.Listenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#Listen., addr.Originalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Original.)
1036 }
1037 httpOrHTTPS = "HTTPS"
1038 return nil
1039 }
1040
1041 for _, sblock := range serverBlocks {
1042 for _, addr := range sblock.parsedKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#parsedKeys. {
1043 if addr.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. == "http" || addr.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. == httpPort {
1044 if err := checkAndSetHTTP(addr); err != nil {
1045 return err
1046 }
1047 } else if addr.Schemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Scheme. == "https" || addr.Portscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Port. == httpsPort || len(srv.TLSConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Server#TLSConnPolicies.) > 0 {
1048 if err := checkAndSetHTTPS(addr); err != nil {
1049 return err
1050 }
1051 } else if addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. == "" {
1052 if err := checkAndSetHTTP(addr); err != nil {
1053 return err
1054 }
1055 }
1056 }
1057 }
1058
1059 return nil
1060 }
1061
1062 // consolidateConnPolicies sorts any catch-all policy to the end, removes empty TLS connection
1063 // policies, and combines equivalent ones for a cleaner overall output.
1064 func consolidateConnPoliciesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/consolidateConnPolicies().(cps 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#) (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#, error) {
1065 // catch-all policies (those without any matcher) should be at the
1066 // end, otherwise it nullifies any more specific policies
1067 sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.SliceStablescip-go gomod github.com/golang/go/src go1.25.1 sort/SliceStable().(cps, func(i, j int) bool {
1068 return cps[j].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw. == nil && cps[i].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw. != nil
1069 })
1070
1071 for i := 0; i < len(cps); i++ {
1072 // compare it to the others
1073 for j := 0; j < len(cps); j++ {
1074 if j == i {
1075 continue
1076 }
1077
1078 // if they're exactly equal in every way, just keep one of them
1079 if reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i], cps[j]) {
1080 cps = slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Deletescip-go gomod github.com/golang/go/src go1.25.1 slices/Delete().(cps, j, j+1)
1081 i--
1082 break
1083 }
1084
1085 // as a special case, if there are adjacent TLS conn policies that are identical except
1086 // by their matchers, and the matchers are specifically just ServerName ("sni") matchers
1087 // (by far the most common), we can combine them into a single policy
1088 if i == j-1 && len(cps[i].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw.) == 1 && len(cps[j].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw.) == 1 {
1089 if iSNIMatcherJSON, ok := cps[i].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw.["sni"]; ok {
1090 if jSNIMatcherJSON, ok := cps[j].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw.["sni"]; ok {
1091 // position of policies and the matcher criteria check out; if settings are
1092 // the same, then we can combine the policies; we have to unmarshal and
1093 // remarshal the matchers though
1094 if cps[i].SettingsEqualscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#SettingsEqual().(*cps[j]) {
1095 var iSNIMatcher caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.MatchServerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/MatchServerName#
1096 if err := jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/Unmarshal().(iSNIMatcherJSON, &iSNIMatcher); err == nil {
1097 var jSNIMatcher caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.MatchServerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/MatchServerName#
1098 if err := jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/Unmarshal().(jSNIMatcherJSON, &jSNIMatcher); err == nil {
1099 iSNIMatcher = append(iSNIMatcher, jSNIMatcher...)
1100 cps[i].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw.["sni"], err = jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/Marshal().(iSNIMatcher)
1101 if err != nil {
1102 return nil, 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().("recombining SNI matchers: %v", err)
1103 }
1104 cps = slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Deletescip-go gomod github.com/golang/go/src go1.25.1 slices/Delete().(cps, j, j+1)
1105 i--
1106 break
1107 }
1108 }
1109 }
1110 }
1111 }
1112 }
1113
1114 // if they have the same matcher, try to reconcile each field: either they must
1115 // be identical, or we have to be able to combine them safely
1116 if reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw., cps[j].MatchersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#MatchersRaw.) {
1117 if len(cps[i].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN.) > 0 &&
1118 len(cps[j].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN.) > 0 &&
1119 !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN., cps[j].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN.) {
1120 return nil, 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().("two policies with same match criteria have conflicting ALPN: %v vs. %v",
1121 cps[i].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN., cps[j].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN.)
1122 }
1123 if len(cps[i].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites.) > 0 &&
1124 len(cps[j].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites.) > 0 &&
1125 !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites., cps[j].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites.) {
1126 return nil, 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().("two policies with same match criteria have conflicting cipher suites: %v vs. %v",
1127 cps[i].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites., cps[j].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites.)
1128 }
1129 if cps[i].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication. == nil &&
1130 cps[j].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication. != nil &&
1131 !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication., cps[j].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication.) {
1132 return nil, 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().("two policies with same match criteria have conflicting client auth configuration: %+v vs. %+v",
1133 cps[i].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication., cps[j].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication.)
1134 }
1135 if len(cps[i].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves.) > 0 &&
1136 len(cps[j].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves.) > 0 &&
1137 !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves., cps[j].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves.) {
1138 return nil, 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().("two policies with same match criteria have conflicting curves: %v vs. %v",
1139 cps[i].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves., cps[j].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves.)
1140 }
1141 if cps[i].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. != "" &&
1142 cps[j].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. != "" &&
1143 cps[i].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. != cps[j].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. {
1144 return nil, 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().("two policies with same match criteria have conflicting default SNI: %s vs. %s",
1145 cps[i].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI., cps[j].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI.)
1146 }
1147 if cps[i].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. != "" &&
1148 cps[j].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. != "" &&
1149 cps[i].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. != cps[j].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. {
1150 return nil, 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().("two policies with same match criteria have conflicting fallback SNI: %s vs. %s",
1151 cps[i].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI., cps[j].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI.)
1152 }
1153 if cps[i].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin. != "" &&
1154 cps[j].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin. != "" &&
1155 cps[i].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin. != cps[j].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin. {
1156 return nil, 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().("two policies with same match criteria have conflicting min protocol: %s vs. %s",
1157 cps[i].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin., cps[j].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin.)
1158 }
1159 if cps[i].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax. != "" &&
1160 cps[j].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax. != "" &&
1161 cps[i].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax. != cps[j].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax. {
1162 return nil, 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().("two policies with same match criteria have conflicting max protocol: %s vs. %s",
1163 cps[i].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax., cps[j].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax.)
1164 }
1165 if cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection. != nil && cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection. != nil {
1166 // merging fields other than AnyTag is not implemented
1167 if !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..SerialNumberscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#SerialNumber., cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..SerialNumberscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#SerialNumber.) ||
1168 !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..SubjectOrganizationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#SubjectOrganization., cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..SubjectOrganizationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#SubjectOrganization.) ||
1169 cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..PublicKeyAlgorithmscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#PublicKeyAlgorithm. != cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..PublicKeyAlgorithmscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#PublicKeyAlgorithm. ||
1170 !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..AllTagsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#AllTags., cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..AllTagsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#AllTags.) {
1171 return nil, 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().("two policies with same match criteria have conflicting cert selections: %+v vs. %+v",
1172 cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection., cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection.)
1173 }
1174 }
1175
1176 // by now we've decided that we can merge the two -- we'll keep i and drop j
1177
1178 if len(cps[i].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN.) == 0 && len(cps[j].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN.) > 0 {
1179 cps[i].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN. = cps[j].ALPNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ALPN.
1180 }
1181 if len(cps[i].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites.) == 0 && len(cps[j].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites.) > 0 {
1182 cps[i].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites. = cps[j].CipherSuitesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CipherSuites.
1183 }
1184 if cps[i].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication. == nil && cps[j].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication. != nil {
1185 cps[i].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication. = cps[j].ClientAuthenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ClientAuthentication.
1186 }
1187 if len(cps[i].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves.) == 0 && len(cps[j].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves.) > 0 {
1188 cps[i].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves. = cps[j].Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#Curves.
1189 }
1190 if cps[i].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. == "" && cps[j].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. != "" {
1191 cps[i].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI. = cps[j].DefaultSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#DefaultSNI.
1192 }
1193 if cps[i].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. == "" && cps[j].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. != "" {
1194 cps[i].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI. = cps[j].FallbackSNIscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#FallbackSNI.
1195 }
1196 if cps[i].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin. == "" && cps[j].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin. != "" {
1197 cps[i].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin. = cps[j].ProtocolMinscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMin.
1198 }
1199 if cps[i].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax. == "" && cps[j].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax. != "" {
1200 cps[i].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax. = cps[j].ProtocolMaxscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#ProtocolMax.
1201 }
1202
1203 if cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection. == nil && cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection. != nil {
1204 // if j is the only one with a policy, move it over to i
1205 cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection. = cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection.
1206 } else if cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection. != nil && cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection. != nil {
1207 // if both have one, then combine AnyTag
1208 for _, tag := range cps[j].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..AnyTagscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#AnyTag. {
1209 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().(cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..AnyTagscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#AnyTag., tag) {
1210 cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..AnyTagscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#AnyTag. = append(cps[i].CertSelectionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/ConnectionPolicy#CertSelection..AnyTagscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CustomCertSelectionPolicy#AnyTag., tag)
1211 }
1212 }
1213 }
1214
1215 cps = slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Deletescip-go gomod github.com/golang/go/src go1.25.1 slices/Delete().(cps, j, j+1)
1216 i--
1217 break
1218 }
1219 }
1220 }
1221
1222 return cps, nil
1223 }
1224
1225 // appendSubrouteToRouteList appends the routes in subroute
1226 // to the routeList, optionally qualified by matchers.
1227 func appendSubrouteToRouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/appendSubrouteToRouteList().(routeList caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RouteList#,
1228 subroute *caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#,
1229 matcherSetsEnc []caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#,
1230 p sbAddrAssociationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#,
1231 warnings *[]caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#,
1232 ) caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RouteList# {
1233 // nothing to do if... there's nothing to do
1234 if len(matcherSetsEnc) == 0 && len(subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.) == 0 && subroute.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Errors. == nil {
1235 return routeList
1236 }
1237
1238 // No need to wrap the handlers in a subroute if this is the only server block
1239 // and there is no matcher for it (doing so would produce unnecessarily nested
1240 // JSON), *unless* there is a host matcher within this site block; if so, then
1241 // we still need to wrap in a subroute because otherwise the host matcher from
1242 // the inside of the site block would be a top-level host matcher, which is
1243 // subject to auto-HTTPS (cert management), and using a host matcher within
1244 // a site block is a valid, common pattern for excluding domains from cert
1245 // management, leading to unexpected behavior; see issue #5124.
1246 wrapInSubroute := true
1247 if len(matcherSetsEnc) == 0 && len(p.serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks.) == 1 {
1248 var hasHostMatcher bool
1249 outer:
1250 for _, route := range subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes. {
1251 for _, ms := range route.MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw. {
1252 for matcherName := range ms {
1253 if matcherName == "host" {
1254 hasHostMatcher = true
1255 break outer
1256 }
1257 }
1258 }
1259 }
1260 wrapInSubroute = hasHostMatcher
1261 }
1262
1263 if wrapInSubroute {
1264 route := caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#{
1265 // the semantics of a site block in the Caddyfile dictate
1266 // that only the first matching one is evaluated, since
1267 // site blocks do not cascade nor inherit
1268 Terminalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#Terminal.: true,
1269 }
1270 if len(matcherSetsEnc) > 0 {
1271 route.MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw. = matcherSetsEnc
1272 }
1273 if len(subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.) > 0 || subroute.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Errors. != nil {
1274 route.HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw. = []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#{
1275 caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONModuleObjectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSONModuleObject().(subroute, "handler", "subroute", warnings),
1276 }
1277 }
1278 if len(route.MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw.) > 0 || len(route.HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw.) > 0 {
1279 routeList = append(routeList, route)
1280 }
1281 } else {
1282 routeList = append(routeList, subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes....)
1283 }
1284
1285 return routeList
1286 }
1287
1288 // buildSubroute turns the config values, which are expected to be routes
1289 // into a clean and orderly subroute that has all the routes within it.
1290 func buildSubroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/buildSubroute().(routes []ConfigValuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#, groupCounter counterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#, needsSorting bool) (*caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#, error) {
1291 if needsSorting {
1292 for _, val := range routes {
1293 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().(directiveOrderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/directiveOrder., val.directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#directive.) {
1294 return nil, 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().("directive '%s' is not an ordered HTTP handler, so it cannot be used here - try placing within a route block or using the order global option", val.directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#directive.)
1295 }
1296 }
1297
1298 sortRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sortRoutes().(routes)
1299 }
1300
1301 subroute := new(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#)
1302
1303 // some directives are mutually exclusive (only first matching
1304 // instance should be evaluated); this is done by putting their
1305 // routes in the same group
1306 mutuallyExclusiveDirs := map[string]*struct {
1307 count int
1308 groupName string
1309 }{
1310 // as a special case, group rewrite directives so that they are mutually exclusive;
1311 // this means that only the first matching rewrite will be evaluated, and that's
1312 // probably a good thing, since there should never be a need to do more than one
1313 // rewrite (I think?), and cascading rewrites smell bad... imagine these rewrites:
1314 // rewrite /docs/json/* /docs/json/index.html
1315 // rewrite /docs/* /docs/index.html
1316 // (We use this on the Caddy website, or at least we did once.) The first rewrite's
1317 // result is also matched by the second rewrite, making the first rewrite pointless.
1318 // See issue #2959.
1319 "rewrite": {},
1320
1321 // handle blocks are also mutually exclusive by definition
1322 "handle": {},
1323
1324 // root just sets a variable, so if it was not mutually exclusive, intersecting
1325 // root directives would overwrite previously-matched ones; they should not cascade
1326 "root": {},
1327 }
1328
1329 // we need to deterministically loop over each of these directives
1330 // in order to keep the group numbers consistent
1331 keys := make([]string, 0, len(mutuallyExclusiveDirs))
1332 for k := range mutuallyExclusiveDirs {
1333 keys = append(keys, k)
1334 }
1335 sortscip-go gomod github.com/golang/go/src go1.25.1 sort/.Stringsscip-go gomod github.com/golang/go/src go1.25.1 sort/Strings().(keys)
1336
1337 for _, meDir := range keys {
1338 info := mutuallyExclusiveDirs[meDir]
1339
1340 // see how many instances of the directive there are
1341 for _, r := range routes {
1342 if r.directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#directive. == meDir {
1343 info.count++
1344 if info.count > 1 {
1345 break
1346 }
1347 }
1348 }
1349 // if there is more than one, put them in a group
1350 // (special case: "rewrite" directive must always be in
1351 // its own group--even if there is only one--because we
1352 // do not want a rewrite to be consolidated into other
1353 // adjacent routes that happen to have the same matcher,
1354 // see caddyserver/caddy#3108 - because the implied
1355 // intent of rewrite is to do an internal redirect,
1356 // we can't assume that the request will continue to
1357 // match the same matcher; anyway, giving a route a
1358 // unique group name should keep it from consolidating)
1359 if info.count > 1 || meDir == "rewrite" {
1360 info.groupName = groupCounter.nextGroupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#nextGroup().()
1361 }
1362 }
1363
1364 // add all the routes piled in from directives
1365 for _, r := range routes {
1366 // put this route into a group if it is mutually exclusive
1367 if info, ok := mutuallyExclusiveDirs[r.directivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#directive.]; ok {
1368 route := r.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#)
1369 route.Groupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#Group. = info.groupName
1370 r.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value. = route
1371 }
1372
1373 switch route := r.Valuescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ConfigValue#Value..(type) {
1374 case caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Subroutescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#:
1375 // if a route-class config value is actually a Subroute handler
1376 // with nothing but a list of routes, then it is the intention
1377 // of the directive to keep these handlers together and in this
1378 // same order, but not necessarily in a subroute (if it wanted
1379 // to keep them in a subroute, the directive would have returned
1380 // a route with a Subroute as its handler); this is useful to
1381 // keep multiple handlers/routes together and in the same order
1382 // so that the sorting procedure we did above doesn't reorder them
1383 if route.Errorsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Errors. != nil {
1384 // if error handlers are also set, this is confusing; it's
1385 // probably supposed to be wrapped in a Route and encoded
1386 // as a regular handler route... programmer error.
1387 panic("found subroute with more than just routes; perhaps it should have been wrapped in a route?")
1388 }
1389 subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes. = append(subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes., route.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes....)
1390 case caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Routescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#:
1391 subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes. = append(subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes., route)
1392 }
1393 }
1394
1395 subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes. = consolidateRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/consolidateRoutes().(subroute.Routesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Subroute#Routes.)
1396
1397 return subroute, nil
1398 }
1399
1400 // normalizeDirectiveName ensures directives that should be sorted
1401 // at the same level are named the same before sorting happens.
1402 func normalizeDirectiveNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/normalizeDirectiveName().(directive string) string {
1403 // As a special case, we want "handle_path" to be sorted
1404 // at the same level as "handle", so we force them to use
1405 // the same directive name after their parsing is complete.
1406 // See https://github.com/caddyserver/caddy/issues/3675#issuecomment-678042377
1407 if directive == "handle_path" {
1408 directive = "handle"
1409 }
1410 return directive
1411 }
1412
1413 // consolidateRoutes combines routes with the same properties
1414 // (same matchers, same Terminal and Group settings) for a
1415 // cleaner overall output.
1416 func consolidateRoutesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/consolidateRoutes().(routes caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RouteList#) caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RouteListscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RouteList# {
1417 for i := 0; i < len(routes)-1; i++ {
1418 if reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(routes[i].MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw., routes[i+1].MatcherSetsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#MatcherSetsRaw.) &&
1419 routes[i].Terminalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#Terminal. == routes[i+1].Terminalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#Terminal. &&
1420 routes[i].Groupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#Group. == routes[i+1].Groupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#Group. {
1421 // keep the handlers in the same order, then splice out repetitive route
1422 routes[i].HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw. = append(routes[i].HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw., routes[i+1].HandlersRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Route#HandlersRaw....)
1423 routes = append(routes[:i+1], routes[i+2:]...)
1424 i--
1425 }
1426 }
1427 return routes
1428 }
1429
1430 func matcherSetFromMatcherTokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/matcherSetFromMatcherToken().(
1431 tkn caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#,
1432 matcherDefs map[string]caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#,
1433 warnings *[]caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#,
1434 ) (caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#, bool, error) {
1435 // matcher tokens can be wildcards, simple path matchers,
1436 // or refer to a pre-defined matcher by some name
1437 if tkn.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text. == "*" {
1438 // match all requests == no matchers, so nothing to do
1439 return nil, true, nil
1440 }
1441
1442 // convenient way to specify a single path match
1443 if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.1 strings/HasPrefix().(tkn.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text., "/") {
1444 return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#{
1445 "path": caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.MatchPathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchPath#{tkn.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text.}, warnings),
1446 }, true, nil
1447 }
1448
1449 // pre-defined matcher
1450 if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.1 strings/HasPrefix().(tkn.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text., matcherPrefixscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/matcherPrefix.) {
1451 m, ok := matcherDefs[tkn.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text.]
1452 if !ok {
1453 return nil, false, 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().("unrecognized matcher name: %+v", tkn.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text.)
1454 }
1455 return m, true, nil
1456 }
1457
1458 return nil, false, nil
1459 }
1460
1461 func (st *ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#) compileEncodedMatcherSetsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#compileEncodedMatcherSets().(sblock serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#) ([]caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#, error) {
1462 type hostPathPair struct {
1463 hostm caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.MatchHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchHost#
1464 pathm caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.MatchPathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchPath#
1465 }
1466
1467 // keep routes with common host and path matchers together
1468 var matcherPairs []*hostPathPair
1469
1470 var catchAllHosts bool
1471 for _, addr := range sblock.parsedKeysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#parsedKeys. {
1472 // choose a matcher pair that should be shared by this
1473 // server block; if none exists yet, create one
1474 var chosenMatcherPair *hostPathPair
1475 for _, mp := range matcherPairs {
1476 if (len(mp.pathm) == 0 && addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path. == "") ||
1477 (len(mp.pathm) == 1 && mp.pathm[0] == addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.) {
1478 chosenMatcherPair = mp
1479 break
1480 }
1481 }
1482 if chosenMatcherPair == nil {
1483 chosenMatcherPair = new(hostPathPair)
1484 if addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path. != "" {
1485 chosenMatcherPair.pathm = []string{addr.Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Path.}
1486 }
1487 matcherPairs = append(matcherPairs, chosenMatcherPair)
1488 }
1489
1490 // if one of the keys has no host (i.e. is a catch-all for
1491 // any hostname), then we need to null out the host matcher
1492 // entirely so that it matches all hosts
1493 if addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. == "" && !catchAllHosts {
1494 chosenMatcherPair.hostm = nil
1495 catchAllHosts = true
1496 }
1497 if catchAllHosts {
1498 continue
1499 }
1500
1501 // add this server block's keys to the matcher
1502 // pair if it doesn't already exist
1503 if addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host. != "" && !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().(chosenMatcherPair.hostm, addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.) {
1504 chosenMatcherPair.hostm = append(chosenMatcherPair.hostm, addr.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/Address#Host.)
1505 }
1506 }
1507
1508 // iterate each pairing of host and path matchers and
1509 // put them into a map for JSON encoding
1510 var matcherSets []map[string]caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError#
1511 for _, mp := range matcherPairs {
1512 matcherSet := make(map[string]caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError#)
1513 if len(mp.hostm) > 0 {
1514 matcherSet["host"] = mp.hostm
1515 }
1516 if len(mp.pathm) > 0 {
1517 matcherSet["path"] = mp.pathm
1518 }
1519 if len(matcherSet) > 0 {
1520 matcherSets = append(matcherSets, matcherSet)
1521 }
1522 }
1523
1524 // finally, encode each of the matcher sets
1525 matcherSetsEnc := make([]caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#, 0, len(matcherSets))
1526 for _, ms := range matcherSets {
1527 msEncoded, err := encodeMatcherSetscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/encodeMatcherSet().(ms)
1528 if err != nil {
1529 return nil, 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().("server block %v: %v", sblock.blockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#block..Keysscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerBlock#Keys., err)
1530 }
1531 matcherSetsEnc = append(matcherSetsEnc, msEncoded)
1532 }
1533
1534 return matcherSetsEnc, nil
1535 }
1536
1537 func parseMatcherDefinitionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/parseMatcherDefinitions().(d *caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#, matchers map[string]caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#) error {
1538 d.Nextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Next().() // advance to the first token
1539
1540 // this is the "name" for "named matchers"
1541 definitionName := d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().()
1542
1543 if _, ok := matchers[definitionName]; ok {
1544 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().("matcher is defined more than once: %s", definitionName)
1545 }
1546 matchers[definitionName] = make(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#)
1547
1548 // given a matcher name and the tokens following it, parse
1549 // the tokens as a matcher module and record it
1550 makeMatcher := func(matcherName string, tokens []caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#) error {
1551 // create a new dispenser from the tokens
1552 dispenser := caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(tokens)
1553
1554 // set the matcher name (without @) in the dispenser context so
1555 // that matcher modules can access it to use it as their name
1556 // (e.g. regexp matchers which use the name for capture groups)
1557 dispenser.SetContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#SetContext().(caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.MatcherNameCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/MatcherNameCtxKey., definitionName[1:])
1558
1559 mod, err := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.GetModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/GetModule().("http.matchers." + matcherName)
1560 if err != nil {
1561 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().("getting matcher module '%s': %v", matcherName, err)
1562 }
1563 unm, ok := mod.Newscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#New.().(caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Unmarshalerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Unmarshaler#)
1564 if !ok {
1565 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().("matcher module '%s' is not a Caddyfile unmarshaler", matcherName)
1566 }
1567 err = unm.UnmarshalCaddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Unmarshaler#UnmarshalCaddyfile.(dispenser)
1568 if err != nil {
1569 return err
1570 }
1571
1572 if rm, ok := unm.(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError#); ok {
1573 matchers[definitionName][matcherName] = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(rm, nil)
1574 return nil
1575 }
1576 // nolint:staticcheck
1577 if rm, ok := unm.(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RequestMatcherscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcher#); ok {
1578 matchers[definitionName][matcherName] = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSON().(rm, nil)
1579 return nil
1580 }
1581 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().("matcher module '%s' is not a request matcher", matcherName)
1582 }
1583
1584 // if the next token is quoted, we can assume it's not a matcher name
1585 // and that it's probably an 'expression' matcher
1586 if d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() {
1587 if d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().().Quotedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Quoted().() {
1588 // since it was missing the matcher name, we insert a token
1589 // in front of the expression token itself; we use Clone() to
1590 // make the new token to keep the same the import location as
1591 // the next token, if this is within a snippet or imported file.
1592 // see https://github.com/caddyserver/caddy/issues/6287
1593 expressionToken := d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().().Clonescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Clone().()
1594 expressionToken.Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text. = "expression"
1595 err := makeMatcher("expression", []caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#{expressionToken, d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().()})
1596 if err != nil {
1597 return err
1598 }
1599 return nil
1600 }
1601
1602 // if it wasn't quoted, then we need to rewind after calling
1603 // d.NextArg() so the below properly grabs the matcher name
1604 d.Prevscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Prev().()
1605 }
1606
1607 // in case there are multiple instances of the same matcher, concatenate
1608 // their tokens (we expect that UnmarshalCaddyfile should be able to
1609 // handle more than one segment); otherwise, we'd overwrite other
1610 // instances of the matcher in this set
1611 tokensByMatcherName := make(map[string][]caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#)
1612 for nesting := d.Nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Nesting().(); d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() || d.NextBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextBlock().(nesting); {
1613 matcherName := d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().()
1614 tokensByMatcherName[matcherName] = append(tokensByMatcherName[matcherName], d.NextSegmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextSegment().()...)
1615 }
1616 for matcherName, tokens := range tokensByMatcherName {
1617 err := makeMatcher(matcherName, tokens)
1618 if err != nil {
1619 return err
1620 }
1621 }
1622 return nil
1623 }
1624
1625 func encodeMatcherSetscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/encodeMatcherSet().(matchers map[string]caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError#) (caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#, error) {
1626 msEncoded := make(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleMap#)
1627 for matcherName, val := range matchers {
1628 jsonBytes, err := jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/Marshal().(val)
1629 if err != nil {
1630 return nil, 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().("marshaling matcher set %#v: %v", matchers, err)
1631 }
1632 msEncoded[matcherName] = jsonBytes
1633 }
1634 return msEncoded, nil
1635 }
1636
1637 // WasReplacedPlaceholderShorthand checks if a token string was
1638 // likely a replaced shorthand of the known Caddyfile placeholder
1639 // replacement outputs. Useful to prevent some user-defined map
1640 // output destinations from overlapping with one of the
1641 // predefined shorthands.
1642 func WasReplacedPlaceholderShorthandscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/WasReplacedPlaceholderShorthand().(token string) string {
1643 prev := ""
1644 for i, item := range placeholderShorthandsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/placeholderShorthands().() {
1645 // only look at every 2nd item, which is the replacement
1646 if i%2 == 0 {
1647 prev = item
1648 continue
1649 }
1650 if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Trimscip-go gomod github.com/golang/go/src go1.25.1 strings/Trim().(token, "{}") == stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Trimscip-go gomod github.com/golang/go/src go1.25.1 strings/Trim().(item, "{}") {
1651 // we return the original shorthand so it
1652 // can be used for an error message
1653 return prev
1654 }
1655 }
1656 return ""
1657 }
1658
1659 // tryInt tries to convert val to an integer. If it fails,
1660 // it downgrades the error to a warning and returns 0.
1661 func tryIntscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryInt().(val any, warnings *[]caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#) int {
1662 intVal, ok := val.(int)
1663 if val != nil && !ok && warnings != nil {
1664 *warnings = append(*warnings, caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#{Messagescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#Message.: "not an integer type"})
1665 }
1666 return intVal
1667 }
1668
1669 func tryStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryString().(val any, warnings *[]caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#) string {
1670 stringVal, ok := val.(string)
1671 if val != nil && !ok && warnings != nil {
1672 *warnings = append(*warnings, caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#{Messagescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#Message.: "not a string type"})
1673 }
1674 return stringVal
1675 }
1676
1677 func tryDurationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/tryDuration().(val any, warnings *[]caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#) 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# {
1678 durationVal, ok := val.(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#)
1679 if val != nil && !ok && warnings != nil {
1680 *warnings = append(*warnings, caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.Warningscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#{Messagescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/Warning#Message.: "not a duration type"})
1681 }
1682 return durationVal
1683 }
1684
1685 // listenersUseAnyPortOtherThan returns true if there are any
1686 // listeners in addresses that use a port which is not otherPort.
1687 // Mostly borrowed from unexported method in caddyhttp package.
1688 func listenersUseAnyPortOtherThanscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/listenersUseAnyPortOtherThan().(addresses []string, otherPort string) bool {
1689 otherPortInt, err := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.1 strconv/Atoi().(otherPort)
1690 if err != nil {
1691 return false
1692 }
1693 for _, lnAddr := range addresses {
1694 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)
1695 if err != nil {
1696 continue
1697 }
1698 if uint(otherPortInt) > laddrs.EndPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#EndPort. || uint(otherPortInt) < laddrs.StartPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#StartPort. {
1699 return true
1700 }
1701 }
1702 return false
1703 }
1704
1705 func mapContainsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/mapContains().[K comparable, V any](m map[K]V, keys []K) bool {
1706 if len(m) == 0 || len(keys) == 0 {
1707 return false
1708 }
1709 for _, key := range keys {
1710 if _, ok := m[key]; ok {
1711 return true
1712 }
1713 }
1714 return false
1715 }
1716
1717 // specificity returns len(s) minus any wildcards (*) and
1718 // placeholders ({...}). Basically, it's a length count
1719 // that penalizes the use of wildcards and placeholders.
1720 // This is useful for comparing hostnames and paths.
1721 // However, wildcards in paths are not a sure answer to
1722 // the question of specificity. For example,
1723 // '*.example.com' is clearly less specific than
1724 // 'a.example.com', but is '/a' more or less specific
1725 // than '/a*'?
1726 func specificityscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/specificity().(s string) int {
1727 l := len(s) - stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Countscip-go gomod github.com/golang/go/src go1.25.1 strings/Count().(s, "*")
1728 for len(s) > 0 {
1729 start := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Indexscip-go gomod github.com/golang/go/src go1.25.1 strings/Index().(s, "{")
1730 if start < 0 {
1731 return l
1732 }
1733 end := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Indexscip-go gomod github.com/golang/go/src go1.25.1 strings/Index().(s[start:], "}") + start + 1
1734 if end <= start {
1735 return l
1736 }
1737 l -= end - start
1738 s = s[end:]
1739 }
1740 return l
1741 }
1742
1743 type counterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter# struct {
1744 nscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#n. *int
1745 }
1746
1747 func (c counterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#) nextGroupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#nextGroup().() string {
1748 name := fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Sprintf().("group%d", *c.nscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#n.)
1749 *c.nscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/counter#n.++
1750 return name
1751 }
1752
1753 type namedCustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog# struct {
1754 namescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#name. string
1755 hostnamesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#hostnames. []string
1756 logscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#log. *caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CustomLogscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CustomLog#
1757 noHostnamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedCustomLog#noHostname. bool
1758 }
1759
1760 // addressWithProtocols associates a listen address with
1761 // the protocols to serve it with
1762 type addressWithProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/addressWithProtocols# struct {
1763 addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/addressWithProtocols#address. string
1764 protocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/addressWithProtocols#protocols. []string
1765 }
1766
1767 // sbAddrAssociation is a mapping from a list of
1768 // addresses with protocols, and a list of server
1769 // blocks that are served on those addresses.
1770 type sbAddrAssociationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation# struct {
1771 addressesWithProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#addressesWithProtocols. []addressWithProtocolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/addressWithProtocols#
1772 serverBlocksscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/sbAddrAssociation#serverBlocks. []serverBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/serverBlock#
1773 }
1774
1775 const (
1776 matcherPrefixscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/matcherPrefix. = "@"
1777 namedRouteKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/namedRouteKey. = "named_route"
1778 )
1779
1780 // Interface guard
1781 var _ caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ServerType# = (*ServerTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile`/ServerType#)(nil)