HTTP Header - CORS跨域设置增加多个选项

This commit is contained in:
GoEdgeLab
2023-05-19 16:34:41 +08:00
parent b9a1a0b484
commit 9f5bc87d0f

View File

@@ -1728,7 +1728,7 @@ func (this *HTTPRequest) processResponseHeaders(responseHeader http.Header, stat
} }
// CORS // CORS
if this.web.ResponseHeaderPolicy.CORS != nil && this.web.ResponseHeaderPolicy.CORS.IsOn { if this.web.ResponseHeaderPolicy.CORS != nil && this.web.ResponseHeaderPolicy.CORS.IsOn && (!this.web.ResponseHeaderPolicy.CORS.OptionsMethodOnly || this.RawReq.Method == http.MethodOptions) {
var corsConfig = this.web.ResponseHeaderPolicy.CORS var corsConfig = this.web.ResponseHeaderPolicy.CORS
// Allow-Origin // Allow-Origin
@@ -1753,6 +1753,16 @@ func (this *HTTPRequest) processResponseHeaders(responseHeader http.Header, stat
responseHeader.Set("Access-Control-Max-Age", types.String(corsConfig.MaxAge)) responseHeader.Set("Access-Control-Max-Age", types.String(corsConfig.MaxAge))
} }
// Expose-Headers
if len(corsConfig.ExposeHeaders) > 0 {
responseHeader.Set("Access-Control-Expose-Headers", strings.Join(corsConfig.ExposeHeaders, ", "))
}
// Request-Method
if len(corsConfig.RequestMethod) > 0 {
responseHeader.Set("Access-Control-Request-Method", strings.ToUpper(corsConfig.RequestMethod))
}
// Allow-Credentials // Allow-Credentials
responseHeader.Set("Access-Control-Allow-Credentials", "true") responseHeader.Set("Access-Control-Allow-Credentials", "true")
} }