mirror of https://github.com/gofiber/fiber.git
🩹 Fix: behavior of `DefaultCtx.Fresh` when 'Last-Modified' and 'If-Modified-Since' are equal (#3150)
* fix(ctx): 'if-modified-since' and 'last-modified' are equal, `DefaultCtx.Fresh` now returns true * accurate benchmark measurementspull/3151/head^2
parent
0c1f5ffde8
commit
44cd700ad5
2
ctx.go
2
ctx.go
|
@ -624,7 +624,7 @@ func (c *DefaultCtx) Fresh() bool {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return lastModifiedTime.Before(modifiedSinceTime)
|
return lastModifiedTime.Compare(modifiedSinceTime) != 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
ctx_test.go
16
ctx_test.go
|
@ -1397,6 +1397,10 @@ func Test_Ctx_Fresh(t *testing.T) {
|
||||||
require.False(t, c.Fresh())
|
require.False(t, c.Fresh())
|
||||||
|
|
||||||
c.Request().Header.Set(HeaderIfModifiedSince, "Wed, 21 Oct 2015 07:28:00 GMT")
|
c.Request().Header.Set(HeaderIfModifiedSince, "Wed, 21 Oct 2015 07:28:00 GMT")
|
||||||
|
require.True(t, c.Fresh())
|
||||||
|
|
||||||
|
c.Request().Header.Set(HeaderIfModifiedSince, "Wed, 21 Oct 2015 07:27:59 GMT")
|
||||||
|
c.Response().Header.Set(HeaderLastModified, "Wed, 21 Oct 2015 07:28:00 GMT")
|
||||||
require.False(t, c.Fresh())
|
require.False(t, c.Fresh())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1412,6 +1416,18 @@ func Benchmark_Ctx_Fresh_WithNoCache(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// go test -v -run=^$ -bench=Benchmark_Ctx_Fresh_LastModified -benchmem -count=4
|
||||||
|
func Benchmark_Ctx_Fresh_LastModified(b *testing.B) {
|
||||||
|
app := New()
|
||||||
|
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||||
|
|
||||||
|
c.Response().Header.Set(HeaderLastModified, "Wed, 21 Oct 2015 07:28:00 GMT")
|
||||||
|
c.Request().Header.Set(HeaderIfModifiedSince, "Wed, 21 Oct 2015 07:28:00 GMT")
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
c.Fresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// go test -run Test_Ctx_Binders -v
|
// go test -run Test_Ctx_Binders -v
|
||||||
func Test_Ctx_Binders(t *testing.T) {
|
func Test_Ctx_Binders(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
Loading…
Reference in New Issue