Merge branch 'master' into mapping_array

This commit is contained in:
田欧 2019-03-14 10:09:31 +08:00 committed by GitHub
commit ddd1a9a9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 3 deletions

View File

@ -13,7 +13,7 @@
Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin. Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin.
![Gin console logger](https://gin-gonic.github.io/gin/other/console.png) ![Gin console logger](testdata/assets/console.png)
## Contents ## Contents

View File

@ -195,7 +195,7 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
// Check if file exists and/or if we have permission to access it // Check if file exists and/or if we have permission to access it
if _, err := fs.Open(file); err != nil { if _, err := fs.Open(file); err != nil {
c.Writer.WriteHeader(http.StatusNotFound) c.Writer.WriteHeader(http.StatusNotFound)
c.handlers = group.engine.allNoRoute c.handlers = group.engine.noRoute
// Reset index // Reset index
c.index = -1 c.index = -1
return return

View File

@ -429,7 +429,6 @@ func TestRouterNotFound(t *testing.T) {
func TestRouterStaticFSNotFound(t *testing.T) { func TestRouterStaticFSNotFound(t *testing.T) {
router := New() router := New()
router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/"))) router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/")))
router.NoRoute(func(c *Context) { router.NoRoute(func(c *Context) {
c.String(404, "non existent") c.String(404, "non existent")
@ -452,6 +451,27 @@ func TestRouterStaticFSFileNotFound(t *testing.T) {
}) })
} }
// Reproduction test for the bug of issue #1805
func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) {
router := New()
// Middleware must be called just only once by per request.
middlewareCalledNum := 0
router.Use(func(c *Context) {
middlewareCalledNum += 1
})
router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/")))
// First access
performRequest(router, "GET", "/nonexistent")
assert.Equal(t, 1, middlewareCalledNum)
// Second access
performRequest(router, "HEAD", "/nonexistent")
assert.Equal(t, 2, middlewareCalledNum)
}
func TestRouteRawPath(t *testing.T) { func TestRouteRawPath(t *testing.T) {
route := New() route := New()
route.UseRawPath = true route.UseRawPath = true

BIN
testdata/assets/console.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB