all repos — website @ c8c7dd2a02eb145632b04d2710d297bd6af63a94

My website

refactor: simplify logging of Host header

since net/http doesn't accept requests without a Host header, there's
no need for a fallback
Alan Pearce alan@alanpearce.eu
Wed, 22 May 2024 18:58:50 +0200
commit

c8c7dd2a02eb145632b04d2710d297bd6af63a94

parent

ea098ab11740fe4783694ff0122738b30e0c342f

2 files changed, 2 insertions(+), 11 deletions(-)

jump to
M internal/server/logging.gointernal/server/logging.go
@@ -22,20 +22,13 @@ func NewLoggingResponseWriter(w http.ResponseWriter) *LoggingResponseWriter { 	return &LoggingResponseWriter{w, http.StatusOK}
 }
 
-type wrappedHandlerOptions struct {
-	defaultHostname string
-}
-
-func wrapHandlerWithLogging(wrappedHandler http.Handler, opts wrappedHandlerOptions) http.Handler {
+func wrapHandlerWithLogging(wrappedHandler http.Handler) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		scheme := r.Header.Get("X-Forwarded-Proto")
 		if scheme == "" {
 			scheme = "http"
 		}
 		host := r.Host
-		if host == "" {
-			host = opts.defaultHostname
-		}
 		lw := NewLoggingResponseWriter(w)
 		wrappedHandler.ServeHTTP(lw, r)
 		statusCode := lw.statusCode
M internal/server/server.gointernal/server/server.go
@@ -107,9 +107,7 @@ Addr:              listenAddress, 			ReadHeaderTimeout: 1 * time.Minute,
 			Handler: sentryHandler.Handle(
 				serverHeaderHandler(
-					wrapHandlerWithLogging(top, wrappedHandlerOptions{
-						defaultHostname: runtimeConfig.BaseURL.Hostname(),
-					}),
+					wrapHandlerWithLogging(top),
 				),
 			),
 		},