From 78066da20883afd755ed23d825af4480d164504d Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sat, 13 Jan 2024 23:46:05 +0800 Subject: [PATCH] Improve setCorsHeaders() for "include" mode --- routers/cors_filter.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/routers/cors_filter.go b/routers/cors_filter.go index aef3b862..ab0d073b 100644 --- a/routers/cors_filter.go +++ b/routers/cors_filter.go @@ -24,16 +24,18 @@ import ( ) const ( - headerOrigin = "Origin" - headerAllowOrigin = "Access-Control-Allow-Origin" - headerAllowMethods = "Access-Control-Allow-Methods" - headerAllowHeaders = "Access-Control-Allow-Headers" + headerOrigin = "Origin" + headerAllowOrigin = "Access-Control-Allow-Origin" + headerAllowMethods = "Access-Control-Allow-Methods" + headerAllowHeaders = "Access-Control-Allow-Headers" + headerAllowCredentials = "Access-Control-Allow-Credentials" ) 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") + ctx.Output.Header(headerAllowCredentials, "true") if ctx.Input.Method() == "OPTIONS" { ctx.ResponseWriter.WriteHeader(http.StatusOK)