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

@@ -106,10 +106,11 @@ func WithCors(origin ...string) RunOption {
// WithCustomCors returns a func to enable CORS for given origin, or default to all origins (*),
// fn lets caller customizing the response.
func WithCustomCors(fn func(http.ResponseWriter), origin ...string) RunOption {
func WithCustomCors(middlewareFn func(header http.Header), notAllowedFn func(http.ResponseWriter),
origin ...string) RunOption {
return func(server *Server) {
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(fn, origin...))
server.Use(cors.Middleware(fn, origin...))
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(notAllowedFn, origin...))
server.Use(cors.Middleware(middlewareFn, origin...))
}
}