diff --git a/router.go b/router.go index af9b4aea..5587f665 100644 --- a/router.go +++ b/router.go @@ -307,8 +307,9 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) { h, _ := r.Find(req.Method, req.URL.Path, c) c.reset(req, w, r.echo) if h == nil { - h = r.echo.notFoundHandler + c.Error(NewHTTPError(http.StatusNotFound)) + } else { + h(c) } - h(c) r.echo.pool.Put(c) } diff --git a/router_test.go b/router_test.go index 153baf7b..69bdd2bd 100644 --- a/router_test.go +++ b/router_test.go @@ -531,11 +531,13 @@ func TestRouterServeHTTP(t *testing.T) { req, _ := http.NewRequest(GET, "/users", nil) w := httptest.NewRecorder() r.ServeHTTP(w, req) + assert.Equal(t, http.StatusOK, w.Code) // Not found req, _ = http.NewRequest(GET, "/files", nil) w = httptest.NewRecorder() r.ServeHTTP(w, req) + assert.Equal(t, http.StatusNotFound, w.Code) } func (n *node) printTree(pfx string, tail bool) {