mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
Merge 5718cec52ae59c69c2377721df10687b0848a80c into fbdcbd22751c7174d4f363995fca296e4670726b
This commit is contained in:
commit
84123e9425
15
gin.go
15
gin.go
@ -104,6 +104,11 @@ type Engine struct {
|
||||
noMethod HandlersChain
|
||||
pool sync.Pool
|
||||
trees methodTrees
|
||||
|
||||
// If defiend, invoke before `handleHTTPRequest`
|
||||
// Change `httpMethod`, `path`, `rawPath` for complex route match,it will not change origin `Context.Request`
|
||||
// Note: If necessary, DON'T MODIFIY `Context`
|
||||
BeforeHandle func(c *Context, httpMethod, path, rawPath *string)
|
||||
}
|
||||
|
||||
var _ IRouter = &Engine{}
|
||||
@ -341,9 +346,15 @@ func (engine *Engine) HandleContext(c *Context) {
|
||||
func (engine *Engine) handleHTTPRequest(c *Context) {
|
||||
httpMethod := c.Request.Method
|
||||
path := c.Request.URL.Path
|
||||
rawPath := c.Request.URL.RawPath
|
||||
if engine.BeforeHandle != nil {
|
||||
engine.BeforeHandle(c, &httpMethod, &path, &rawPath)
|
||||
}
|
||||
|
||||
unescape := false
|
||||
if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 {
|
||||
path = c.Request.URL.RawPath
|
||||
|
||||
if engine.UseRawPath && len(rawPath) > 0 {
|
||||
path = rawPath
|
||||
unescape = engine.UnescapePathValues
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user