mirror of
https://github.com/gogf/gf.git
synced 2025-04-05 11:18:50 +08:00
parent
93964ee231
commit
acf2307eb9
@ -33,18 +33,6 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if s.config.ClientMaxBodySize > 0 {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, s.config.ClientMaxBodySize)
|
||||
}
|
||||
// In case of, eg:
|
||||
// Case 1:
|
||||
// GET /net/http
|
||||
// r.URL.Path : /net/http
|
||||
// r.URL.RawPath : (empty string)
|
||||
// Case 2:
|
||||
// GET /net%2Fhttp
|
||||
// r.URL.Path : /net/http
|
||||
// r.URL.RawPath : /net%2Fhttp
|
||||
if r.URL.RawPath != "" {
|
||||
r.URL.Path = r.URL.RawPath
|
||||
}
|
||||
// Rewrite feature checks.
|
||||
if len(s.config.Rewrites) > 0 {
|
||||
if rewrite, ok := s.config.Rewrites[r.URL.Path]; ok {
|
||||
@ -111,7 +99,10 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Search the dynamic service handler.
|
||||
request.handlers, request.serveHandler, request.hasHookHandler, request.hasServeHandler = s.getHandlersWithCache(request)
|
||||
request.handlers,
|
||||
request.serveHandler,
|
||||
request.hasHookHandler,
|
||||
request.hasServeHandler = s.getHandlersWithCache(request)
|
||||
|
||||
// Check the service type static or dynamic for current request.
|
||||
if request.StaticFile != nil && request.StaticFile.IsDir && request.hasServeHandler {
|
||||
|
@ -47,6 +47,18 @@ func (s *Server) getHandlersWithCache(r *Request) (parsedItems []*HandlerItemPar
|
||||
path = r.URL.Path
|
||||
host = r.GetHost()
|
||||
)
|
||||
// In case of, eg:
|
||||
// Case 1:
|
||||
// GET /net/http
|
||||
// r.URL.Path : /net/http
|
||||
// r.URL.RawPath : (empty string)
|
||||
// Case 2:
|
||||
// GET /net%2Fhttp
|
||||
// r.URL.Path : /net/http
|
||||
// r.URL.RawPath : /net%2Fhttp
|
||||
if r.URL.RawPath != "" {
|
||||
path = r.URL.RawPath
|
||||
}
|
||||
// Special http method OPTIONS handling.
|
||||
// It searches the handler with the request method instead of OPTIONS method.
|
||||
if method == http.MethodOptions {
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/encoding/gurl"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
@ -420,3 +421,21 @@ func Test_Issue2890(t *testing.T) {
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2963
|
||||
func Test_Issue2963(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
s := g.Server(guid.S())
|
||||
s.SetServerRoot(gtest.DataPath("issue2963"))
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
|
||||
t.Assert(c.GetContent(ctx, "/1.txt"), `1`)
|
||||
t.Assert(c.GetContent(ctx, "/中文G146(1)-icon.txt"), `中文G146(1)-icon`)
|
||||
t.Assert(c.GetContent(ctx, "/"+gurl.Encode("中文G146(1)-icon.txt")), `中文G146(1)-icon`)
|
||||
})
|
||||
}
|
||||
|
1
net/ghttp/testdata/issue2963/1.txt
vendored
Normal file
1
net/ghttp/testdata/issue2963/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
1
|
1
net/ghttp/testdata/issue2963/中文G146(1)-icon.txt
vendored
Normal file
1
net/ghttp/testdata/issue2963/中文G146(1)-icon.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
中文G146(1)-icon
|
Loading…
x
Reference in New Issue
Block a user