mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix issue in cors
This commit is contained in:
@ -6,7 +6,7 @@ import "github.com/gogf/gf/frame/g"
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.SetIndexFolder(true)
|
||||
s.SetServerRoot("/Users/john/Temp")
|
||||
s.SetServerRoot("/Users/john/Downloads")
|
||||
s.AddSearchPath("/Users/john/Documents")
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
|
||||
2
go.mod
2
go.mod
@ -1,5 +1,7 @@
|
||||
module github.com/gogf/gf
|
||||
|
||||
go 1.10
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/clbanning/mxj v1.8.4
|
||||
|
||||
@ -83,8 +83,8 @@ func (r *Request) WebSocket() (*WebSocket, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获得指定名称的参数字符串(Router/GET/POST),同 GetRequestString
|
||||
// 这是常用方法的简化别名
|
||||
// Get是GetRequest方法的别名,用于获得指定名称的参数值,注意键值可能是字符串、数组、Map类型。
|
||||
// 大多数场景下,你可能需要的是 GetString/GetVar。
|
||||
func (r *Request) Get(key string, def ...interface{}) interface{} {
|
||||
return r.GetRequest(key, def...)
|
||||
}
|
||||
|
||||
@ -23,7 +23,9 @@ func (r *Request) initRaw() {
|
||||
}
|
||||
}
|
||||
|
||||
// 获得router、post或者get提交的参数,如果有同名参数,那么按照router->get->post优先级进行覆盖
|
||||
// 获得router、post或者get提交的参数值,如果有同名参数,
|
||||
// 那么按照 router->get->post->OtherHttpMethod 优先级进行覆盖。
|
||||
// 注意获得参数值可能是字符串、数组、Map三种类型。
|
||||
func (r *Request) GetRequest(key string, def ...interface{}) interface{} {
|
||||
v := r.GetRouterValue(key)
|
||||
if v == nil {
|
||||
|
||||
@ -32,10 +32,10 @@ func (r *Response) DefaultCORSOptions() CORSOptions {
|
||||
AllowOrigin: "*",
|
||||
AllowMethods: HTTP_METHODS,
|
||||
AllowCredentials: "true",
|
||||
AllowHeaders: "Origin, X-Requested-With, Content-Type, Accept, Key",
|
||||
AllowHeaders: "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With",
|
||||
MaxAge: 3628800,
|
||||
}
|
||||
if origin := r.Header().Get("Origin"); origin != "" {
|
||||
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 {
|
||||
|
||||
@ -261,7 +261,6 @@ func (s *Server) serveFile(r *Request, f *staticServeFile, allowIndex ...bool) {
|
||||
r.Response.WriteStatus(http.StatusForbidden)
|
||||
}
|
||||
} else {
|
||||
// 读取文件内容返回, no buffer
|
||||
http.ServeContent(r.Response.Writer, r.Request, info.Name(), info.ModTime(), file)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user