1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-12 01:22:21 +02:00

Support for 405 - method not allowed, closes #205

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-11-03 16:26:20 -08:00
parent e619a97607
commit cddd4a6676
4 changed files with 12 additions and 57 deletions

View File

@ -383,14 +383,14 @@ func TestEchoNotFound(t *testing.T) {
}
func TestEchoMethodNotAllowed(t *testing.T) {
// e := New()
// e.Get("/", func(c *Context) error {
// return c.String(http.StatusOK, "Echo!")
// })
// r, _ := http.NewRequest(POST, "/", nil)
// w := httptest.NewRecorder()
// e.ServeHTTP(w, r)
// assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
e := New()
e.Get("/", func(c *Context) error {
return c.String(http.StatusOK, "Echo!")
})
r, _ := http.NewRequest(POST, "/", nil)
w := httptest.NewRecorder()
e.ServeHTTP(w, r)
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
}
func TestEchoHTTPError(t *testing.T) {

View File

@ -374,14 +374,16 @@ End:
e = cn.echo
}
if h == nil {
h = methodNotAllowedHandler
// Dig further for match-any, might have an empty value for *, e.g.
// serving a directory. Issue #207.
if cn = cn.findChildByKind(mkind); cn == nil {
h = notFoundHandler
return
}
h = cn.findHandler(method)
ctx.pvalues[len(cn.pnames)-1] = ""
if h = cn.findHandler(method); h == nil {
h = methodNotAllowedHandler
}
}
return
}

View File

@ -1,29 +0,0 @@
{
"apiVersion": "v1",
"kind": "ReplicationController",
"metadata": {
"name": "echo"
},
"spec": {
"replicas": 2,
"selector": {
"name": "echo"
},
"template": {
"metadata": {
"labels": {
"name": "echo"
}
},
"spec": {
"containers": [{
"image": "gcr.io/fluent-anagram-95603/echo",
"name": "echo",
"ports": [{
"containerPort": 5091
}]
}]
}
}
}
}

View File

@ -1,18 +0,0 @@
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "echo",
"labels": {
"name": "echo"
}
},
"spec": {
"ports": [{
"port": 5091
}],
"selector": {
"name": "echo"
}
}
}