serve: support custom http response headers

Co-authored-by: Tim Schumacher <tim@tschumacher.net>
This commit is contained in:
kkocdko
2026-05-06 12:41:15 +01:00
committed by GitHub
co-authored by Tim Schumacher
parent 03b06ac459
commit d86b72c405
5 changed files with 121 additions and 21 deletions
+12
View File
@@ -199,6 +199,18 @@ func MiddlewareCORS(allowOrigin string) Middleware {
}
}
// MiddlewareResponseHeaders instantiates middleware that apply custom headers to every response
func MiddlewareResponseHeaders(headers []*fs.HTTPOption) Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
for _, header := range headers {
w.Header().Set(header.Key, header.Value)
}
next.ServeHTTP(w, r)
})
}
}
// MiddlewareStripPrefix instantiates middleware that removes the BaseURL from the path
func MiddlewareStripPrefix(prefix string) Middleware {
return func(next http.Handler) http.Handler {