|
1 | 1 | from __future__ import absolute_import, division, print_function, with_statement
|
2 | 2 | from tornado import gen
|
3 | 3 | from tornado.escape import json_decode, utf8, to_unicode, recursive_unicode, native_str, to_basestring
|
| 4 | +from tornado.httputil import format_timestamp |
4 | 5 | from tornado.iostream import IOStream
|
5 | 6 | from tornado.log import app_log, gen_log
|
6 | 7 | from tornado.simple_httpclient import SimpleAsyncHTTPClient
|
@@ -813,6 +814,29 @@ def test_static_304_if_none_match(self):
|
813 | 814 | 'If-None-Match': response1.headers['Etag']})
|
814 | 815 | self.assertEqual(response2.code, 304)
|
815 | 816 |
|
| 817 | + def test_static_if_modified_since_pre_epoch(self): |
| 818 | + # On windows, the functions that work with time_t do not accept |
| 819 | + # negative values, and at least one client (processing.js) seems |
| 820 | + # to use if-modified-since 1/1/1960 as a cache-busting technique. |
| 821 | + response = self.fetch("/static/robots.txt", headers={ |
| 822 | + 'If-Modified-Since': 'Fri, 01 Jan 1960 00:00:00 GMT'}) |
| 823 | + self.assertEqual(response.code, 200) |
| 824 | + |
| 825 | + def test_static_if_modified_since_time_zone(self): |
| 826 | + # Instead of the value from Last-Modified, make requests with times |
| 827 | + # chosen just before and after the known modification time |
| 828 | + # of the file to ensure that the right time zone is being used |
| 829 | + # when parsing If-Modified-Since. |
| 830 | + stat = os.stat(os.path.join(os.path.dirname(__file__), |
| 831 | + 'static/robots.txt')) |
| 832 | + |
| 833 | + response = self.fetch('/static/robots.txt', headers={ |
| 834 | + 'If-Modified-Since': format_timestamp(stat.st_mtime - 1)}) |
| 835 | + self.assertEqual(response.code, 200) |
| 836 | + response = self.fetch('/static/robots.txt', headers={ |
| 837 | + 'If-Modified-Since': format_timestamp(stat.st_mtime + 1)}) |
| 838 | + self.assertEqual(response.code, 304) |
| 839 | + |
816 | 840 |
|
817 | 841 | @wsgi_safe
|
818 | 842 | class CustomStaticFileTest(WebTestCase):
|
|
0 commit comments