From 40e05e5a01d50b381fa7a7a472ea38f44518f02c Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 18 Sep 2019 18:01:32 -0600 Subject: 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` --- modules/caddyhttp/server.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'modules/caddyhttp/server.go') 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 } } } -- cgit v1.2.3