Merge 5718cec52ae59c69c2377721df10687b0848a80c into fbdcbd22751c7174d4f363995fca296e4670726b

This commit is contained in:
RedDragonet 2018-10-10 07:32:33 +00:00 committed by GitHub
commit 84123e9425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

15
gin.go
View File

@ -104,6 +104,11 @@ type Engine struct {
noMethod HandlersChain noMethod HandlersChain
pool sync.Pool pool sync.Pool
trees methodTrees 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{} var _ IRouter = &Engine{}
@ -341,9 +346,15 @@ func (engine *Engine) HandleContext(c *Context) {
func (engine *Engine) handleHTTPRequest(c *Context) { func (engine *Engine) handleHTTPRequest(c *Context) {
httpMethod := c.Request.Method httpMethod := c.Request.Method
path := c.Request.URL.Path path := c.Request.URL.Path
rawPath := c.Request.URL.RawPath
if engine.BeforeHandle != nil {
engine.BeforeHandle(c, &httpMethod, &path, &rawPath)
}
unescape := false 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 unescape = engine.UnescapePathValues
} }