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())
Exemplo n.º 2
0
 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 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 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())