Skip to content

Commit a288123

Browse files
straight-shootaRX14
authored andcommittedJan 19, 2018
Fix HTTP::StaticFileHandler to properly parse HTTP date (#5607)
1 parent a29e21b commit a288123

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed
 

‎src/http/server/handlers/static_file_handler.cr

+3-4
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ class HTTP::StaticFileHandler
6868
context.response.headers["Last-Modified"] = HTTP.rfc1123_date(last_modified)
6969

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.