yield gen.Task(self.flush)
self.finish()
+class CacheHandler(RequestHandler):
+ def get(self, computed_etag):
+ self.write(computed_etag)
+
+ def compute_etag(self):
+ return self._write_buffer[0]
+
class TestMixin(object):
def get_handlers(self):
return [
('/redirect(/.*)', RedirectHandler),
('/post', PostHandler),
('/chunked', ChunkedHandler),
+ ('/cache/(.*)', CacheHandler),
]
def get_app_kwargs(self):
raise red.response.http_error.res_error
else:
raise Exception("unknown error; incomplete response")
-
self.assertEqual(int(red.response.status_code), expected_status)
allowed_warnings = (allowed_warnings or []) + self.get_allowed_warnings()
def test_chunked(self):
self.check_url('/chunked')
+ def test_strong_etag_match(self):
+ computed_etag = '"xyzzy"'
+ etags = '"xyzzy"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=304)
+
+ def test_multiple_strong_etag_match(self):
+ computed_etag = '"xyzzy1"'
+ etags = '"xyzzy1", "xyzzy2"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=304)
+
+ def test_strong_etag_not_match(self):
+ computed_etag = '"xyzzy"'
+ etags = '"xyzzy1"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=200)
+
+ def test_multiple_strong_etag_not_match(self):
+ computed_etag = '"xyzzy"'
+ etags = '"xyzzy1", "xyzzy2"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=200)
+
+ def test_wildcard_etag(self):
+ computed_etag = '"xyzzy"'
+ etags = '*'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=304,
+ allowed_warnings=[rs.MISSING_HDRS_304])
+
+ def test_weak_etag_match(self):
+ computed_etag = '"xyzzy1"'
+ etags = 'W/"xyzzy1"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=304)
+
+ def test_multiple_weak_etag_match(self):
+ computed_etag = '"xyzzy2"'
+ etags = 'W/"xyzzy1", W/"xyzzy2"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=304)
+
+ def test_weak_etag_not_match(self):
+ computed_etag = '"xyzzy2"'
+ etags = 'W/"xyzzy1"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=200)
+
+ def test_multiple_weak_etag_not_match(self):
+ computed_etag = '"xyzzy3"'
+ etags = 'W/"xyzzy1", W/"xyzzy2"'
+ self.check_url(
+ '/cache/' + computed_etag, method='GET',
+ headers=[('If-None-Match', etags)],
+ expected_status=200)
+
class DefaultHTTPTest(AsyncHTTPTestCase, LogTrapTestCase, TestMixin):
def get_app(self):
return Application(self.get_handlers(), **self.get_app_kwargs())