File tree Expand file tree Collapse file tree 3 files changed +54
-21
lines changed Expand file tree Collapse file tree 3 files changed +54
-21
lines changed Original file line number Diff line number Diff line change @@ -603,28 +603,30 @@ const noCacheValue = "no-cache"
603
603
604
604
// isNoCache checks if the cacheControl header value is a `no-cache`.
605
605
func isNoCache (cacheControl string ) bool {
606
- i := strings .Index (cacheControl , noCacheValue )
607
- if i == - 1 {
608
- return false
609
- }
610
-
611
- // Xno-cache
612
- if i > 0 && ! (cacheControl [i - 1 ] == ' ' || cacheControl [i - 1 ] == ',' ) {
613
- return false
614
- }
615
-
616
- // bla bla, no-cache
617
- if i + len (noCacheValue ) == len (cacheControl ) {
618
- return true
619
- }
620
-
621
- // bla bla, no-cacheX
622
- if cacheControl [i + len (noCacheValue )] != ',' {
623
- return false
606
+ n := len (cacheControl )
607
+ ncLen := len (noCacheValue )
608
+ for i := 0 ; i < n ; i ++ {
609
+ if cacheControl [i ] != 'n' {
610
+ continue
611
+ }
612
+ if i + ncLen > n {
613
+ return false
614
+ }
615
+ if cacheControl [i :i + ncLen ] != noCacheValue {
616
+ continue
617
+ }
618
+ if i > 0 {
619
+ prev := cacheControl [i - 1 ]
620
+ if prev != ' ' && prev != ',' {
621
+ continue
622
+ }
623
+ }
624
+ if i + ncLen == n || cacheControl [i + ncLen ] == ',' {
625
+ return true
626
+ }
624
627
}
625
628
626
- // OK
627
- return true
629
+ return false
628
630
}
629
631
630
632
var errTestConnClosed = errors .New ("testConn is closed" )
Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ func HTTPHandlerFunc(h http.HandlerFunc) fiber.Handler {
32
32
33
33
// HTTPHandler wraps net/http handler to fiber handler
34
34
func HTTPHandler (h http.Handler ) fiber.Handler {
35
+ handler := fasthttpadaptor .NewFastHTTPHandler (h )
35
36
return func (c fiber.Ctx ) error {
36
- handler := fasthttpadaptor .NewFastHTTPHandler (h )
37
37
handler (c .RequestCtx ())
38
38
return nil
39
39
}
Original file line number Diff line number Diff line change @@ -634,3 +634,34 @@ func Benchmark_FiberHandlerFunc_Parallel(b *testing.B) {
634
634
})
635
635
}
636
636
}
637
+
638
+ func Benchmark_HTTPHandler (b * testing.B ) {
639
+ handler := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
640
+ w .WriteHeader (http .StatusOK )
641
+ w .Write ([]byte ("ok" )) //nolint:errcheck // not needed
642
+ })
643
+
644
+ var err error
645
+ app := fiber .New ()
646
+
647
+ ctx := app .AcquireCtx (& fasthttp.RequestCtx {})
648
+ defer func () {
649
+ app .ReleaseCtx (ctx )
650
+ }()
651
+
652
+ b .ReportAllocs ()
653
+ b .ResetTimer ()
654
+
655
+ fiberHandler := HTTPHandler (handler )
656
+
657
+ for i := 0 ; i < b .N ; i ++ {
658
+ ctx .Request ().Reset ()
659
+ ctx .Response ().Reset ()
660
+ ctx .Request ().SetRequestURI ("/test" )
661
+ ctx .Request ().Header .SetMethod ("GET" )
662
+
663
+ err = fiberHandler (ctx )
664
+ }
665
+
666
+ require .NoError (b , err )
667
+ }
You can’t perform that action at this time.
0 commit comments