mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-08 04:00:51 +08:00
Enable CORS for "OPTIONS" request
This commit is contained in:
@@ -36,7 +36,7 @@ func CorsFilter(ctx *context.Context) {
|
|||||||
if origin != "" && originConf != "" && origin != originConf {
|
if origin != "" && originConf != "" && origin != originConf {
|
||||||
if object.IsOriginAllowed(origin) {
|
if object.IsOriginAllowed(origin) {
|
||||||
ctx.Output.Header(headerAllowOrigin, origin)
|
ctx.Output.Header(headerAllowOrigin, origin)
|
||||||
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS")
|
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE")
|
||||||
ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")
|
ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")
|
||||||
} else {
|
} else {
|
||||||
ctx.ResponseWriter.WriteHeader(http.StatusForbidden)
|
ctx.ResponseWriter.WriteHeader(http.StatusForbidden)
|
||||||
@@ -48,4 +48,11 @@ func CorsFilter(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.Input.Method() == "OPTIONS" {
|
||||||
|
ctx.Output.Header(headerAllowOrigin, "*")
|
||||||
|
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE")
|
||||||
|
ctx.ResponseWriter.WriteHeader(http.StatusOK)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user