@@ -578,12 +578,18 @@ func testRouterNotFoundByMethod(t *testing.T, method string) {
578
578
router .Handle (method , "/USERS/{name}/enTRies/" , handlerFunc )
579
579
router .Handle (method , "/static/{filepath:*}" , handlerFunc )
580
580
581
+ reqMethod := method
582
+ if method == MethodWild {
583
+ reqMethod = randomHTTPMethod ()
584
+ }
585
+
581
586
// Moved Permanently, request with GET method
582
587
expectedCode := fasthttp .StatusMovedPermanently
583
- if method == fasthttp .MethodConnect {
588
+ switch {
589
+ case reqMethod == fasthttp .MethodConnect :
584
590
// CONNECT method does not allow redirects, so Not Found (404)
585
591
expectedCode = fasthttp .StatusNotFound
586
- } else if method != fasthttp .MethodGet {
592
+ case reqMethod != fasthttp .MethodGet :
587
593
// Permanent Redirect, request with same method
588
594
expectedCode = fasthttp .StatusPermanentRedirect
589
595
}
@@ -616,30 +622,29 @@ func testRouterNotFoundByMethod(t *testing.T, method string) {
616
622
}... )
617
623
}
618
624
619
- reqMethod := method
620
- if method == MethodWild {
621
- reqMethod = randomHTTPMethod ()
622
- }
623
-
624
625
for _ , tr := range testRoutes {
625
- if runtime .GOOS == "windows" && strings .HasPrefix (tr .route , "/../" ) {
626
- // See: https://github.com/valyala/fasthttp/issues/1226
627
- t .Logf ("skipping route '%s %s' on %s, unsupported yet" , reqMethod , tr .route , runtime .GOOS )
628
-
629
- continue
630
- }
631
-
632
626
ctx := new (fasthttp.RequestCtx )
633
-
634
627
ctx .Request .Header .SetMethod (reqMethod )
635
628
ctx .Request .SetRequestURI (tr .route )
636
629
ctx .Request .SetHost (host )
630
+
637
631
router .Handler (ctx )
638
632
639
633
statusCode := ctx .Response .StatusCode ()
640
634
location := string (ctx .Response .Header .Peek ("Location" ))
635
+
641
636
if ! (statusCode == tr .code && (statusCode == fasthttp .StatusNotFound || location == tr .location )) {
642
- t .Errorf ("NotFound handling route %s failed: ReqMethod=%s, Code=%d, Header=%v" , method , tr .route , statusCode , location )
637
+ fn := t .Errorf
638
+ msg := "NotFound handling route '%s' failed: Method=%s, ReqMethod=%s, Code=%d, ExpectedCode=%d, Header=%v"
639
+
640
+ if runtime .GOOS == "windows" && strings .HasPrefix (tr .route , "/../" ) {
641
+ // See: https://github.com/valyala/fasthttp/issues/1226
642
+ // Not fail, because it is a known issue.
643
+ fn = t .Logf
644
+ msg = "ERROR: " + msg
645
+ }
646
+
647
+ fn (msg , tr .route , method , reqMethod , statusCode , tr .code , location )
643
648
}
644
649
}
645
650
@@ -655,9 +660,14 @@ func testRouterNotFoundByMethod(t *testing.T, method string) {
655
660
ctx .Request .Header .SetMethod (reqMethod )
656
661
ctx .Request .SetRequestURI ("/nope" )
657
662
router .Handler (ctx )
663
+
658
664
if ! (ctx .Response .StatusCode () == fasthttp .StatusNotFound && notFound == true ) {
659
- t .Errorf ("Custom NotFound handler failed: Code=%d, Header=%v" , ctx .Response .StatusCode (), ctx .Response .Header .String ())
665
+ t .Errorf (
666
+ "Custom NotFound handling failed: Method=%s, ReqMethod=%s, Code=%d, Header=%v" ,
667
+ method , reqMethod , ctx .Response .StatusCode (), ctx .Response .Header .String (),
668
+ )
660
669
}
670
+
661
671
ctx .Response .Reset ()
662
672
}
663
673
0 commit comments