fix inconsistent handling of IPv6 listen address
Alan Pearce alan@alanpearce.eu
Tue, 02 Jul 2024 11:47:36 +0200
3 files changed, 7 insertions(+), 11 deletions(-)
M cmd/server/main.go → cmd/server/main.go
@@ -6,8 +6,8 @@ "fmt" "os" "os/signal" - "go.alanpearce.eu/x/log" "go.alanpearce.eu/website/internal/server" + "go.alanpearce.eu/x/log" "github.com/ardanlabs/conf/v3" "gitlab.com/tozd/go/errors" @@ -24,6 +24,10 @@ } panic("parsing runtime configuration" + err.Error()) } log := log.Configure(!runtimeConfig.Development) + + if listenAddress := runtimeConfig.ListenAddress; listenAddress[0] == '[' { + runtimeConfig.ListenAddress = listenAddress[1 : len(listenAddress)-1] + } if runtimeConfig.Development { tmpdir, err := os.MkdirTemp("", "website")
M internal/server/server.go → internal/server/server.go
@@ -15,9 +15,9 @@ "time" "go.alanpearce.eu/website/internal/builder" cfg "go.alanpearce.eu/website/internal/config" - "go.alanpearce.eu/x/log" "go.alanpearce.eu/website/internal/vcs" "go.alanpearce.eu/website/internal/website" + "go.alanpearce.eu/x/log" "github.com/ardanlabs/conf/v3" "github.com/osdevisnot/sorvor/pkg/livereload" @@ -134,7 +134,6 @@ if runtimeConfig.Development { applyDevModeOverrides(config, runtimeConfig) } - listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, strconv.Itoa(runtimeConfig.Port)) top := http.NewServeMux() err = rebuild(builderConfig, config, log) @@ -210,7 +209,6 @@ ReadHeaderTimeout: 10 * time.Second, ReadTimeout: 1 * time.Minute, WriteTimeout: 2 * time.Minute, IdleTimeout: 10 * time.Minute, - Addr: listenAddress, Handler: top, }, redirectServer: &http.Server{ @@ -218,7 +216,6 @@ ReadHeaderTimeout: 10 * time.Second, ReadTimeout: 1 * time.Minute, WriteTimeout: 2 * time.Minute, IdleTimeout: 10 * time.Minute, - Addr: listenAddress, Handler: rMux, }, log: log,
M internal/server/tls.go → internal/server/tls.go
@@ -56,16 +56,11 @@ // caddy's ACME server (step-ca) doesn't specify an OCSP server cfg.OCSP.DisableStapling = true - listenAddress := s.runtimeConfig.ListenAddress - if listenAddress[0] == '[' { - listenAddress = listenAddress[1 : len(listenAddress)-1] - } - issuer = certmagic.NewACMEIssuer(cfg, certmagic.ACMEIssuer{ CA: s.runtimeConfig.ACMECA, TrustedRoots: cp, DisableTLSALPNChallenge: true, - ListenHost: listenAddress, + ListenHost: s.runtimeConfig.ListenAddress, AltHTTPPort: s.runtimeConfig.Port, AltTLSALPNPort: s.runtimeConfig.TLSPort, })