From 42d4018b8b027c341c45638f313b286f832d49e1 Mon Sep 17 00:00:00 2001 From: Justin Hammond Date: Sat, 20 Aug 2022 00:12:13 +0800 Subject: [PATCH] add AddAllowedHeaders function to whitelist common headers --- context.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/context.go b/context.go index 6280662..938f18c 100644 --- a/context.go +++ b/context.go @@ -28,6 +28,16 @@ var allowedHeaders = map[string]bool{ "vary": true, } +// AddAllowedHeader adds a header to the list of allowed headers for the response. +// This is useful for common headers that might be sent due to middleware +// or other frameworks +func AddAllowedHeaders(name ...string) { + for _, h := range name { + allowedHeaders[strings.ToLower(h)] = true + } +} + + // ContextFromRequest returns a Huma context for a request, useful for // accessing high-level convenience functions from e.g. middleware. func ContextFromRequest(w http.ResponseWriter, r *http.Request) Context {