Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 Fix: behavior of DefaultCtx.Fresh when 'Last-Modified' and 'If-Modified-Since' are equal #3150

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func (c *DefaultCtx) Fresh() bool {
if err != nil {
return false
}
return lastModifiedTime.Before(modifiedSinceTime)
return lastModifiedTime.Compare(modifiedSinceTime) != 1
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,10 @@ func Test_Ctx_Fresh(t *testing.T) {
require.False(t, c.Fresh())

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")
gaby marked this conversation as resolved.
Show resolved Hide resolved
require.False(t, c.Fresh())
}

Expand All @@ -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
func Test_Ctx_Binders(t *testing.T) {
t.Parallel()
Expand Down
Loading