diff --git a/workhorse/internal/upstream/handlers.go b/workhorse/internal/upstream/handlers.go index 85fee0bf7e2a774a29b316950430acc7074159c5..87c193352bd3ba4c7cc58b14042a3e0e8d71a958 100644 --- a/workhorse/internal/upstream/handlers.go +++ b/workhorse/internal/upstream/handlers.go @@ -1,3 +1,8 @@ +/* +Package upstream provides functionality for handling upstream requests. + +This package includes handlers for managing request routing and interaction with upstream servers. +*/ package upstream import ( @@ -29,7 +34,7 @@ func contentEncodingHandler(h http.Handler) http.Handler { fail.Request(w, r, fmt.Errorf("contentEncodingHandler: %v", err)) return } - defer body.Close() + defer func() { _ = body.Close() }() r.Body = body r.Header.Del("Content-Encoding") diff --git a/workhorse/internal/upstream/metrics.go b/workhorse/internal/upstream/metrics.go index 27cc6bb045ba709ca692fcb2b3a48ce0154db835..dd43d412c2934c68e1767d1b0672f54a52afd71d 100644 --- a/workhorse/internal/upstream/metrics.go +++ b/workhorse/internal/upstream/metrics.go @@ -29,10 +29,10 @@ var ( buildHandler = metrics.NewHandlerFactory(metrics.WithNamespace(namespace), metrics.WithLabels("route")) ) -func instrumentRoute(next http.Handler, method string, regexpStr string) http.Handler { +func instrumentRoute(next http.Handler, _ string, regexpStr string) http.Handler { return buildHandler(next, metrics.WithLabelValues(map[string]string{"route": regexpStr})) } -func instrumentGeoProxyRoute(next http.Handler, method string, regexpStr string) http.Handler { +func instrumentGeoProxyRoute(next http.Handler, _ string, regexpStr string) http.Handler { return promhttp.InstrumentHandlerCounter(httpGeoProxiedRequestsTotal.MustCurryWith(map[string]string{"route": regexpStr}), next) } diff --git a/workhorse/internal/upstream/notfoundunless.go b/workhorse/internal/upstream/notfoundunless.go index 3bbe3e873a46c88fb22d2f34d8e6241a10c7ae00..78ed984ea6aed2912beafb661ec341616e2e55c6 100644 --- a/workhorse/internal/upstream/notfoundunless.go +++ b/workhorse/internal/upstream/notfoundunless.go @@ -2,10 +2,11 @@ package upstream import "net/http" +// NotFoundUnless returns a handler that forwards requests to the given handler if pass is true. +// Otherwise, it responds with a 404 Not Found status. func NotFoundUnless(pass bool, handler http.Handler) http.Handler { if pass { return handler } - - return http.HandlerFunc(http.NotFound) + return http.NotFoundHandler() } diff --git a/workhorse/internal/upstream/roundtripper/roundtripper.go b/workhorse/internal/upstream/roundtripper/roundtripper.go index fcba50d79755332b47a5a90048bbb783b55ac178..19d9e12136da665e39434857d6ed37bbbc4490db 100644 --- a/workhorse/internal/upstream/roundtripper/roundtripper.go +++ b/workhorse/internal/upstream/roundtripper/roundtripper.go @@ -1,3 +1,9 @@ +/* +Package roundtripper provides a custom HTTP roundtripper for handling requests. + +This package implements a custom HTTP transport for handling HTTP requests +with additional features such as logging, tracing, and error handling. +*/ package roundtripper import ( @@ -41,16 +47,17 @@ func newBackendRoundTripper(backend *url.URL, socket string, proxyHeadersTimeout dial := transport.DialContext - if backend != nil && socket == "" { + switch { + case backend != nil && socket == "": address := mustParseAddress(backend.Host, backend.Scheme) transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { return dial(ctx, "tcp", address) } - } else if socket != "" { + case socket != "": transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { return dial(ctx, "unix", socket) } - } else { + default: panic("backend is nil and socket is empty") } diff --git a/workhorse/internal/upstream/routes.go b/workhorse/internal/upstream/routes.go index cf75f919968680f074c2a3574b4df709ead98845..7bf03f662db5d1fd4cb22ed6d5d8b83fee25b9cf 100644 --- a/workhorse/internal/upstream/routes.go +++ b/workhorse/internal/upstream/routes.go @@ -384,8 +384,8 @@ func configureRoutes(u *upstream) { u.geoLocalRoutes = []routeEntry{ // Git and LFS requests // - // Note that Geo already redirects pushes, with special terminal output. - // Note that excessive secondary lag can cause unexpected behavior since + // Geo already redirects pushes, with special terminal output. + // Excessive secondary lag can cause unexpected behavior since // pulls are performed against a different source of truth. Ideally, we'd // proxy/redirect pulls as well, when the secondary is not up-to-date. //