chore: only allow cors middleware to change headers (#1276)

This commit is contained in:
Kevin Wan
2021-11-26 14:14:06 +08:00
committed by GitHub
parent c800f6f723
commit 3dda557410
4 changed files with 12 additions and 9 deletions

View File

@@ -45,12 +45,12 @@ func NotAllowedHandler(fn func(w http.ResponseWriter), origins ...string) http.H
}
// Middleware returns a middleware that adds CORS headers to the response.
func Middleware(fn func(w http.ResponseWriter), origins ...string) func(http.HandlerFunc) http.HandlerFunc {
func Middleware(fn func(w http.Header), origins ...string) func(http.HandlerFunc) http.HandlerFunc {
return func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
checkAndSetHeaders(w, r, origins)
if fn != nil {
fn(w)
fn(w.Header())
}
if r.Method == http.MethodOptions {