File tree Expand file tree Collapse file tree 3 files changed +90
-1
lines changed
caddyconfig/httpcaddyfile
caddytest/integration/caddyfile_adapt Expand file tree Collapse file tree 3 files changed +90
-1
lines changed Original file line number Diff line number Diff line change @@ -478,6 +478,27 @@ func (sb serverBlock) hostsFromKeys(loggerMode bool) []string {
478478 return sblockHosts
479479}
480480
481+ func (sb serverBlock ) hostsFromKeysNotHTTP (httpPort string ) []string {
482+ // ensure each entry in our list is unique
483+ hostMap := make (map [string ]struct {})
484+ for _ , addr := range sb .keys {
485+ if addr .Host == "" {
486+ continue
487+ }
488+ if addr .Scheme != "http" && addr .Port != httpPort {
489+ hostMap [addr .Host ] = struct {}{}
490+ }
491+ }
492+
493+ // convert map to slice
494+ sblockHosts := make ([]string , 0 , len (hostMap ))
495+ for host := range hostMap {
496+ sblockHosts = append (sblockHosts , host )
497+ }
498+
499+ return sblockHosts
500+ }
501+
481502// hasHostCatchAllKey returns true if sb has a key that
482503// omits a host portion, i.e. it "catches all" hosts.
483504func (sb serverBlock ) hasHostCatchAllKey () bool {
Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ func (st ServerType) buildTLSApp(
189189 }
190190
191191 // associate our new automation policy with this server block's hosts
192- ap .Subjects = sblockHosts
192+ ap .Subjects = sblock . hostsFromKeysNotHTTP ( httpPort )
193193 sort .Strings (ap .Subjects ) // solely for deterministic test results
194194
195195 // if a combination of public and internal names were given
Original file line number Diff line number Diff line change 1+ # (this Caddyfile is contrived, but based on issues #4176 and #4198)
2+
3+ http://example.com {
4+ }
5+
6+ https://example.com {
7+ tls internal
8+ }
9+
10+ ----------
11+ {
12+ "apps": {
13+ "http": {
14+ "servers": {
15+ "srv0": {
16+ "listen": [
17+ ":443"
18+ ],
19+ "routes": [
20+ {
21+ "match": [
22+ {
23+ "host": [
24+ "example.com"
25+ ]
26+ }
27+ ],
28+ "terminal": true
29+ }
30+ ]
31+ },
32+ "srv1": {
33+ "listen": [
34+ ":80"
35+ ],
36+ "routes": [
37+ {
38+ "match": [
39+ {
40+ "host": [
41+ "example.com"
42+ ]
43+ }
44+ ],
45+ "terminal": true
46+ }
47+ ]
48+ }
49+ }
50+ },
51+ "tls": {
52+ "automation": {
53+ "policies": [
54+ {
55+ "subjects": [
56+ "example.com"
57+ ],
58+ "issuers": [
59+ {
60+ "module": "internal"
61+ }
62+ ]
63+ }
64+ ]
65+ }
66+ }
67+ }
68+ }
You can’t perform that action at this time.
0 commit comments