Set OPTIONS status in setCorsHeaders()

This commit is contained in:
Yang Luo 2023-09-30 01:13:29 +08:00
parent 7e0bce2d0f
commit de6cd380eb

View File

@ -35,6 +35,10 @@ func setCorsHeaders(ctx *context.Context, origin string) {
ctx.Output.Header(headerAllowOrigin, origin) ctx.Output.Header(headerAllowOrigin, origin)
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE") ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE")
ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization") ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")
if ctx.Input.Method() == "OPTIONS" {
ctx.ResponseWriter.WriteHeader(http.StatusOK)
}
} }
func getHostname(s string) string { func getHostname(s string) string {
@ -89,11 +93,6 @@ func CorsFilter(ctx *context.Context) {
ctx.ResponseWriter.WriteHeader(http.StatusForbidden) ctx.ResponseWriter.WriteHeader(http.StatusForbidden)
return return
} }
if ctx.Input.Method() == "OPTIONS" {
ctx.ResponseWriter.WriteHeader(http.StatusOK)
return
}
} }
} }