diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-09-18 18:01:32 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-09-18 18:01:32 -0600 |
commit | 40e05e5a01d50b381fa7a7a472ea38f44518f02c (patch) | |
tree | beb53883008ce4a91aa8e2f3ceed2024a9408f85 /modules/caddyhttp/server.go | |
parent | 39d61cad2d27cb7869e7dbf64faad7d90857e944 (diff) |
http: Improve auto HTTP->HTTPS redirects, fix edge cases
See https://caddy.community/t/v2-issues-with-multiple-server-blocks-in-caddyfile-style-config/6206/13?u=matt
Also print pid when using `caddy start`
Diffstat (limited to 'modules/caddyhttp/server.go')
-rw-r--r-- | modules/caddyhttp/server.go | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go index 0ccdeea..c4c306e 100644 --- a/modules/caddyhttp/server.go +++ b/modules/caddyhttp/server.go @@ -196,17 +196,26 @@ func (s *Server) listenersUseAnyPortOtherThan(otherPort int) bool { return false } -// listenersIncludePort returns true if there are any -// listeners in s that use otherPort. -func (s *Server) listenersIncludePort(otherPort int) bool { +func (s *Server) hasListenerAddress(fullAddr string) bool { + netw, addrs, err := caddy.ParseNetworkAddress(fullAddr) + if err != nil { + return false + } + if len(addrs) != 1 { + return false + } + addr := addrs[0] for _, lnAddr := range s.Listen { - _, addrs, err := caddy.ParseNetworkAddress(lnAddr) - if err == nil { - for _, a := range addrs { - _, port, err := net.SplitHostPort(a) - if err == nil && port == strconv.Itoa(otherPort) { - return true - } + thisNetw, thisAddrs, err := caddy.ParseNetworkAddress(lnAddr) + if err != nil { + continue + } + if thisNetw != netw { + continue + } + for _, a := range thisAddrs { + if a == addr { + return true } } } |