From de6cd380ebb8e7e0c84efdb7718ac71f4a478da3 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sat, 30 Sep 2023 01:13:29 +0800 Subject: [PATCH] Set OPTIONS status in setCorsHeaders() --- routers/cors_filter.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/routers/cors_filter.go b/routers/cors_filter.go index 408172e8..1d54563a 100644 --- a/routers/cors_filter.go +++ b/routers/cors_filter.go @@ -35,6 +35,10 @@ func setCorsHeaders(ctx *context.Context, origin string) { ctx.Output.Header(headerAllowOrigin, origin) ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE") ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization") + + if ctx.Input.Method() == "OPTIONS" { + ctx.ResponseWriter.WriteHeader(http.StatusOK) + } } func getHostname(s string) string { @@ -89,11 +93,6 @@ func CorsFilter(ctx *context.Context) { ctx.ResponseWriter.WriteHeader(http.StatusForbidden) return } - - if ctx.Input.Method() == "OPTIONS" { - ctx.ResponseWriter.WriteHeader(http.StatusOK) - return - } } }