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

Possible fix for #424 #430

Merged
merged 2 commits into from
Nov 26, 2020
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
3 changes: 3 additions & 0 deletions src/Giraffe/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type DateTimeOffset with
/// <returns>Formatted string value.</returns>
member this.ToIsoString() = this.ToString("o")

member this.CutOffMs() =
DateTimeOffset(this.Year, this.Month, this.Day, this.Hour, this.Minute, this.Second, 0, this.Offset)

// ---------------------------
// Common helper functions
// ---------------------------
Expand Down
10 changes: 6 additions & 4 deletions src/Giraffe/Preconditional.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type HttpContext with
match lastModified with
| None -> AllConditionsMet
| Some lastModified ->
match requestHeaders.IfUnmodifiedSince.Value > DateTimeOffset.UtcNow
let lastModified = lastModified.CutOffMs()
match requestHeaders.IfUnmodifiedSince.Value > DateTimeOffset.UtcNow.CutOffMs()
|| requestHeaders.IfUnmodifiedSince.Value >= lastModified with
| true -> AllConditionsMet
| false -> ConditionFailed
Expand Down Expand Up @@ -81,7 +82,8 @@ type HttpContext with
match lastModified with
| None -> AllConditionsMet
| Some lastModified ->
match requestHeaders.IfModifiedSince.Value <= DateTimeOffset.UtcNow
let lastModified = lastModified.CutOffMs()
match requestHeaders.IfModifiedSince.Value <= DateTimeOffset.UtcNow.CutOffMs()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need an integration test to check the value of requestHeaders.IfModifiedSince.Value

&& requestHeaders.IfModifiedSince.Value < lastModified with
| true -> AllConditionsMet
| false -> ResourceNotModified
Expand Down Expand Up @@ -136,8 +138,8 @@ type HttpContext with
| ResourceNotModified -> ResourceNotModified

// Set ETag and Last-Modified in the response
if eTag.IsSome then responseHeaders.ETag <- eTag.Value
if lastModified.IsSome then responseHeaders.LastModified <- Nullable(lastModified.Value)
if eTag.IsSome then responseHeaders.ETag <- eTag.Value
if lastModified.IsSome then responseHeaders.LastModified <- Nullable(lastModified.Value.CutOffMs())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this has any effect, but I don't think there's any harm here either


// Validate headers in correct precedence
// RFC: https://tools.ietf.org/html/rfc7232#section-6
Expand Down