From 16ae3d39a79d30a1fe5087f48c3ab853bea72ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 18 Jan 2018 23:20:13 +0100 Subject: [PATCH] Fix HTTP::StaticFileHandler to properly parse HTTP date --- src/http/server/handlers/static_file_handler.cr | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/http/server/handlers/static_file_handler.cr b/src/http/server/handlers/static_file_handler.cr index c2ece0c154b2..fdc17bcfc54d 100644 --- a/src/http/server/handlers/static_file_handler.cr +++ b/src/http/server/handlers/static_file_handler.cr @@ -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