@marcel91200 / caddy Mirror · read-only / commits / 869fbac6
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

Don't use auto HTTPS for servers with only HTTP port listeners

Matthew Holt committed May 22, 2019 at 14:14 UTC 869fbac632bc098f8d40fd7b43790fadce84ed1a
2 files changed +21
modules/caddyhttp/caddyhttp.go
+5
@@ -188,6 +188,11 @@ func (app *App) automaticHTTPS() error {
188 continue
189 }
190
191 + // skip if all listeners use the HTTP port
192 + if !srv.listenersUseAnyPortOtherThan(app.HTTPPort) {
193 + continue
194 + }
195 +
196 // find all qualifying domain names, de-duplicated
197 domainSet := make(map[string]struct{})
198 for _, route := range srv.Routes {
modules/caddyhttp/server.go
+16
@@ -4,6 +4,7 @@ import (
4 "context"
5 "fmt"
6 "log"
7 + "net"
8 "net/http"
9 "strconv"
10
@@ -98,6 +99,21 @@ func (s *Server) executeCompositeRoute(w http.ResponseWriter, r *http.Request, s
99 return err
100 }
101
102 +func (s *Server) listenersUseAnyPortOtherThan(otherPort int) bool {
103 + for _, lnAddr := range s.Listen {
104 + _, addrs, err := parseListenAddr(lnAddr)
105 + if err == nil {
106 + for _, a := range addrs {
107 + _, port, err := net.SplitHostPort(a)
108 + if err == nil && port != strconv.Itoa(otherPort) {
109 + return true
110 + }
111 + }
112 + }
113 + }
114 + return false
115 +}
116 +
117 type httpErrorConfig struct {
118 Routes RouteList `json:"routes,omitempty"`
119 // TODO: some way to configure the logging of errors, probably? standardize