@marcel91200 / caddy Mirror · read-only / commits / 8b2ad612
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

httpcaddyfile: Skip hosts from auto-https when http:// scheme (fix #2998)

Matthew Holt committed Jan 23, 2020 at 13:17 UTC 8b2ad61220f199e7329f218e21a6950bb1ab4c67
1 file changed +28
caddyconfig/httpcaddyfile/httptype.go
+28
@@ -389,6 +389,24 @@ func (st *ServerType) serversFromPairings(
389 // TODO: consolidate equal conn policies
390 }
391
392 + // exclude any hosts that were defined explicitly with
393 + // "http://" in the key from automated cert management (issue #2998)
394 + for _, key := range sblock.block.Keys {
395 + addr, err := ParseAddress(key)
396 + if err != nil {
397 + return nil, err
398 + }
399 + addr = addr.Normalize()
400 + if addr.Scheme == "http" {
401 + if srv.AutoHTTPS == nil {
402 + srv.AutoHTTPS = new(caddyhttp.AutoHTTPSConfig)
403 + }
404 + if !sliceContains(srv.AutoHTTPS.Skip, addr.Host) {
405 + srv.AutoHTTPS.Skip = append(srv.AutoHTTPS.Skip, addr.Host)
406 + }
407 + }
408 + }
409 +
410 // set up each handler directive, making sure to honor directive order
411 dirRoutes := sblock.pile["route"]
412 siteSubroute, err := buildSubroute(dirRoutes, groupCounter)
@@ -723,6 +741,16 @@ func tryInt(val interface{}, warnings *[]caddyconfig.Warning) int {
741 return intVal
742 }
743
744 +// sliceContains returns true if needle is in haystack.
745 +func sliceContains(haystack []string, needle string) bool {
746 + for _, s := range haystack {
747 + if s == needle {
748 + return true
749 + }
750 + }
751 + return false
752 +}
753 +
754 // specifity returns len(s) minus any wildcards (*) and
755 // placeholders ({...}). Basically, it's a length count
756 // that penalizes the use of wildcards and placeholders.