diff --git a/net/ghttp/ghttp_response_cors.go b/net/ghttp/ghttp_response_cors.go index 88042785c..1853239a7 100644 --- a/net/ghttp/ghttp_response_cors.go +++ b/net/ghttp/ghttp_response_cors.go @@ -8,6 +8,7 @@ package ghttp import ( + "net/http" "net/url" "github.com/gogf/gf/text/gstr" @@ -69,6 +70,13 @@ func (r *Response) CORS(options CORSOptions) { if options.AllowHeaders != "" { r.Header().Set("Access-Control-Allow-Headers", options.AllowHeaders) } + // No continue service handling if it's OPTIONS request. + if gstr.Equal(r.Request.Method, "OPTIONS") { + if r.Status == 0 { + r.Status = http.StatusOK + } + r.Request.ExitAll() + } } // CORSAllowed checks whether the current request origin is allowed cross-domain.