diff --git a/net/ghttp/ghttp_response_cors.go b/net/ghttp/ghttp_response_cors.go index 59772f5526c..7a80fe64773 100644 --- a/net/ghttp/ghttp_response_cors.go +++ b/net/ghttp/ghttp_response_cors.go @@ -64,8 +64,8 @@ func (r *Response) DefaultCORSOptions() CORSOptions { if origin := r.Request.Header.Get("Origin"); origin != "" { options.AllowOrigin = origin } else if referer := r.Request.Referer(); referer != "" { - if p := gstr.PosR(referer, "/", 6); p != -1 { - options.AllowOrigin = referer[:p] + if ref, err := url.Parse(referer); err == nil { + options.AllowOrigin = ref.Scheme + "://" + ref.Host } else { options.AllowOrigin = referer }