diff options
author | Francis Lavoie <lavofr@gmail.com> | 2022-03-25 00:54:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 22:54:03 -0600 |
commit | a58f240d3ecbb59285303746406cab50217f8d24 (patch) | |
tree | 60da8ebee4a81e8ad608b56e8ab81b55101111a4 /caddyconfig/httpcaddyfile/directives.go | |
parent | 4b75f3e2f09b77b98783ea4d6602391c7283f984 (diff) |
httpcaddyfile: Fix #4640 (auto-HTTPS edgecase) (#4661)
Guh, this is complicated.
Fixes #4640
This also follows up on #4398 (reverting it) which made a change that technically worked, but was incorrect. It changed the condition in `hostsFromKeysNotHTTP` from `&&` to `||`, but then the function no longer did what its name said it would do, and it would return hosts even if they were marked with `http://`, if they used a non-HTTP port. That wasn't the intent of it. The test added in there was kept though, because it is a valid usecase.
The actual fix is to check _earlier_ whether all the addresses explicitly have `http://`, and if so we can short circuit and skip considering the rest.
Diffstat (limited to 'caddyconfig/httpcaddyfile/directives.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/directives.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index 425bf19..6b80e34 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -494,7 +494,7 @@ func (sb serverBlock) hostsFromKeysNotHTTP(httpPort string) []string { if addr.Host == "" { continue } - if addr.Scheme != "http" || addr.Port != httpPort { + if addr.Scheme != "http" && addr.Port != httpPort { hostMap[addr.Host] = struct{}{} } } @@ -519,6 +519,17 @@ func (sb serverBlock) hasHostCatchAllKey() bool { return false } +// isAllHTTP returns true if all sb keys explicitly specify +// the http:// scheme +func (sb serverBlock) isAllHTTP() bool { + for _, addr := range sb.keys { + if addr.Scheme != "http" { + return false + } + } + return true +} + type ( // UnmarshalFunc is a function which can unmarshal Caddyfile // tokens into zero or more config values using a Helper type. |