mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
Fix behavior, add unit test
This commit is contained in:
parent
465ead47d0
commit
b6f35cda64
@ -189,6 +189,10 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
|
|||||||
return func(c *Context) {
|
return func(c *Context) {
|
||||||
if nolisting {
|
if nolisting {
|
||||||
c.Writer.WriteHeader(http.StatusNotFound)
|
c.Writer.WriteHeader(http.StatusNotFound)
|
||||||
|
|
||||||
|
c.handlers = group.engine.allNoRoute
|
||||||
|
c.index = -1
|
||||||
|
return
|
||||||
}
|
}
|
||||||
fileServer.ServeHTTP(c.Writer, c.Request)
|
fileServer.ServeHTTP(c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
|
@ -411,6 +411,21 @@ func TestRouterNotFound(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
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) {
|
func TestRouteRawPath(t *testing.T) {
|
||||||
route := New()
|
route := New()
|
||||||
route.UseRawPath = true
|
route.UseRawPath = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user