def test_from_httplib_py2(self): msg = """ Server: nginx Content-Type: text/html; charset=windows-1251 Connection: keep-alive X-Some-Multiline: asdf asdf\t \t asdf Set-Cookie: bb_lastvisit=1348253375; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ Set-Cookie: bb_lastactivity=0; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ www-authenticate: asdf www-authenticate: bla """ buffer = six.moves.StringIO(msg.lstrip().replace('\n', '\r\n')) msg = six.moves.http_client.HTTPMessage(buffer) d = HTTPHeaderDict.from_httplib(msg) assert d['server'] == 'nginx' cookies = d.getlist('set-cookie') assert len(cookies) == 2 assert cookies[0].startswith("bb_lastvisit") assert cookies[1].startswith("bb_lastactivity") assert d['x-some-multiline'] == 'asdf asdf asdf' assert d['www-authenticate'] == 'asdf, bla' assert d.getlist('www-authenticate') == ['asdf', 'bla'] with_invalid_multiline = """\tthis-is-not-a-header: but it has a pretend value Authorization: Bearer 123 """ buffer = six.moves.StringIO(with_invalid_multiline.replace('\n', '\r\n')) msg = six.moves.http_client.HTTPMessage(buffer) with pytest.raises(InvalidHeader): HTTPHeaderDict.from_httplib(msg)
def test_from_httplib_py2(self): msg = """ Server: nginx Content-Type: text/html; charset=windows-1251 Connection: keep-alive X-Some-Multiline: asdf asdf\t \t asdf Set-Cookie: bb_lastvisit=1348253375; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ Set-Cookie: bb_lastactivity=0; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ www-authenticate: asdf www-authenticate: bla """ buffer = six.moves.StringIO(msg.lstrip().replace('\n', '\r\n')) msg = six.moves.http_client.HTTPMessage(buffer) d = HTTPHeaderDict.from_httplib(msg) assert d['server'] == 'nginx' cookies = d.getlist('set-cookie') assert len(cookies) == 2 assert cookies[0].startswith("bb_lastvisit") assert cookies[1].startswith("bb_lastactivity") assert d['x-some-multiline'] == 'asdf asdf asdf' assert d['www-authenticate'] == 'asdf, bla' assert d.getlist('www-authenticate') == ['asdf', 'bla'] with_invalid_multiline = """\tthis-is-not-a-header: but it has a pretend value Authorization: Bearer 123 """ buffer = six.moves.StringIO( with_invalid_multiline.replace('\n', '\r\n')) msg = six.moves.http_client.HTTPMessage(buffer) with pytest.raises(InvalidHeader): HTTPHeaderDict.from_httplib(msg)
def test_from_httplib_py2(self): msg = """ Server: nginx Content-Type: text/html; charset=windows-1251 Connection: keep-alive X-Some-Multiline: asdf asdf asdf Set-Cookie: bb_lastvisit=1348253375; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ Set-Cookie: bb_lastactivity=0; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ www-authenticate: asdf www-authenticate: bla """ buffer = six.moves.StringIO(msg.lstrip().replace('\n', '\r\n')) msg = six.moves.http_client.HTTPMessage(buffer) d = HTTPHeaderDict.from_httplib(msg) assert d['server'] == 'nginx' cookies = d.getlist('set-cookie') assert len(cookies) == 2 assert cookies[0].startswith("bb_lastvisit") assert cookies[1].startswith("bb_lastactivity") assert d['x-some-multiline'].split() == ['asdf', 'asdf', 'asdf'] assert d['www-authenticate'] == 'asdf, bla' assert d.getlist('www-authenticate') == ['asdf', 'bla']
def test_from_httplib_py2(self): if six.PY3: raise SkipTest("python3 has a different internal header implementation") msg = """ Server: nginx Content-Type: text/html; charset=windows-1251 Connection: keep-alive X-Some-Multiline: asdf asdf asdf Set-Cookie: bb_lastvisit=1348253375; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ Set-Cookie: bb_lastactivity=0; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ www-authenticate: asdf www-authenticate: bla """ buffer = six.moves.StringIO(msg.lstrip().replace('\n', '\r\n')) msg = six.moves.http_client.HTTPMessage(buffer) d = HTTPHeaderDict.from_httplib(msg) self.assertEqual(d['server'], 'nginx') cookies = d.getlist('set-cookie') self.assertEqual(len(cookies), 2) self.assertTrue(cookies[0].startswith("bb_lastvisit")) self.assertTrue(cookies[1].startswith("bb_lastactivity")) self.assertEqual(d['x-some-multiline'].split(), ['asdf', 'asdf', 'asdf']) self.assertEqual(d['www-authenticate'], 'asdf, bla') self.assertEqual(d.getlist('www-authenticate'), ['asdf', 'bla'])
def test_from_httplib_py2(self): if six.PY3: raise SkipTest( "python3 has a different internal header implementation") msg = """ Server: nginx Content-Type: text/html; charset=windows-1251 Connection: keep-alive X-Some-Multiline: asdf asdf asdf Set-Cookie: bb_lastvisit=1348253375; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ Set-Cookie: bb_lastactivity=0; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ www-authenticate: asdf www-authenticate: bla """ buffer = six.moves.StringIO(msg.lstrip().replace('\n', '\r\n')) msg = six.moves.http_client.HTTPMessage(buffer) d = HTTPHeaderDict.from_httplib(msg) self.assertEqual(d['server'], 'nginx') cookies = d.getlist('set-cookie') self.assertEqual(len(cookies), 2) self.assertTrue(cookies[0].startswith("bb_lastvisit")) self.assertTrue(cookies[1].startswith("bb_lastactivity")) self.assertEqual(d['x-some-multiline'].split(), ['asdf', 'asdf', 'asdf']) self.assertEqual(d['www-authenticate'], 'asdf, bla') self.assertEqual(d.getlist('www-authenticate'), ['asdf', 'bla'])
def test_from_httplib(self): if six.PY3: raise SkipTest() from httplib import HTTPMessage from StringIO import StringIO msg = """ Server: nginx Content-Type: text/html; charset=windows-1251 Connection: keep-alive Set-Cookie: bb_lastvisit=1348253375; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ Set-Cookie: bb_lastactivity=0; expires=Sat, 21-Sep-2013 18:49:35 GMT; path=/ """ msg = HTTPMessage(StringIO(msg.lstrip().replace('\n', '\r\n'))) d = HTTPHeaderDict.from_httplib(msg) self.assertEqual(d['server'], 'nginx') cookies = d.getlist('set-cookie') self.assertEqual(len(cookies), 2) self.assertTrue(cookies[0].startswith("bb_lastvisit")) self.assertTrue(cookies[1].startswith("bb_lastactivity"))