mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
improve CORS feature for ghttp.Server
This commit is contained in:
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user