def test_parse_headers(self): hdrs = ('', 'test: line\r\n', ' continue\r\n', 'test2: data\r\n', '\r\n') headers, close, compression = protocol.parse_headers( hdrs, 8190, 32768, 8190) self.assertEqual(list(headers), [('TEST', 'line\r\n continue'), ('TEST2', 'data')]) self.assertIsNone(close) self.assertIsNone(compression)
def test_parse_headers(self): hdrs = ('', 'test: line\r\n', ' continue\r\n', 'test2: data\r\n', '\r\n') headers, close, compression = protocol.parse_headers( hdrs, 8190, 32768, 8190) self.assertEqual(list(headers), [('TEST', 'line\r\n continue'), ('TEST2', 'data')]) self.assertIsNone(close) self.assertIsNone(compression)
def test_parse_headers_multi(self): hdrs = ('', 'Set-Cookie: c1=cookie1\r\n', 'Set-Cookie: c2=cookie2\r\n', '\r\n') headers, close, compression = protocol.parse_headers( hdrs, 8190, 32768, 8190) self.assertEqual(list(headers), [('SET-COOKIE', 'c1=cookie1'), ('SET-COOKIE', 'c2=cookie2')]) self.assertIsNone(close) self.assertIsNone(compression)
def test_parse_headers_multi(self): hdrs = ('', 'Set-Cookie: c1=cookie1\r\n', 'Set-Cookie: c2=cookie2\r\n', '\r\n') headers, close, compression = protocol.parse_headers( hdrs, 8190, 32768, 8190) self.assertEqual(list(headers), [('SET-COOKIE', 'c1=cookie1'), ('SET-COOKIE', 'c2=cookie2')]) self.assertIsNone(close) self.assertIsNone(compression)
def test_compression_unknown(self): headers, close, compression = protocol.parse_headers( ['', 'content-encoding: compress\r\n', '\r\n'], 8190, 32768, 8190) self.assertIsNone(compression)
def test_compression_deflate(self): headers, close, compression = protocol.parse_headers( ['', 'content-encoding: deflate\r\n', '\r\n'], 8190, 32768, 8190) self.assertEqual('deflate', compression)
def test_compression_gzip(self): headers, close, compression = protocol.parse_headers( ['', 'content-encoding: gzip\r\n', '\r\n'], 8190, 32768, 8190) self.assertEqual('gzip', compression)
def test_conn_other(self): headers, close, compression = protocol.parse_headers( ['', 'connection: test\r\n', '\r\n'], 8190, 32768, 8190) self.assertIsNone(close)
def test_conn_keep_alive(self): headers, close, compression = protocol.parse_headers( ['', 'connection: keep-alive\r\n', '\r\n'], 8190, 32768, 8190) self.assertFalse(close)
def test_conn_close(self): headers, close, compression = protocol.parse_headers( ['', 'connection: close\r\n', '\r\n'], 8190, 32768, 8190) self.assertTrue(close)
def test_conn_keep_alive(self): headers, close, compression = protocol.parse_headers( ['', 'connection: keep-alive\r\n', '\r\n'], 8190, 32768, 8190) self.assertFalse(close)
def test_invalid_name(self): with self.assertRaises(ValueError) as cm: protocol.parse_headers(['', 'test[]: line\r\n', '\r\n'], 8190, 32768, 8190) self.assertIn("Invalid header name: TEST[]", str(cm.exception))
def test_max_continuation_headers_size(self): with self.assertRaises(errors.LineTooLong) as cm: protocol.parse_headers(['', 'test: line\r\n', ' test\r\n', '\r\n'], 8190, 32768, 5) self.assertIn("limit request headers fields size", str(cm.exception))
def test_compression_unknown(self): headers, close, compression = protocol.parse_headers( ['', 'content-encoding: compress\r\n', '\r\n'], 8190, 32768, 8190) self.assertIsNone(compression)
def test_compression_deflate(self): headers, close, compression = protocol.parse_headers( ['', 'content-encoding: deflate\r\n', '\r\n'], 8190, 32768, 8190) self.assertEqual('deflate', compression)
def test_compression_gzip(self): headers, close, compression = protocol.parse_headers( ['', 'content-encoding: gzip\r\n', '\r\n'], 8190, 32768, 8190) self.assertEqual('gzip', compression)
def test_conn_other(self): headers, close, compression = protocol.parse_headers( ['', 'connection: test\r\n', '\r\n'], 8190, 32768, 8190) self.assertIsNone(close)
def test_max_continuation_headers_size(self): with self.assertRaises(errors.LineTooLong) as cm: protocol.parse_headers( ['', 'test: line\r\n', ' test\r\n', '\r\n'], 8190, 32768, 5) self.assertIn("limit request headers fields size", str(cm.exception))
def test_invalid_name(self): with self.assertRaises(ValueError) as cm: protocol.parse_headers( ['', 'test[]: line\r\n', '\r\n'], 8190, 32768, 8190) self.assertIn("Invalid header name: TEST[]", str(cm.exception))
def test_conn_close(self): headers, close, compression = protocol.parse_headers( ['', 'connection: close\r\n', '\r\n'], 8190, 32768, 8190) self.assertTrue(close)