def testGetHTTPResponseHeader(self): r = Request() r.response_headers = {} self.assertEquals(None, r.GetHTTPResponseHeader('Foo')) r.response_headers = {'Foo': 'Bar', 'Baz': 'Foo'} self.assertEquals('Bar', r.GetHTTPResponseHeader('Foo')) r.response_headers = {'foo': 'Bar', 'Baz': 'Foo'} self.assertEquals('Bar', r.GetHTTPResponseHeader('Foo'))
def testContentType(self): r = Request() r.response_headers = {} self.assertEquals(None, r.GetContentType()) r.response_headers = {'Content-Type': 'application/javascript'} self.assertEquals('application/javascript', r.GetContentType()) r.response_headers = {'Content-Type': 'application/javascript;bla'} self.assertEquals('application/javascript', r.GetContentType())
def testGetRawResponseHeaders(self): r = Request() r.protocol = 'http/1.1' r.status = 200 r.status_text = 'Hello world' r.response_headers = {'Foo': 'Bar', 'Baz': 'Foo'} self.assertEquals('HTTP/1.1 200 Hello world\x00Baz: Foo\x00Foo: Bar\x00', r.GetRawResponseHeaders())
def testContentType(self): r = Request() r.response_headers = {} self.assertEquals(None, r.GetContentType()) r.response_headers = {'Content-Type': 'application/javascript'} self.assertEquals('application/javascript', r.GetContentType()) # Case-insensitive match. r.response_headers = {'content-type': 'application/javascript'} self.assertEquals('application/javascript', r.GetContentType()) # Parameters are filtered out. r.response_headers = {'Content-Type': 'application/javascript;bla'} self.assertEquals('application/javascript', r.GetContentType()) # MIME type takes precedence over 'Content-Type' header. r.mime_type = 'image/webp' self.assertEquals('image/webp', r.GetContentType()) r.mime_type = None # Test for 'ping' type. r.status = 204 self.assertEquals('ping', r.GetContentType()) r.status = None r.response_headers = {'Content-Type': 'application/javascript', 'content-length': '0'} self.assertEquals('ping', r.GetContentType()) # Test for 'redirect' type. r.response_headers = {'Content-Type': 'application/javascript', 'location': 'http://foo', 'content-length': '0'} self.assertEquals('redirect', r.GetContentType())
def testContentType(self): r = Request() r.response_headers = {} self.assertEquals(None, r.GetContentType()) r.response_headers = {'Content-Type': 'application/javascript'} self.assertEquals('application/javascript', r.GetContentType()) # Case-insensitive match. r.response_headers = {'content-type': 'application/javascript'} self.assertEquals('application/javascript', r.GetContentType()) # Parameters are filtered out. r.response_headers = {'Content-Type': 'application/javascript;bla'} self.assertEquals('application/javascript', r.GetContentType()) # MIME type takes precedence over 'Content-Type' header. r.mime_type = 'image/webp' self.assertEquals('image/webp', r.GetContentType()) r.mime_type = None # Test for 'ping' type. r.status = 204 self.assertEquals('ping', r.GetContentType()) r.status = None r.response_headers = { 'Content-Type': 'application/javascript', 'content-length': '0' } self.assertEquals('ping', r.GetContentType()) # Test for 'redirect' type. r.response_headers = { 'Content-Type': 'application/javascript', 'location': 'http://foo', 'content-length': '0' } self.assertEquals('redirect', r.GetContentType())
def testMaxAge(self): rq = Request() self.assertEqual(-1, rq.MaxAge()) rq.response_headers = {} self.assertEqual(-1, rq.MaxAge()) rq.response_headers[ 'Cache-Control'] = 'private,s-maxage=0,max-age=0,must-revalidate' self.assertEqual(0, rq.MaxAge()) rq.response_headers[ 'Cache-Control'] = 'private,s-maxage=0,no-store,max-age=100' self.assertEqual(-1, rq.MaxAge()) rq.response_headers[ 'Cache-Control'] = 'private,s-maxage=0' self.assertEqual(-1, rq.MaxAge())
def testMaxAge(self): rq = Request() self.assertEqual(-1, rq.MaxAge()) rq.response_headers = {} self.assertEqual(-1, rq.MaxAge()) rq.response_headers[ 'Cache-Control'] = 'private,s-maxage=0,max-age=0,must-revalidate' self.assertEqual(0, rq.MaxAge()) rq.response_headers[ 'Cache-Control'] = 'private,s-maxage=0,no-store,max-age=100' self.assertEqual(-1, rq.MaxAge()) rq.response_headers['Cache-Control'] = 'private,s-maxage=0' self.assertEqual(-1, rq.MaxAge()) # Case-insensitive match. rq.response_headers['cache-control'] = 'max-age=600' self.assertEqual(600, rq.MaxAge())