mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
Merge branch 'master' into fc
This commit is contained in:
commit
1ad00d4ef8
@ -687,7 +687,7 @@ func TestUriBinding(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var not NotSupportStruct
|
var not NotSupportStruct
|
||||||
assert.Error(t, b.BindUri(m, ¬))
|
assert.Error(t, b.BindUri(m, ¬))
|
||||||
assert.Equal(t, "", not.Name)
|
assert.Equal(t, map[string]interface{}(nil), not.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFormBinding(t *testing.T, method, path, badPath, body, badBody string) {
|
func testFormBinding(t *testing.T, method, path, badPath, body, badBody string) {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ func TestPanicWithBrokenPipe(t *testing.T) {
|
|||||||
const expectCode = 204
|
const expectCode = 204
|
||||||
|
|
||||||
expectMsgs := map[syscall.Errno]string{
|
expectMsgs := map[syscall.Errno]string{
|
||||||
syscall.EPIPE: "Broken pipe",
|
syscall.EPIPE: "broken pipe",
|
||||||
syscall.ECONNRESET: "connection reset by peer",
|
syscall.ECONNRESET: "connection reset by peer",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ func TestPanicWithBrokenPipe(t *testing.T) {
|
|||||||
w := performRequest(router, "GET", "/recovery")
|
w := performRequest(router, "GET", "/recovery")
|
||||||
// TEST
|
// TEST
|
||||||
assert.Equal(t, expectCode, w.Code)
|
assert.Equal(t, expectCode, w.Code)
|
||||||
assert.Contains(t, buf.String(), expectMsg)
|
assert.Contains(t, strings.ToLower(buf.String()), expectMsg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,11 +185,19 @@ func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRou
|
|||||||
func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
|
func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
|
||||||
absolutePath := group.calculateAbsolutePath(relativePath)
|
absolutePath := group.calculateAbsolutePath(relativePath)
|
||||||
fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
|
fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
|
||||||
_, nolisting := fs.(*onlyfilesFS)
|
|
||||||
return func(c *Context) {
|
return func(c *Context) {
|
||||||
if nolisting {
|
file := c.Param("filepath")
|
||||||
|
|
||||||
|
// Check if file exists and/or if we have permission to access it
|
||||||
|
if _, err := fs.Open(file); err != nil {
|
||||||
c.Writer.WriteHeader(http.StatusNotFound)
|
c.Writer.WriteHeader(http.StatusNotFound)
|
||||||
|
c.handlers = group.engine.allNoRoute
|
||||||
|
// Reset index
|
||||||
|
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("/thisreallydoesntexist/")))
|
||||||
|
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
|
||||||
|
@ -1 +0,0 @@
|
|||||||
box: wercker/default
|
|
Loading…
x
Reference in New Issue
Block a user