Skip to content

Commit

Permalink
Fix HTTP::StaticFileHandler to properly parse HTTP date (#5607)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and RX14 committed Jan 19, 2018
1 parent a29e21b commit a288123
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/http/server/handlers/static_file_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ class HTTP::StaticFileHandler
context.response.headers["Last-Modified"] = HTTP.rfc1123_date(last_modified)

if if_modified_since = context.request.headers["If-Modified-Since"]?
# TODO: Use a more generalized time format parser for better compatibility to RFC 7232
header_time = Time.parse(if_modified_since, "%a, %d %b %Y %H:%M:%S GMT")
header_time = HTTP.parse_time(if_modified_since)

# File mtime probably has a higher resolution than the header value.
# An exact comparison might be slightly off, so we add 1s padding.
# Static files should generally not be modified in subsecond intervals, so this is perfectly safe.
# This might replaced by a more sophisticated time comparison when it becomes available.
if last_modified <= header_time + 1.second
# This might be replaced by a more sophisticated time comparison when it becomes available.
if header_time && last_modified <= header_time + 1.second
context.response.status_code = 304
return
end
Expand Down

0 comments on commit a288123

Please sign in to comment.