|
@@ -225,7 +225,7 @@ func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
|
|
|
engine.rebuild405Handlers()
|
|
engine.rebuild405Handlers()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Use attachs a global middleware to the router. ie. the middleware attached though Use() will be
|
|
|
|
|
|
|
+// Use attaches a global middleware to the router. ie. the middleware attached though Use() will be
|
|
|
// included in the handlers chain for every single request. Even 404, 405, static files...
|
|
// included in the handlers chain for every single request. Even 404, 405, static files...
|
|
|
// For example, this is the right place for a logger or error management middleware.
|
|
// For example, this is the right place for a logger or error management middleware.
|
|
|
func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes {
|
|
func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes {
|
|
@@ -366,10 +366,10 @@ 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
|
|
|
|
|
|
|
+ rPath := c.Request.URL.Path
|
|
|
unescape := false
|
|
unescape := false
|
|
|
if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 {
|
|
if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 {
|
|
|
- path = c.Request.URL.RawPath
|
|
|
|
|
|
|
+ rPath = c.Request.URL.RawPath
|
|
|
unescape = engine.UnescapePathValues
|
|
unescape = engine.UnescapePathValues
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -381,7 +381,7 @@ func (engine *Engine) handleHTTPRequest(c *Context) {
|
|
|
}
|
|
}
|
|
|
root := t[i].root
|
|
root := t[i].root
|
|
|
// Find route in tree
|
|
// Find route in tree
|
|
|
- handlers, params, tsr := root.getValue(path, c.Params, unescape)
|
|
|
|
|
|
|
+ handlers, params, tsr := root.getValue(rPath, c.Params, unescape)
|
|
|
if handlers != nil {
|
|
if handlers != nil {
|
|
|
c.handlers = handlers
|
|
c.handlers = handlers
|
|
|
c.Params = params
|
|
c.Params = params
|
|
@@ -389,7 +389,7 @@ func (engine *Engine) handleHTTPRequest(c *Context) {
|
|
|
c.writermem.WriteHeaderNow()
|
|
c.writermem.WriteHeaderNow()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if httpMethod != "CONNECT" && path != "/" {
|
|
|
|
|
|
|
+ if httpMethod != "CONNECT" && rPath != "/" {
|
|
|
if tsr && engine.RedirectTrailingSlash {
|
|
if tsr && engine.RedirectTrailingSlash {
|
|
|
redirectTrailingSlash(c)
|
|
redirectTrailingSlash(c)
|
|
|
return
|
|
return
|
|
@@ -406,7 +406,7 @@ func (engine *Engine) handleHTTPRequest(c *Context) {
|
|
|
if tree.method == httpMethod {
|
|
if tree.method == httpMethod {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
- if handlers, _, _ := tree.root.getValue(path, nil, unescape); handlers != nil {
|
|
|
|
|
|
|
+ if handlers, _, _ := tree.root.getValue(rPath, nil, unescape); handlers != nil {
|
|
|
c.handlers = engine.allNoMethod
|
|
c.handlers = engine.allNoMethod
|
|
|
serveError(c, http.StatusMethodNotAllowed, default405Body)
|
|
serveError(c, http.StatusMethodNotAllowed, default405Body)
|
|
|
return
|
|
return
|
|
@@ -459,15 +459,15 @@ func redirectTrailingSlash(c *Context) {
|
|
|
|
|
|
|
|
func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
|
|
func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
|
|
|
req := c.Request
|
|
req := c.Request
|
|
|
- path := req.URL.Path
|
|
|
|
|
|
|
+ rPath := req.URL.Path
|
|
|
|
|
|
|
|
- if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(path), trailingSlash); ok {
|
|
|
|
|
|
|
+ if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(rPath), trailingSlash); ok {
|
|
|
code := http.StatusMovedPermanently // Permanent redirect, request with GET method
|
|
code := http.StatusMovedPermanently // Permanent redirect, request with GET method
|
|
|
if req.Method != "GET" {
|
|
if req.Method != "GET" {
|
|
|
code = http.StatusTemporaryRedirect
|
|
code = http.StatusTemporaryRedirect
|
|
|
}
|
|
}
|
|
|
req.URL.Path = string(fixedPath)
|
|
req.URL.Path = string(fixedPath)
|
|
|
- debugPrint("redirecting request %d: %s --> %s", code, path, req.URL.String())
|
|
|
|
|
|
|
+ debugPrint("redirecting request %d: %s --> %s", code, rPath, req.URL.String())
|
|
|
http.Redirect(c.Writer, req, req.URL.String(), code)
|
|
http.Redirect(c.Writer, req, req.URL.String(), code)
|
|
|
c.writermem.WriteHeaderNow()
|
|
c.writermem.WriteHeaderNow()
|
|
|
return true
|
|
return true
|