Fixes NoMethod / NoRoute handlers
This commit is contained in:
parent
48fec0650d
commit
aa9fad5ad8
13
gin.go
13
gin.go
@ -6,7 +6,6 @@ package gin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"math"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -15,7 +14,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AbortIndex = math.MaxInt8 / 2
|
|
||||||
MIMEJSON = "application/json"
|
MIMEJSON = "application/json"
|
||||||
MIMEHTML = "text/html"
|
MIMEHTML = "text/html"
|
||||||
MIMEXML = "application/xml"
|
MIMEXML = "application/xml"
|
||||||
@ -35,7 +33,8 @@ type (
|
|||||||
Default404Body []byte
|
Default404Body []byte
|
||||||
Default405Body []byte
|
Default405Body []byte
|
||||||
pool sync.Pool
|
pool sync.Pool
|
||||||
allNoRouteNoMethod []HandlerFunc
|
allNoRoute []HandlerFunc
|
||||||
|
allNoMethod []HandlerFunc
|
||||||
noRoute []HandlerFunc
|
noRoute []HandlerFunc
|
||||||
noMethod []HandlerFunc
|
noMethod []HandlerFunc
|
||||||
router *httprouter.Router
|
router *httprouter.Router
|
||||||
@ -115,15 +114,15 @@ func (engine *Engine) Use(middlewares ...HandlerFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) rebuild404Handlers() {
|
func (engine *Engine) rebuild404Handlers() {
|
||||||
engine.allNoRouteNoMethod = engine.combineHandlers(engine.noRoute)
|
engine.allNoRoute = engine.combineHandlers(engine.noRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) rebuild405Handlers() {
|
func (engine *Engine) rebuild405Handlers() {
|
||||||
engine.allNoRouteNoMethod = engine.combineHandlers(engine.noMethod)
|
engine.allNoMethod = engine.combineHandlers(engine.noMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) handle404(w http.ResponseWriter, req *http.Request) {
|
func (engine *Engine) handle404(w http.ResponseWriter, req *http.Request) {
|
||||||
c := engine.createContext(w, req, nil, engine.allNoRouteNoMethod)
|
c := engine.createContext(w, req, nil, engine.allNoRoute)
|
||||||
// set 404 by default, useful for logging
|
// set 404 by default, useful for logging
|
||||||
c.Writer.WriteHeader(404)
|
c.Writer.WriteHeader(404)
|
||||||
c.Next()
|
c.Next()
|
||||||
@ -138,7 +137,7 @@ func (engine *Engine) handle404(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) handle405(w http.ResponseWriter, req *http.Request) {
|
func (engine *Engine) handle405(w http.ResponseWriter, req *http.Request) {
|
||||||
c := engine.createContext(w, req, nil, engine.allNoRouteNoMethod)
|
c := engine.createContext(w, req, nil, engine.allNoMethod)
|
||||||
// set 405 by default, useful for logging
|
// set 405 by default, useful for logging
|
||||||
c.Writer.WriteHeader(405)
|
c.Writer.WriteHeader(405)
|
||||||
c.Next()
|
c.Next()
|
||||||
|
Loading…
Reference in New Issue
Block a user