Fix behavior, add unit test

This commit is contained in:
Johny Michelson 2018-11-25 15:03:23 +01:00
parent 465ead47d0
commit b6f35cda64
2 changed files with 19 additions and 0 deletions

View File

@ -189,6 +189,10 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
return func(c *Context) {
if nolisting {
c.Writer.WriteHeader(http.StatusNotFound)
c.handlers = group.engine.allNoRoute
c.index = -1
return
}
fileServer.ServeHTTP(c.Writer, c.Request)
}

View File

@ -411,6 +411,21 @@ func TestRouterNotFound(t *testing.T) {
assert.Equal(t, http.StatusNotFound, w.Code)
}
func TestRouterStaticFSNotFound(t *testing.T) {
router := New()
router.StaticFS("/", http.FileSystem(http.Dir("/thisdoesntexist/")))
router.NoRoute(func(c *Context) {
c.String(404, "non existent")
})
w := performRequest(router, "GET", "nonexistent")
assert.Equal(t, "non existent", w.Body.String())
w = performRequest(router, "HEAD", "nonexistent")
assert.Equal(t, "non existent", w.Body.String())
}
func TestRouteRawPath(t *testing.T) {
route := New()
route.UseRawPath = true