1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 20:41:57 +00:00

Implement the Status Method Not Allowed for gorilla mux too and add some tests

Former-commit-id: b157bacfa15567b8c98f959f3359e025fdf1b205
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-02-21 14:20:31 +02:00
parent 6fca78d12a
commit b25d99870e
5 changed files with 164 additions and 10 deletions

View File

@@ -702,12 +702,17 @@ func (mux *serveMux) buildHandler(pool iris.ContextPool) http.Handler {
}
// https://github.com/kataras/iris/issues/469
if context.Framework().Config.FireMethodNotAllowed {
var methodAllowed string
for i := range mux.garden {
tree := mux.garden[i]
methodAllowed = tree.method // keep track of the allowed method of the last checked tree
if !mux.methodEqual(context.Method(), tree.method) {
continue
}
}
// RCF rfc2616 https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
// The response MUST include an Allow header containing a list of valid methods for the requested resource.
context.SetHeader("Allow", methodAllowed)
context.EmitError(iris.StatusMethodNotAllowed)
return
}