summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-22 14:14:26 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-22 14:14:26 -0600
commit869fbac632bc098f8d40fd7b43790fadce84ed1a (patch)
tree45400f5e541aec8b7786c65638ef44f9b678dd14 /modules/caddyhttp
parent284fb3a98cae2e6e6ca79327988230a3a916996a (diff)
Don't use auto HTTPS for servers with only HTTP port listeners
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/caddyhttp.go5
-rw-r--r--modules/caddyhttp/server.go16
2 files changed, 21 insertions, 0 deletions
diff --git a/modules/caddyhttp/caddyhttp.go b/modules/caddyhttp/caddyhttp.go
index 1ff2cbc..0fde218 100644
--- a/modules/caddyhttp/caddyhttp.go
+++ b/modules/caddyhttp/caddyhttp.go
@@ -188,6 +188,11 @@ func (app *App) automaticHTTPS() error {
continue
}
+ // skip if all listeners use the HTTP port
+ if !srv.listenersUseAnyPortOtherThan(app.HTTPPort) {
+ continue
+ }
+
// find all qualifying domain names, de-duplicated
domainSet := make(map[string]struct{})
for _, route := range srv.Routes {
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index c66fcab..8a16cea 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
+ "net"
"net/http"
"strconv"
@@ -98,6 +99,21 @@ func (s *Server) executeCompositeRoute(w http.ResponseWriter, r *http.Request, s
return err
}
+func (s *Server) listenersUseAnyPortOtherThan(otherPort int) bool {
+ for _, lnAddr := range s.Listen {
+ _, addrs, err := parseListenAddr(lnAddr)
+ if err == nil {
+ for _, a := range addrs {
+ _, port, err := net.SplitHostPort(a)
+ if err == nil && port != strconv.Itoa(otherPort) {
+ return true
+ }
+ }
+ }
+ }
+ return false
+}
+
type httpErrorConfig struct {
Routes RouteList `json:"routes,omitempty"`
// TODO: some way to configure the logging of errors, probably? standardize