feat: support rest.WithCorsHeaders to customize cors headers (#4284)

This commit is contained in:
Kevin Wan
2024-07-30 17:29:44 +08:00
committed by GitHub
parent c2421beb25
commit 2588a36555
4 changed files with 144 additions and 0 deletions

View File

@@ -26,6 +26,11 @@ const (
originHeader = "Origin"
)
// AddAllowHeaders sets the allowed headers.
func AddAllowHeaders(header http.Header, headers ...string) {
header.Add(allowHeaders, strings.Join(headers, ", "))
}
// NotAllowedHandler handles cross domain not allowed requests.
// At most one origin can be specified, other origins are ignored if given, default to be *.
func NotAllowedHandler(fn func(w http.ResponseWriter), origins ...string) http.Handler {