From 121798bae3b94492826706017c1a2d0f0d71454a Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 10 Sep 2011 19:37:48 +0200 Subject: Handle rfc1123 dates with timezone names. --- fbin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fbin.py b/fbin.py index 14ba18d..75a0343 100755 --- a/fbin.py +++ b/fbin.py @@ -6,6 +6,7 @@ from PIL import Image base62_alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' rfc1123_format = '%a, %d %b %Y %H:%M:%S +0000' +rfc1123_format_tzname = '%a, %d %b %Y %H:%M:%S %Z' if not os.path.isdir(settings.file_directory): os.mkdir(settings.file_directory) @@ -124,7 +125,11 @@ class Application(object): def not_modified(self, environ, date): if not 'HTTP_IF_MODIFIED_SINCE' in environ: return False - mod_since_date = datetime.datetime.strptime(environ['HTTP_IF_MODIFIED_SINCE'], rfc1123_format) + try: + mod_since_date = datetime.datetime.strptime(environ['HTTP_IF_MODIFIED_SINCE'], rfc1123_format) + except ValueError: + # some clients use timezone names (eg. GMT) instead of numeric timezones + mod_since_date = datetime.datetime.strptime(environ['HTTP_IF_MODIFIED_SINCE'], rfc1123_format_tzname) return date == mod_since_date def file(self, environ, start_response, path): -- cgit v1.2.3