404 not found performance improvements
benchmark old ns/op new ns/op delta Benchmark404 737 249 -66.21% Benchmark404Many 2330 454 -80.52% benchmark old allocs new allocs delta Benchmark404 3 0 -100.00% Benchmark404Many 10 0 -100.00% benchmark old bytes new bytes delta Benchmark404 115 68 -40.87% Benchmark404Many 235 57 -75.74%
This commit is contained in:
+19
-2
@@ -61,6 +61,7 @@ func testRouteNotOK(method string, t *testing.T) {
|
||||
func testRouteNotOK2(method string, t *testing.T) {
|
||||
passed := false
|
||||
router := New()
|
||||
router.HandleMethodNotAllowed = true
|
||||
var methodRoute string
|
||||
if method == "POST" {
|
||||
methodRoute = "GET"
|
||||
@@ -224,9 +225,9 @@ func TestRouterMiddlewareAndStatic(t *testing.T) {
|
||||
assert.Equal(t, w.HeaderMap.Get("x-GIN"), "Gin Framework")
|
||||
}
|
||||
|
||||
func TestRouteNotAllowed(t *testing.T) {
|
||||
func TestRouteNotAllowedEnabled(t *testing.T) {
|
||||
router := New()
|
||||
|
||||
router.HandleMethodNotAllowed = true
|
||||
router.POST("/path", func(c *Context) {})
|
||||
w := performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Code, http.StatusMethodNotAllowed)
|
||||
@@ -239,8 +240,24 @@ func TestRouteNotAllowed(t *testing.T) {
|
||||
assert.Equal(t, w.Code, http.StatusTeapot)
|
||||
}
|
||||
|
||||
func TestRouteNotAllowedDisabled(t *testing.T) {
|
||||
router := New()
|
||||
router.HandleMethodNotAllowed = false
|
||||
router.POST("/path", func(c *Context) {})
|
||||
w := performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
|
||||
router.NoMethod(func(c *Context) {
|
||||
c.String(http.StatusTeapot, "responseText")
|
||||
})
|
||||
w = performRequest(router, "GET", "/path")
|
||||
assert.Equal(t, w.Body.String(), "404 page not found")
|
||||
assert.Equal(t, w.Code, 404)
|
||||
}
|
||||
|
||||
func TestRouterNotFound(t *testing.T) {
|
||||
router := New()
|
||||
router.RedirectFixedPath = true
|
||||
router.GET("/path", func(c *Context) {})
|
||||
router.GET("/dir/", func(c *Context) {})
|
||||
router.GET("/", func(c *Context) {})
|
||||
|
||||
Reference in New Issue
Block a user