Jeremy Hylton | 636950f | 2009-03-28 04:34:21 +0000 | [diff] [blame] | 1 | import errno |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 2 | from http import client |
Jeremy Hylton | 8fff792 | 2007-08-03 20:56:14 +0000 | [diff] [blame] | 3 | import io |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 4 | import os |
Antoine Pitrou | ead1d62 | 2009-09-29 18:44:53 +0000 | [diff] [blame] | 5 | import array |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 6 | import socket |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 7 | |
Gregory P. Smith | b406637 | 2010-01-03 03:28:29 +0000 | [diff] [blame] | 8 | import unittest |
| 9 | TestCase = unittest.TestCase |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 10 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 11 | from test import support |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 12 | |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 13 | here = os.path.dirname(__file__) |
| 14 | # Self-signed cert file for 'localhost' |
| 15 | CERT_localhost = os.path.join(here, 'keycert.pem') |
| 16 | # Self-signed cert file for 'fakehostname' |
| 17 | CERT_fakehostname = os.path.join(here, 'keycert2.pem') |
| 18 | # Root cert file (CA) for svn.python.org's cert |
| 19 | CACERT_svn_python_org = os.path.join(here, 'https_svn_python_org_root.pem') |
| 20 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 21 | HOST = support.HOST |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 22 | |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 23 | class FakeSocket: |
Jeremy Hylton | 8fff792 | 2007-08-03 20:56:14 +0000 | [diff] [blame] | 24 | def __init__(self, text, fileclass=io.BytesIO): |
| 25 | if isinstance(text, str): |
Guido van Rossum | 39478e8 | 2007-08-27 17:23:59 +0000 | [diff] [blame] | 26 | text = text.encode("ascii") |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 27 | self.text = text |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 28 | self.fileclass = fileclass |
Martin v. Löwis | dd5a860 | 2007-06-30 09:22:09 +0000 | [diff] [blame] | 29 | self.data = b'' |
Antoine Pitrou | 90e4774 | 2013-01-02 22:10:47 +0100 | [diff] [blame] | 30 | self.sendall_calls = 0 |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 31 | |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 32 | def sendall(self, data): |
Antoine Pitrou | 90e4774 | 2013-01-02 22:10:47 +0100 | [diff] [blame] | 33 | self.sendall_calls += 1 |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 34 | self.data += data |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 35 | |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 36 | def makefile(self, mode, bufsize=None): |
| 37 | if mode != 'r' and mode != 'rb': |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 38 | raise client.UnimplementedFileMode() |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 39 | return self.fileclass(self.text) |
| 40 | |
Jeremy Hylton | 636950f | 2009-03-28 04:34:21 +0000 | [diff] [blame] | 41 | class EPipeSocket(FakeSocket): |
| 42 | |
| 43 | def __init__(self, text, pipe_trigger): |
| 44 | # When sendall() is called with pipe_trigger, raise EPIPE. |
| 45 | FakeSocket.__init__(self, text) |
| 46 | self.pipe_trigger = pipe_trigger |
| 47 | |
| 48 | def sendall(self, data): |
| 49 | if self.pipe_trigger in data: |
Andrew Svetlov | 0832af6 | 2012-12-18 23:10:48 +0200 | [diff] [blame] | 50 | raise OSError(errno.EPIPE, "gotcha") |
Jeremy Hylton | 636950f | 2009-03-28 04:34:21 +0000 | [diff] [blame] | 51 | self.data += data |
| 52 | |
| 53 | def close(self): |
| 54 | pass |
| 55 | |
Jeremy Hylton | 8fff792 | 2007-08-03 20:56:14 +0000 | [diff] [blame] | 56 | class NoEOFStringIO(io.BytesIO): |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 57 | """Like StringIO, but raises AssertionError on EOF. |
| 58 | |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 59 | This is used below to test that http.client doesn't try to read |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 60 | more from the underlying file than it should. |
| 61 | """ |
| 62 | def read(self, n=-1): |
Jeremy Hylton | 8fff792 | 2007-08-03 20:56:14 +0000 | [diff] [blame] | 63 | data = io.BytesIO.read(self, n) |
Jeremy Hylton | da3f228 | 2007-08-29 17:26:34 +0000 | [diff] [blame] | 64 | if data == b'': |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 65 | raise AssertionError('caller tried to read past EOF') |
| 66 | return data |
| 67 | |
| 68 | def readline(self, length=None): |
Jeremy Hylton | 8fff792 | 2007-08-03 20:56:14 +0000 | [diff] [blame] | 69 | data = io.BytesIO.readline(self, length) |
Jeremy Hylton | da3f228 | 2007-08-29 17:26:34 +0000 | [diff] [blame] | 70 | if data == b'': |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 71 | raise AssertionError('caller tried to read past EOF') |
| 72 | return data |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 73 | |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 74 | class HeaderTests(TestCase): |
| 75 | def test_auto_headers(self): |
| 76 | # Some headers are added automatically, but should not be added by |
| 77 | # .request() if they are explicitly set. |
| 78 | |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 79 | class HeaderCountingBuffer(list): |
| 80 | def __init__(self): |
| 81 | self.count = {} |
| 82 | def append(self, item): |
Guido van Rossum | 022c474 | 2007-08-29 02:00:20 +0000 | [diff] [blame] | 83 | kv = item.split(b':') |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 84 | if len(kv) > 1: |
| 85 | # item is a 'Key: Value' header string |
Martin v. Löwis | dd5a860 | 2007-06-30 09:22:09 +0000 | [diff] [blame] | 86 | lcKey = kv[0].decode('ascii').lower() |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 87 | self.count.setdefault(lcKey, 0) |
| 88 | self.count[lcKey] += 1 |
| 89 | list.append(self, item) |
| 90 | |
| 91 | for explicit_header in True, False: |
| 92 | for header in 'Content-length', 'Host', 'Accept-encoding': |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 93 | conn = client.HTTPConnection('example.com') |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 94 | conn.sock = FakeSocket('blahblahblah') |
| 95 | conn._buffer = HeaderCountingBuffer() |
| 96 | |
| 97 | body = 'spamspamspam' |
| 98 | headers = {} |
| 99 | if explicit_header: |
| 100 | headers[header] = str(len(body)) |
| 101 | conn.request('POST', '/', body, headers) |
| 102 | self.assertEqual(conn._buffer.count[header.lower()], 1) |
| 103 | |
Senthil Kumaran | 5fa4a89 | 2012-05-19 16:58:09 +0800 | [diff] [blame] | 104 | def test_content_length_0(self): |
| 105 | |
| 106 | class ContentLengthChecker(list): |
| 107 | def __init__(self): |
| 108 | list.__init__(self) |
| 109 | self.content_length = None |
| 110 | def append(self, item): |
| 111 | kv = item.split(b':', 1) |
| 112 | if len(kv) > 1 and kv[0].lower() == b'content-length': |
| 113 | self.content_length = kv[1].strip() |
| 114 | list.append(self, item) |
| 115 | |
| 116 | # POST with empty body |
| 117 | conn = client.HTTPConnection('example.com') |
| 118 | conn.sock = FakeSocket(None) |
| 119 | conn._buffer = ContentLengthChecker() |
| 120 | conn.request('POST', '/', '') |
| 121 | self.assertEqual(conn._buffer.content_length, b'0', |
| 122 | 'Header Content-Length not set') |
| 123 | |
| 124 | # PUT request with empty body |
| 125 | conn = client.HTTPConnection('example.com') |
| 126 | conn.sock = FakeSocket(None) |
| 127 | conn._buffer = ContentLengthChecker() |
| 128 | conn.request('PUT', '/', '') |
| 129 | self.assertEqual(conn._buffer.content_length, b'0', |
| 130 | 'Header Content-Length not set') |
| 131 | |
Senthil Kumaran | 58d5dbf | 2010-10-03 18:22:42 +0000 | [diff] [blame] | 132 | def test_putheader(self): |
| 133 | conn = client.HTTPConnection('example.com') |
| 134 | conn.sock = FakeSocket(None) |
| 135 | conn.putrequest('GET','/') |
| 136 | conn.putheader('Content-length', 42) |
Senthil Kumaran | 58d5dbf | 2010-10-03 18:22:42 +0000 | [diff] [blame] | 137 | self.assertTrue(b'Content-length: 42' in conn._buffer) |
| 138 | |
Senthil Kumaran | 74ebd9e | 2010-11-13 12:27:49 +0000 | [diff] [blame] | 139 | def test_ipv6host_header(self): |
| 140 | # Default host header on IPv6 transaction should wrapped by [] if |
| 141 | # its actual IPv6 address |
| 142 | expected = b'GET /foo HTTP/1.1\r\nHost: [2001::]:81\r\n' \ |
| 143 | b'Accept-Encoding: identity\r\n\r\n' |
| 144 | conn = client.HTTPConnection('[2001::]:81') |
| 145 | sock = FakeSocket('') |
| 146 | conn.sock = sock |
| 147 | conn.request('GET', '/foo') |
| 148 | self.assertTrue(sock.data.startswith(expected)) |
| 149 | |
| 150 | expected = b'GET /foo HTTP/1.1\r\nHost: [2001:102A::]\r\n' \ |
| 151 | b'Accept-Encoding: identity\r\n\r\n' |
| 152 | conn = client.HTTPConnection('[2001:102A::]') |
| 153 | sock = FakeSocket('') |
| 154 | conn.sock = sock |
| 155 | conn.request('GET', '/foo') |
| 156 | self.assertTrue(sock.data.startswith(expected)) |
| 157 | |
Senthil Kumaran | 58d5dbf | 2010-10-03 18:22:42 +0000 | [diff] [blame] | 158 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 159 | class BasicTest(TestCase): |
| 160 | def test_status_lines(self): |
| 161 | # Test HTTP status lines |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 162 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 163 | body = "HTTP/1.1 200 Ok\r\n\r\nText" |
| 164 | sock = FakeSocket(body) |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 165 | resp = client.HTTPResponse(sock) |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 166 | resp.begin() |
Jeremy Hylton | 8fff792 | 2007-08-03 20:56:14 +0000 | [diff] [blame] | 167 | self.assertEqual(resp.read(), b"Text") |
Guido van Rossum | 8ce8a78 | 2007-11-01 19:42:39 +0000 | [diff] [blame] | 168 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b5b9c8c | 2013-02-06 10:31:57 +0200 | [diff] [blame] | 169 | self.assertFalse(resp.closed) |
| 170 | resp.close() |
| 171 | self.assertTrue(resp.closed) |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 172 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 173 | body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" |
| 174 | sock = FakeSocket(body) |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 175 | resp = client.HTTPResponse(sock) |
| 176 | self.assertRaises(client.BadStatusLine, resp.begin) |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 177 | |
Benjamin Peterson | 11dbfd4 | 2010-03-21 22:50:04 +0000 | [diff] [blame] | 178 | def test_bad_status_repr(self): |
| 179 | exc = client.BadStatusLine('') |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 180 | self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''') |
Benjamin Peterson | 11dbfd4 | 2010-03-21 22:50:04 +0000 | [diff] [blame] | 181 | |
Guido van Rossum | 8ce8a78 | 2007-11-01 19:42:39 +0000 | [diff] [blame] | 182 | def test_partial_reads(self): |
Antoine Pitrou | 084daa2 | 2012-12-15 19:11:54 +0100 | [diff] [blame] | 183 | # if we have a length, the system knows when to close itself |
Guido van Rossum | 8ce8a78 | 2007-11-01 19:42:39 +0000 | [diff] [blame] | 184 | # same behaviour than when we read the whole thing with read() |
| 185 | body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" |
| 186 | sock = FakeSocket(body) |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 187 | resp = client.HTTPResponse(sock) |
Guido van Rossum | 8ce8a78 | 2007-11-01 19:42:39 +0000 | [diff] [blame] | 188 | resp.begin() |
| 189 | self.assertEqual(resp.read(2), b'Te') |
| 190 | self.assertFalse(resp.isclosed()) |
| 191 | self.assertEqual(resp.read(2), b'xt') |
| 192 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b5b9c8c | 2013-02-06 10:31:57 +0200 | [diff] [blame] | 193 | self.assertFalse(resp.closed) |
| 194 | resp.close() |
| 195 | self.assertTrue(resp.closed) |
Guido van Rossum | 8ce8a78 | 2007-11-01 19:42:39 +0000 | [diff] [blame] | 196 | |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 197 | def test_partial_readintos(self): |
Antoine Pitrou | d20e774 | 2012-12-15 19:22:30 +0100 | [diff] [blame] | 198 | # if we have a length, the system knows when to close itself |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 199 | # same behaviour than when we read the whole thing with read() |
| 200 | body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" |
| 201 | sock = FakeSocket(body) |
| 202 | resp = client.HTTPResponse(sock) |
| 203 | resp.begin() |
| 204 | b = bytearray(2) |
| 205 | n = resp.readinto(b) |
| 206 | self.assertEqual(n, 2) |
| 207 | self.assertEqual(bytes(b), b'Te') |
| 208 | self.assertFalse(resp.isclosed()) |
| 209 | n = resp.readinto(b) |
| 210 | self.assertEqual(n, 2) |
| 211 | self.assertEqual(bytes(b), b'xt') |
| 212 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b6c86fd | 2013-02-06 10:35:40 +0200 | [diff] [blame] | 213 | self.assertFalse(resp.closed) |
| 214 | resp.close() |
| 215 | self.assertTrue(resp.closed) |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 216 | |
Antoine Pitrou | 084daa2 | 2012-12-15 19:11:54 +0100 | [diff] [blame] | 217 | def test_partial_reads_no_content_length(self): |
| 218 | # when no length is present, the socket should be gracefully closed when |
| 219 | # all data was read |
| 220 | body = "HTTP/1.1 200 Ok\r\n\r\nText" |
| 221 | sock = FakeSocket(body) |
| 222 | resp = client.HTTPResponse(sock) |
| 223 | resp.begin() |
| 224 | self.assertEqual(resp.read(2), b'Te') |
| 225 | self.assertFalse(resp.isclosed()) |
| 226 | self.assertEqual(resp.read(2), b'xt') |
| 227 | self.assertEqual(resp.read(1), b'') |
| 228 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b5b9c8c | 2013-02-06 10:31:57 +0200 | [diff] [blame] | 229 | self.assertFalse(resp.closed) |
| 230 | resp.close() |
| 231 | self.assertTrue(resp.closed) |
Antoine Pitrou | 084daa2 | 2012-12-15 19:11:54 +0100 | [diff] [blame] | 232 | |
Antoine Pitrou | d20e774 | 2012-12-15 19:22:30 +0100 | [diff] [blame] | 233 | def test_partial_readintos_no_content_length(self): |
| 234 | # when no length is present, the socket should be gracefully closed when |
| 235 | # all data was read |
| 236 | body = "HTTP/1.1 200 Ok\r\n\r\nText" |
| 237 | sock = FakeSocket(body) |
| 238 | resp = client.HTTPResponse(sock) |
| 239 | resp.begin() |
| 240 | b = bytearray(2) |
| 241 | n = resp.readinto(b) |
| 242 | self.assertEqual(n, 2) |
| 243 | self.assertEqual(bytes(b), b'Te') |
| 244 | self.assertFalse(resp.isclosed()) |
| 245 | n = resp.readinto(b) |
| 246 | self.assertEqual(n, 2) |
| 247 | self.assertEqual(bytes(b), b'xt') |
| 248 | n = resp.readinto(b) |
| 249 | self.assertEqual(n, 0) |
| 250 | self.assertTrue(resp.isclosed()) |
| 251 | |
Antoine Pitrou | beec61a | 2013-02-02 22:49:34 +0100 | [diff] [blame] | 252 | def test_partial_reads_incomplete_body(self): |
| 253 | # if the server shuts down the connection before the whole |
| 254 | # content-length is delivered, the socket is gracefully closed |
| 255 | body = "HTTP/1.1 200 Ok\r\nContent-Length: 10\r\n\r\nText" |
| 256 | sock = FakeSocket(body) |
| 257 | resp = client.HTTPResponse(sock) |
| 258 | resp.begin() |
| 259 | self.assertEqual(resp.read(2), b'Te') |
| 260 | self.assertFalse(resp.isclosed()) |
| 261 | self.assertEqual(resp.read(2), b'xt') |
| 262 | self.assertEqual(resp.read(1), b'') |
| 263 | self.assertTrue(resp.isclosed()) |
| 264 | |
Antoine Pitrou | 6a35e18 | 2013-02-02 23:04:56 +0100 | [diff] [blame] | 265 | def test_partial_readintos_incomplete_body(self): |
| 266 | # if the server shuts down the connection before the whole |
| 267 | # content-length is delivered, the socket is gracefully closed |
| 268 | body = "HTTP/1.1 200 Ok\r\nContent-Length: 10\r\n\r\nText" |
| 269 | sock = FakeSocket(body) |
| 270 | resp = client.HTTPResponse(sock) |
| 271 | resp.begin() |
| 272 | b = bytearray(2) |
| 273 | n = resp.readinto(b) |
| 274 | self.assertEqual(n, 2) |
| 275 | self.assertEqual(bytes(b), b'Te') |
| 276 | self.assertFalse(resp.isclosed()) |
| 277 | n = resp.readinto(b) |
| 278 | self.assertEqual(n, 2) |
| 279 | self.assertEqual(bytes(b), b'xt') |
| 280 | n = resp.readinto(b) |
| 281 | self.assertEqual(n, 0) |
| 282 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b5b9c8c | 2013-02-06 10:31:57 +0200 | [diff] [blame] | 283 | self.assertFalse(resp.closed) |
| 284 | resp.close() |
| 285 | self.assertTrue(resp.closed) |
Antoine Pitrou | 6a35e18 | 2013-02-02 23:04:56 +0100 | [diff] [blame] | 286 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 287 | def test_host_port(self): |
| 288 | # Check invalid host_port |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 289 | |
Łukasz Langa | a5a9a9c | 2011-10-18 21:17:39 +0200 | [diff] [blame] | 290 | for hp in ("www.python.org:abc", "user:password@www.python.org"): |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 291 | self.assertRaises(client.InvalidURL, client.HTTPConnection, hp) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 292 | |
Jeremy Hylton | 3a38c91 | 2007-08-14 17:08:07 +0000 | [diff] [blame] | 293 | for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", |
| 294 | "fe80::207:e9ff:fe9b", 8000), |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 295 | ("www.python.org:80", "www.python.org", 80), |
Łukasz Langa | a5a9a9c | 2011-10-18 21:17:39 +0200 | [diff] [blame] | 296 | ("www.python.org:", "www.python.org", 80), |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 297 | ("www.python.org", "www.python.org", 80), |
Łukasz Langa | a5a9a9c | 2011-10-18 21:17:39 +0200 | [diff] [blame] | 298 | ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80), |
| 299 | ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)): |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 300 | c = client.HTTPConnection(hp) |
Jeremy Hylton | 3a38c91 | 2007-08-14 17:08:07 +0000 | [diff] [blame] | 301 | self.assertEqual(h, c.host) |
| 302 | self.assertEqual(p, c.port) |
Skip Montanaro | 10e6e0e | 2004-09-14 16:32:02 +0000 | [diff] [blame] | 303 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 304 | def test_response_headers(self): |
| 305 | # test response with multiple message headers with the same field name. |
| 306 | text = ('HTTP/1.1 200 OK\r\n' |
Jeremy Hylton | 3a38c91 | 2007-08-14 17:08:07 +0000 | [diff] [blame] | 307 | 'Set-Cookie: Customer="WILE_E_COYOTE"; ' |
| 308 | 'Version="1"; Path="/acme"\r\n' |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 309 | 'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";' |
| 310 | ' Path="/acme"\r\n' |
| 311 | '\r\n' |
| 312 | 'No body\r\n') |
| 313 | hdr = ('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"' |
| 314 | ', ' |
| 315 | 'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"') |
| 316 | s = FakeSocket(text) |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 317 | r = client.HTTPResponse(s) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 318 | r.begin() |
| 319 | cookies = r.getheader("Set-Cookie") |
Jeremy Hylton | 3a38c91 | 2007-08-14 17:08:07 +0000 | [diff] [blame] | 320 | self.assertEqual(cookies, hdr) |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 321 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 322 | def test_read_head(self): |
| 323 | # Test that the library doesn't attempt to read any data |
| 324 | # from a HEAD request. (Tickles SF bug #622042.) |
| 325 | sock = FakeSocket( |
| 326 | 'HTTP/1.1 200 OK\r\n' |
| 327 | 'Content-Length: 14432\r\n' |
| 328 | '\r\n', |
| 329 | NoEOFStringIO) |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 330 | resp = client.HTTPResponse(sock, method="HEAD") |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 331 | resp.begin() |
Guido van Rossum | a00f123 | 2007-09-12 19:43:09 +0000 | [diff] [blame] | 332 | if resp.read(): |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 333 | self.fail("Did not expect response from HEAD request") |
Jeremy Hylton | c1b2cb9 | 2003-05-05 16:13:58 +0000 | [diff] [blame] | 334 | |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 335 | def test_readinto_head(self): |
| 336 | # Test that the library doesn't attempt to read any data |
| 337 | # from a HEAD request. (Tickles SF bug #622042.) |
| 338 | sock = FakeSocket( |
| 339 | 'HTTP/1.1 200 OK\r\n' |
| 340 | 'Content-Length: 14432\r\n' |
| 341 | '\r\n', |
| 342 | NoEOFStringIO) |
| 343 | resp = client.HTTPResponse(sock, method="HEAD") |
| 344 | resp.begin() |
| 345 | b = bytearray(5) |
| 346 | if resp.readinto(b) != 0: |
| 347 | self.fail("Did not expect response from HEAD request") |
| 348 | self.assertEqual(bytes(b), b'\x00'*5) |
| 349 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 350 | def test_send_file(self): |
Guido van Rossum | 022c474 | 2007-08-29 02:00:20 +0000 | [diff] [blame] | 351 | expected = (b'GET /foo HTTP/1.1\r\nHost: example.com\r\n' |
| 352 | b'Accept-Encoding: identity\r\nContent-Length:') |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 353 | |
Brett Cannon | 77b7de6 | 2010-10-29 23:31:11 +0000 | [diff] [blame] | 354 | with open(__file__, 'rb') as body: |
| 355 | conn = client.HTTPConnection('example.com') |
| 356 | sock = FakeSocket(body) |
| 357 | conn.sock = sock |
| 358 | conn.request('GET', '/foo', body) |
| 359 | self.assertTrue(sock.data.startswith(expected), '%r != %r' % |
| 360 | (sock.data[:len(expected)], expected)) |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 361 | |
Antoine Pitrou | ead1d62 | 2009-09-29 18:44:53 +0000 | [diff] [blame] | 362 | def test_send(self): |
| 363 | expected = b'this is a test this is only a test' |
| 364 | conn = client.HTTPConnection('example.com') |
| 365 | sock = FakeSocket(None) |
| 366 | conn.sock = sock |
| 367 | conn.send(expected) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 368 | self.assertEqual(expected, sock.data) |
Antoine Pitrou | ead1d62 | 2009-09-29 18:44:53 +0000 | [diff] [blame] | 369 | sock.data = b'' |
| 370 | conn.send(array.array('b', expected)) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 371 | self.assertEqual(expected, sock.data) |
Antoine Pitrou | ead1d62 | 2009-09-29 18:44:53 +0000 | [diff] [blame] | 372 | sock.data = b'' |
| 373 | conn.send(io.BytesIO(expected)) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 374 | self.assertEqual(expected, sock.data) |
Antoine Pitrou | ead1d62 | 2009-09-29 18:44:53 +0000 | [diff] [blame] | 375 | |
Andrew Svetlov | 7b2c8bb | 2013-04-12 22:49:19 +0300 | [diff] [blame] | 376 | def test_send_updating_file(self): |
| 377 | def data(): |
| 378 | yield 'data' |
| 379 | yield None |
| 380 | yield 'data_two' |
| 381 | |
| 382 | class UpdatingFile(): |
| 383 | mode = 'r' |
| 384 | d = data() |
| 385 | def read(self, blocksize=-1): |
| 386 | return self.d.__next__() |
| 387 | |
| 388 | expected = b'data' |
| 389 | |
| 390 | conn = client.HTTPConnection('example.com') |
| 391 | sock = FakeSocket("") |
| 392 | conn.sock = sock |
| 393 | conn.send(UpdatingFile()) |
| 394 | self.assertEqual(sock.data, expected) |
| 395 | |
| 396 | |
Senthil Kumaran | 7bc0d87 | 2010-12-19 10:49:52 +0000 | [diff] [blame] | 397 | def test_send_iter(self): |
| 398 | expected = b'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \ |
| 399 | b'Accept-Encoding: identity\r\nContent-Length: 11\r\n' \ |
| 400 | b'\r\nonetwothree' |
| 401 | |
| 402 | def body(): |
| 403 | yield b"one" |
| 404 | yield b"two" |
| 405 | yield b"three" |
| 406 | |
| 407 | conn = client.HTTPConnection('example.com') |
| 408 | sock = FakeSocket("") |
| 409 | conn.sock = sock |
| 410 | conn.request('GET', '/foo', body(), {'Content-Length': '11'}) |
Victor Stinner | 04ba966 | 2011-01-04 00:04:46 +0000 | [diff] [blame] | 411 | self.assertEqual(sock.data, expected) |
Senthil Kumaran | 7bc0d87 | 2010-12-19 10:49:52 +0000 | [diff] [blame] | 412 | |
Senthil Kumaran | eb71ad4 | 2011-08-02 18:33:41 +0800 | [diff] [blame] | 413 | def test_send_type_error(self): |
| 414 | # See: Issue #12676 |
| 415 | conn = client.HTTPConnection('example.com') |
| 416 | conn.sock = FakeSocket('') |
| 417 | with self.assertRaises(TypeError): |
| 418 | conn.request('POST', 'test', conn) |
| 419 | |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 420 | def test_chunked(self): |
| 421 | chunked_start = ( |
| 422 | 'HTTP/1.1 200 OK\r\n' |
| 423 | 'Transfer-Encoding: chunked\r\n\r\n' |
| 424 | 'a\r\n' |
| 425 | 'hello worl\r\n' |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 426 | '3\r\n' |
| 427 | 'd! \r\n' |
| 428 | '8\r\n' |
| 429 | 'and now \r\n' |
| 430 | '22\r\n' |
| 431 | 'for something completely different\r\n' |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 432 | ) |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 433 | expected = b'hello world! and now for something completely different' |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 434 | sock = FakeSocket(chunked_start + '0\r\n') |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 435 | resp = client.HTTPResponse(sock, method="GET") |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 436 | resp.begin() |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 437 | self.assertEqual(resp.read(), expected) |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 438 | resp.close() |
| 439 | |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 440 | # Various read sizes |
| 441 | for n in range(1, 12): |
| 442 | sock = FakeSocket(chunked_start + '0\r\n') |
| 443 | resp = client.HTTPResponse(sock, method="GET") |
| 444 | resp.begin() |
| 445 | self.assertEqual(resp.read(n) + resp.read(n) + resp.read(), expected) |
| 446 | resp.close() |
| 447 | |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 448 | for x in ('', 'foo\r\n'): |
| 449 | sock = FakeSocket(chunked_start + x) |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 450 | resp = client.HTTPResponse(sock, method="GET") |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 451 | resp.begin() |
| 452 | try: |
| 453 | resp.read() |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 454 | except client.IncompleteRead as i: |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 455 | self.assertEqual(i.partial, expected) |
| 456 | expected_message = 'IncompleteRead(%d bytes read)' % len(expected) |
| 457 | self.assertEqual(repr(i), expected_message) |
| 458 | self.assertEqual(str(i), expected_message) |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 459 | else: |
| 460 | self.fail('IncompleteRead expected') |
| 461 | finally: |
| 462 | resp.close() |
| 463 | |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 464 | def test_readinto_chunked(self): |
| 465 | chunked_start = ( |
| 466 | 'HTTP/1.1 200 OK\r\n' |
| 467 | 'Transfer-Encoding: chunked\r\n\r\n' |
| 468 | 'a\r\n' |
| 469 | 'hello worl\r\n' |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 470 | '3\r\n' |
| 471 | 'd! \r\n' |
| 472 | '8\r\n' |
| 473 | 'and now \r\n' |
| 474 | '22\r\n' |
| 475 | 'for something completely different\r\n' |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 476 | ) |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 477 | expected = b'hello world! and now for something completely different' |
| 478 | nexpected = len(expected) |
| 479 | b = bytearray(128) |
| 480 | |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 481 | sock = FakeSocket(chunked_start + '0\r\n') |
| 482 | resp = client.HTTPResponse(sock, method="GET") |
| 483 | resp.begin() |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 484 | n = resp.readinto(b) |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 485 | self.assertEqual(b[:nexpected], expected) |
| 486 | self.assertEqual(n, nexpected) |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 487 | resp.close() |
| 488 | |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 489 | # Various read sizes |
| 490 | for n in range(1, 12): |
| 491 | sock = FakeSocket(chunked_start + '0\r\n') |
| 492 | resp = client.HTTPResponse(sock, method="GET") |
| 493 | resp.begin() |
| 494 | m = memoryview(b) |
| 495 | i = resp.readinto(m[0:n]) |
| 496 | i += resp.readinto(m[i:n + i]) |
| 497 | i += resp.readinto(m[i:]) |
| 498 | self.assertEqual(b[:nexpected], expected) |
| 499 | self.assertEqual(i, nexpected) |
| 500 | resp.close() |
| 501 | |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 502 | for x in ('', 'foo\r\n'): |
| 503 | sock = FakeSocket(chunked_start + x) |
| 504 | resp = client.HTTPResponse(sock, method="GET") |
| 505 | resp.begin() |
| 506 | try: |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 507 | n = resp.readinto(b) |
| 508 | except client.IncompleteRead as i: |
Antoine Pitrou | f7e7818 | 2012-01-04 18:57:22 +0100 | [diff] [blame] | 509 | self.assertEqual(i.partial, expected) |
| 510 | expected_message = 'IncompleteRead(%d bytes read)' % len(expected) |
| 511 | self.assertEqual(repr(i), expected_message) |
| 512 | self.assertEqual(str(i), expected_message) |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 513 | else: |
| 514 | self.fail('IncompleteRead expected') |
| 515 | finally: |
| 516 | resp.close() |
| 517 | |
Senthil Kumaran | 71fb6c8 | 2010-04-28 17:39:48 +0000 | [diff] [blame] | 518 | def test_chunked_head(self): |
| 519 | chunked_start = ( |
| 520 | 'HTTP/1.1 200 OK\r\n' |
| 521 | 'Transfer-Encoding: chunked\r\n\r\n' |
| 522 | 'a\r\n' |
| 523 | 'hello world\r\n' |
| 524 | '1\r\n' |
| 525 | 'd\r\n' |
| 526 | ) |
| 527 | sock = FakeSocket(chunked_start + '0\r\n') |
| 528 | resp = client.HTTPResponse(sock, method="HEAD") |
| 529 | resp.begin() |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 530 | self.assertEqual(resp.read(), b'') |
| 531 | self.assertEqual(resp.status, 200) |
| 532 | self.assertEqual(resp.reason, 'OK') |
Senthil Kumaran | 0b99883 | 2010-06-04 17:27:11 +0000 | [diff] [blame] | 533 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b5b9c8c | 2013-02-06 10:31:57 +0200 | [diff] [blame] | 534 | self.assertFalse(resp.closed) |
| 535 | resp.close() |
| 536 | self.assertTrue(resp.closed) |
Senthil Kumaran | 71fb6c8 | 2010-04-28 17:39:48 +0000 | [diff] [blame] | 537 | |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 538 | def test_readinto_chunked_head(self): |
| 539 | chunked_start = ( |
| 540 | 'HTTP/1.1 200 OK\r\n' |
| 541 | 'Transfer-Encoding: chunked\r\n\r\n' |
| 542 | 'a\r\n' |
| 543 | 'hello world\r\n' |
| 544 | '1\r\n' |
| 545 | 'd\r\n' |
| 546 | ) |
| 547 | sock = FakeSocket(chunked_start + '0\r\n') |
| 548 | resp = client.HTTPResponse(sock, method="HEAD") |
| 549 | resp.begin() |
| 550 | b = bytearray(5) |
| 551 | n = resp.readinto(b) |
| 552 | self.assertEqual(n, 0) |
| 553 | self.assertEqual(bytes(b), b'\x00'*5) |
| 554 | self.assertEqual(resp.status, 200) |
| 555 | self.assertEqual(resp.reason, 'OK') |
| 556 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b6c86fd | 2013-02-06 10:35:40 +0200 | [diff] [blame] | 557 | self.assertFalse(resp.closed) |
| 558 | resp.close() |
| 559 | self.assertTrue(resp.closed) |
Antoine Pitrou | 38d9643 | 2011-12-06 22:33:57 +0100 | [diff] [blame] | 560 | |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 561 | def test_negative_content_length(self): |
Jeremy Hylton | 8206695 | 2008-12-15 03:08:30 +0000 | [diff] [blame] | 562 | sock = FakeSocket( |
| 563 | 'HTTP/1.1 200 OK\r\nContent-Length: -1\r\n\r\nHello\r\n') |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 564 | resp = client.HTTPResponse(sock, method="GET") |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 565 | resp.begin() |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 566 | self.assertEqual(resp.read(), b'Hello\r\n') |
Antoine Pitrou | beec61a | 2013-02-02 22:49:34 +0100 | [diff] [blame] | 567 | self.assertTrue(resp.isclosed()) |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 568 | |
Benjamin Peterson | 6accb98 | 2009-03-02 22:50:25 +0000 | [diff] [blame] | 569 | def test_incomplete_read(self): |
| 570 | sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n') |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 571 | resp = client.HTTPResponse(sock, method="GET") |
Benjamin Peterson | 6accb98 | 2009-03-02 22:50:25 +0000 | [diff] [blame] | 572 | resp.begin() |
| 573 | try: |
| 574 | resp.read() |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 575 | except client.IncompleteRead as i: |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 576 | self.assertEqual(i.partial, b'Hello\r\n') |
Benjamin Peterson | 6accb98 | 2009-03-02 22:50:25 +0000 | [diff] [blame] | 577 | self.assertEqual(repr(i), |
| 578 | "IncompleteRead(7 bytes read, 3 more expected)") |
| 579 | self.assertEqual(str(i), |
| 580 | "IncompleteRead(7 bytes read, 3 more expected)") |
Antoine Pitrou | beec61a | 2013-02-02 22:49:34 +0100 | [diff] [blame] | 581 | self.assertTrue(resp.isclosed()) |
Benjamin Peterson | 6accb98 | 2009-03-02 22:50:25 +0000 | [diff] [blame] | 582 | else: |
| 583 | self.fail('IncompleteRead expected') |
Benjamin Peterson | 6accb98 | 2009-03-02 22:50:25 +0000 | [diff] [blame] | 584 | |
Jeremy Hylton | 636950f | 2009-03-28 04:34:21 +0000 | [diff] [blame] | 585 | def test_epipe(self): |
| 586 | sock = EPipeSocket( |
| 587 | "HTTP/1.0 401 Authorization Required\r\n" |
| 588 | "Content-type: text/html\r\n" |
| 589 | "WWW-Authenticate: Basic realm=\"example\"\r\n", |
| 590 | b"Content-Length") |
| 591 | conn = client.HTTPConnection("example.com") |
| 592 | conn.sock = sock |
Andrew Svetlov | 0832af6 | 2012-12-18 23:10:48 +0200 | [diff] [blame] | 593 | self.assertRaises(OSError, |
Jeremy Hylton | 636950f | 2009-03-28 04:34:21 +0000 | [diff] [blame] | 594 | lambda: conn.request("PUT", "/url", "body")) |
| 595 | resp = conn.getresponse() |
| 596 | self.assertEqual(401, resp.status) |
| 597 | self.assertEqual("Basic realm=\"example\"", |
| 598 | resp.getheader("www-authenticate")) |
Christian Heimes | a612dc0 | 2008-02-24 13:08:18 +0000 | [diff] [blame] | 599 | |
Senthil Kumaran | 5466bf1 | 2010-12-18 16:55:23 +0000 | [diff] [blame] | 600 | # Test lines overflowing the max line size (_MAXLINE in http.client) |
| 601 | |
| 602 | def test_overflowing_status_line(self): |
| 603 | body = "HTTP/1.1 200 Ok" + "k" * 65536 + "\r\n" |
| 604 | resp = client.HTTPResponse(FakeSocket(body)) |
| 605 | self.assertRaises((client.LineTooLong, client.BadStatusLine), resp.begin) |
| 606 | |
| 607 | def test_overflowing_header_line(self): |
| 608 | body = ( |
| 609 | 'HTTP/1.1 200 OK\r\n' |
| 610 | 'X-Foo: bar' + 'r' * 65536 + '\r\n\r\n' |
| 611 | ) |
| 612 | resp = client.HTTPResponse(FakeSocket(body)) |
| 613 | self.assertRaises(client.LineTooLong, resp.begin) |
| 614 | |
| 615 | def test_overflowing_chunked_line(self): |
| 616 | body = ( |
| 617 | 'HTTP/1.1 200 OK\r\n' |
| 618 | 'Transfer-Encoding: chunked\r\n\r\n' |
| 619 | + '0' * 65536 + 'a\r\n' |
| 620 | 'hello world\r\n' |
| 621 | '0\r\n' |
| 622 | ) |
| 623 | resp = client.HTTPResponse(FakeSocket(body)) |
| 624 | resp.begin() |
| 625 | self.assertRaises(client.LineTooLong, resp.read) |
| 626 | |
Senthil Kumaran | 9c29f86 | 2012-04-29 10:20:46 +0800 | [diff] [blame] | 627 | def test_early_eof(self): |
| 628 | # Test httpresponse with no \r\n termination, |
| 629 | body = "HTTP/1.1 200 Ok" |
| 630 | sock = FakeSocket(body) |
| 631 | resp = client.HTTPResponse(sock) |
| 632 | resp.begin() |
| 633 | self.assertEqual(resp.read(), b'') |
| 634 | self.assertTrue(resp.isclosed()) |
Serhiy Storchaka | b5b9c8c | 2013-02-06 10:31:57 +0200 | [diff] [blame] | 635 | self.assertFalse(resp.closed) |
| 636 | resp.close() |
| 637 | self.assertTrue(resp.closed) |
Senthil Kumaran | 9c29f86 | 2012-04-29 10:20:46 +0800 | [diff] [blame] | 638 | |
Antoine Pitrou | 90e4774 | 2013-01-02 22:10:47 +0100 | [diff] [blame] | 639 | def test_delayed_ack_opt(self): |
| 640 | # Test that Nagle/delayed_ack optimistaion works correctly. |
| 641 | |
| 642 | # For small payloads, it should coalesce the body with |
| 643 | # headers, resulting in a single sendall() call |
| 644 | conn = client.HTTPConnection('example.com') |
| 645 | sock = FakeSocket(None) |
| 646 | conn.sock = sock |
| 647 | body = b'x' * (conn.mss - 1) |
| 648 | conn.request('POST', '/', body) |
| 649 | self.assertEqual(sock.sendall_calls, 1) |
| 650 | |
| 651 | # For large payloads, it should send the headers and |
| 652 | # then the body, resulting in more than one sendall() |
| 653 | # call |
| 654 | conn = client.HTTPConnection('example.com') |
| 655 | sock = FakeSocket(None) |
| 656 | conn.sock = sock |
| 657 | body = b'x' * conn.mss |
| 658 | conn.request('POST', '/', body) |
| 659 | self.assertGreater(sock.sendall_calls, 1) |
| 660 | |
Georg Brandl | 4cbd1e3 | 2006-02-17 22:01:08 +0000 | [diff] [blame] | 661 | class OfflineTest(TestCase): |
| 662 | def test_responses(self): |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 663 | self.assertEqual(client.responses[client.NOT_FOUND], "Not Found") |
Georg Brandl | 4cbd1e3 | 2006-02-17 22:01:08 +0000 | [diff] [blame] | 664 | |
Gregory P. Smith | b406637 | 2010-01-03 03:28:29 +0000 | [diff] [blame] | 665 | |
| 666 | class SourceAddressTest(TestCase): |
| 667 | def setUp(self): |
| 668 | self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 669 | self.port = support.bind_port(self.serv) |
| 670 | self.source_port = support.find_unused_port() |
| 671 | self.serv.listen(5) |
| 672 | self.conn = None |
| 673 | |
| 674 | def tearDown(self): |
| 675 | if self.conn: |
| 676 | self.conn.close() |
| 677 | self.conn = None |
| 678 | self.serv.close() |
| 679 | self.serv = None |
| 680 | |
| 681 | def testHTTPConnectionSourceAddress(self): |
| 682 | self.conn = client.HTTPConnection(HOST, self.port, |
| 683 | source_address=('', self.source_port)) |
| 684 | self.conn.connect() |
| 685 | self.assertEqual(self.conn.sock.getsockname()[1], self.source_port) |
| 686 | |
| 687 | @unittest.skipIf(not hasattr(client, 'HTTPSConnection'), |
| 688 | 'http.client.HTTPSConnection not defined') |
| 689 | def testHTTPSConnectionSourceAddress(self): |
| 690 | self.conn = client.HTTPSConnection(HOST, self.port, |
| 691 | source_address=('', self.source_port)) |
| 692 | # We don't test anything here other the constructor not barfing as |
| 693 | # this code doesn't deal with setting up an active running SSL server |
| 694 | # for an ssl_wrapped connect() to actually return from. |
| 695 | |
| 696 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 697 | class TimeoutTest(TestCase): |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 698 | PORT = None |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 699 | |
| 700 | def setUp(self): |
| 701 | self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 702 | TimeoutTest.PORT = support.bind_port(self.serv) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 703 | self.serv.listen(5) |
| 704 | |
| 705 | def tearDown(self): |
| 706 | self.serv.close() |
| 707 | self.serv = None |
| 708 | |
| 709 | def testTimeoutAttribute(self): |
Jeremy Hylton | 3a38c91 | 2007-08-14 17:08:07 +0000 | [diff] [blame] | 710 | # This will prove that the timeout gets through HTTPConnection |
| 711 | # and into the socket. |
| 712 | |
Georg Brandl | f78e02b | 2008-06-10 17:40:04 +0000 | [diff] [blame] | 713 | # default -- use global socket timeout |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 714 | self.assertTrue(socket.getdefaulttimeout() is None) |
Georg Brandl | f78e02b | 2008-06-10 17:40:04 +0000 | [diff] [blame] | 715 | socket.setdefaulttimeout(30) |
| 716 | try: |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 717 | httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT) |
Georg Brandl | f78e02b | 2008-06-10 17:40:04 +0000 | [diff] [blame] | 718 | httpConn.connect() |
| 719 | finally: |
| 720 | socket.setdefaulttimeout(None) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 721 | self.assertEqual(httpConn.sock.gettimeout(), 30) |
| 722 | httpConn.close() |
| 723 | |
Georg Brandl | f78e02b | 2008-06-10 17:40:04 +0000 | [diff] [blame] | 724 | # no timeout -- do not use global socket default |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 725 | self.assertTrue(socket.getdefaulttimeout() is None) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 726 | socket.setdefaulttimeout(30) |
| 727 | try: |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 728 | httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT, |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 729 | timeout=None) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 730 | httpConn.connect() |
| 731 | finally: |
Georg Brandl | f78e02b | 2008-06-10 17:40:04 +0000 | [diff] [blame] | 732 | socket.setdefaulttimeout(None) |
| 733 | self.assertEqual(httpConn.sock.gettimeout(), None) |
| 734 | httpConn.close() |
| 735 | |
| 736 | # a value |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 737 | httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT, timeout=30) |
Georg Brandl | f78e02b | 2008-06-10 17:40:04 +0000 | [diff] [blame] | 738 | httpConn.connect() |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 739 | self.assertEqual(httpConn.sock.gettimeout(), 30) |
| 740 | httpConn.close() |
| 741 | |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 742 | |
| 743 | class HTTPSTest(TestCase): |
| 744 | |
| 745 | def setUp(self): |
| 746 | if not hasattr(client, 'HTTPSConnection'): |
| 747 | self.skipTest('ssl support required') |
| 748 | |
| 749 | def make_server(self, certfile): |
| 750 | from test.ssl_servers import make_https_server |
Antoine Pitrou | da23259 | 2013-02-05 21:20:51 +0100 | [diff] [blame] | 751 | return make_https_server(self, certfile=certfile) |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 752 | |
| 753 | def test_attributes(self): |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 754 | # simple test to check it's storing the timeout |
| 755 | h = client.HTTPSConnection(HOST, TimeoutTest.PORT, timeout=30) |
| 756 | self.assertEqual(h.timeout, 30) |
| 757 | |
| 758 | def _check_svn_python_org(self, resp): |
| 759 | # Just a simple check that everything went fine |
| 760 | server_string = resp.getheader('server') |
| 761 | self.assertIn('Apache', server_string) |
| 762 | |
| 763 | def test_networked(self): |
| 764 | # Default settings: no cert verification is done |
| 765 | support.requires('network') |
| 766 | with support.transient_internet('svn.python.org'): |
| 767 | h = client.HTTPSConnection('svn.python.org', 443) |
| 768 | h.request('GET', '/') |
| 769 | resp = h.getresponse() |
| 770 | self._check_svn_python_org(resp) |
| 771 | |
| 772 | def test_networked_good_cert(self): |
| 773 | # We feed a CA cert that validates the server's cert |
| 774 | import ssl |
| 775 | support.requires('network') |
| 776 | with support.transient_internet('svn.python.org'): |
| 777 | context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) |
| 778 | context.verify_mode = ssl.CERT_REQUIRED |
| 779 | context.load_verify_locations(CACERT_svn_python_org) |
| 780 | h = client.HTTPSConnection('svn.python.org', 443, context=context) |
| 781 | h.request('GET', '/') |
| 782 | resp = h.getresponse() |
| 783 | self._check_svn_python_org(resp) |
| 784 | |
| 785 | def test_networked_bad_cert(self): |
| 786 | # We feed a "CA" cert that is unrelated to the server's cert |
| 787 | import ssl |
| 788 | support.requires('network') |
| 789 | with support.transient_internet('svn.python.org'): |
| 790 | context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) |
| 791 | context.verify_mode = ssl.CERT_REQUIRED |
| 792 | context.load_verify_locations(CERT_localhost) |
| 793 | h = client.HTTPSConnection('svn.python.org', 443, context=context) |
| 794 | with self.assertRaises(ssl.SSLError): |
| 795 | h.request('GET', '/') |
| 796 | |
| 797 | def test_local_good_hostname(self): |
| 798 | # The (valid) cert validates the HTTP hostname |
| 799 | import ssl |
Brett Cannon | 252365b | 2011-08-04 22:43:11 -0700 | [diff] [blame] | 800 | server = self.make_server(CERT_localhost) |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 801 | context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) |
| 802 | context.verify_mode = ssl.CERT_REQUIRED |
| 803 | context.load_verify_locations(CERT_localhost) |
| 804 | h = client.HTTPSConnection('localhost', server.port, context=context) |
| 805 | h.request('GET', '/nonexistent') |
| 806 | resp = h.getresponse() |
| 807 | self.assertEqual(resp.status, 404) |
Brett Cannon | 252365b | 2011-08-04 22:43:11 -0700 | [diff] [blame] | 808 | del server |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 809 | |
| 810 | def test_local_bad_hostname(self): |
| 811 | # The (valid) cert doesn't validate the HTTP hostname |
| 812 | import ssl |
Brett Cannon | 252365b | 2011-08-04 22:43:11 -0700 | [diff] [blame] | 813 | server = self.make_server(CERT_fakehostname) |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 814 | context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) |
| 815 | context.verify_mode = ssl.CERT_REQUIRED |
| 816 | context.load_verify_locations(CERT_fakehostname) |
| 817 | h = client.HTTPSConnection('localhost', server.port, context=context) |
| 818 | with self.assertRaises(ssl.CertificateError): |
| 819 | h.request('GET', '/') |
| 820 | # Same with explicit check_hostname=True |
| 821 | h = client.HTTPSConnection('localhost', server.port, context=context, |
| 822 | check_hostname=True) |
| 823 | with self.assertRaises(ssl.CertificateError): |
| 824 | h.request('GET', '/') |
| 825 | # With check_hostname=False, the mismatching is ignored |
| 826 | h = client.HTTPSConnection('localhost', server.port, context=context, |
| 827 | check_hostname=False) |
| 828 | h.request('GET', '/nonexistent') |
| 829 | resp = h.getresponse() |
| 830 | self.assertEqual(resp.status, 404) |
Brett Cannon | 252365b | 2011-08-04 22:43:11 -0700 | [diff] [blame] | 831 | del server |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 832 | |
Petri Lehtinen | e119c40 | 2011-10-26 21:29:15 +0300 | [diff] [blame] | 833 | @unittest.skipIf(not hasattr(client, 'HTTPSConnection'), |
| 834 | 'http.client.HTTPSConnection not available') |
Łukasz Langa | a5a9a9c | 2011-10-18 21:17:39 +0200 | [diff] [blame] | 835 | def test_host_port(self): |
| 836 | # Check invalid host_port |
| 837 | |
| 838 | for hp in ("www.python.org:abc", "user:password@www.python.org"): |
| 839 | self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp) |
| 840 | |
| 841 | for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", |
| 842 | "fe80::207:e9ff:fe9b", 8000), |
| 843 | ("www.python.org:443", "www.python.org", 443), |
| 844 | ("www.python.org:", "www.python.org", 443), |
| 845 | ("www.python.org", "www.python.org", 443), |
| 846 | ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443), |
| 847 | ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", |
| 848 | 443)): |
| 849 | c = client.HTTPSConnection(hp) |
| 850 | self.assertEqual(h, c.host) |
| 851 | self.assertEqual(p, c.port) |
| 852 | |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 853 | |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 854 | class RequestBodyTest(TestCase): |
| 855 | """Test cases where a request includes a message body.""" |
| 856 | |
| 857 | def setUp(self): |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 858 | self.conn = client.HTTPConnection('example.com') |
Jeremy Hylton | 636950f | 2009-03-28 04:34:21 +0000 | [diff] [blame] | 859 | self.conn.sock = self.sock = FakeSocket("") |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 860 | self.conn.sock = self.sock |
| 861 | |
| 862 | def get_headers_and_fp(self): |
| 863 | f = io.BytesIO(self.sock.data) |
| 864 | f.readline() # read the request line |
Jeremy Hylton | 7c1692d | 2009-03-27 21:31:03 +0000 | [diff] [blame] | 865 | message = client.parse_headers(f) |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 866 | return message, f |
| 867 | |
| 868 | def test_manual_content_length(self): |
| 869 | # Set an incorrect content-length so that we can verify that |
| 870 | # it will not be over-ridden by the library. |
| 871 | self.conn.request("PUT", "/url", "body", |
| 872 | {"Content-Length": "42"}) |
| 873 | message, f = self.get_headers_and_fp() |
| 874 | self.assertEqual("42", message.get("content-length")) |
| 875 | self.assertEqual(4, len(f.read())) |
| 876 | |
| 877 | def test_ascii_body(self): |
| 878 | self.conn.request("PUT", "/url", "body") |
| 879 | message, f = self.get_headers_and_fp() |
| 880 | self.assertEqual("text/plain", message.get_content_type()) |
Raymond Hettinger | 7beae8a | 2011-01-06 05:34:17 +0000 | [diff] [blame] | 881 | self.assertIsNone(message.get_charset()) |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 882 | self.assertEqual("4", message.get("content-length")) |
| 883 | self.assertEqual(b'body', f.read()) |
| 884 | |
| 885 | def test_latin1_body(self): |
| 886 | self.conn.request("PUT", "/url", "body\xc1") |
| 887 | message, f = self.get_headers_and_fp() |
| 888 | self.assertEqual("text/plain", message.get_content_type()) |
Raymond Hettinger | 7beae8a | 2011-01-06 05:34:17 +0000 | [diff] [blame] | 889 | self.assertIsNone(message.get_charset()) |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 890 | self.assertEqual("5", message.get("content-length")) |
| 891 | self.assertEqual(b'body\xc1', f.read()) |
| 892 | |
| 893 | def test_bytes_body(self): |
| 894 | self.conn.request("PUT", "/url", b"body\xc1") |
| 895 | message, f = self.get_headers_and_fp() |
| 896 | self.assertEqual("text/plain", message.get_content_type()) |
Raymond Hettinger | 7beae8a | 2011-01-06 05:34:17 +0000 | [diff] [blame] | 897 | self.assertIsNone(message.get_charset()) |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 898 | self.assertEqual("5", message.get("content-length")) |
| 899 | self.assertEqual(b'body\xc1', f.read()) |
| 900 | |
| 901 | def test_file_body(self): |
Victor Stinner | 18d15cb | 2011-09-21 01:09:04 +0200 | [diff] [blame] | 902 | self.addCleanup(support.unlink, support.TESTFN) |
Brett Cannon | 77b7de6 | 2010-10-29 23:31:11 +0000 | [diff] [blame] | 903 | with open(support.TESTFN, "w") as f: |
| 904 | f.write("body") |
| 905 | with open(support.TESTFN) as f: |
| 906 | self.conn.request("PUT", "/url", f) |
| 907 | message, f = self.get_headers_and_fp() |
| 908 | self.assertEqual("text/plain", message.get_content_type()) |
Raymond Hettinger | 7beae8a | 2011-01-06 05:34:17 +0000 | [diff] [blame] | 909 | self.assertIsNone(message.get_charset()) |
Brett Cannon | 77b7de6 | 2010-10-29 23:31:11 +0000 | [diff] [blame] | 910 | self.assertEqual("4", message.get("content-length")) |
| 911 | self.assertEqual(b'body', f.read()) |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 912 | |
| 913 | def test_binary_file_body(self): |
Victor Stinner | 18d15cb | 2011-09-21 01:09:04 +0200 | [diff] [blame] | 914 | self.addCleanup(support.unlink, support.TESTFN) |
Brett Cannon | 77b7de6 | 2010-10-29 23:31:11 +0000 | [diff] [blame] | 915 | with open(support.TESTFN, "wb") as f: |
| 916 | f.write(b"body\xc1") |
| 917 | with open(support.TESTFN, "rb") as f: |
| 918 | self.conn.request("PUT", "/url", f) |
| 919 | message, f = self.get_headers_and_fp() |
| 920 | self.assertEqual("text/plain", message.get_content_type()) |
Raymond Hettinger | 7beae8a | 2011-01-06 05:34:17 +0000 | [diff] [blame] | 921 | self.assertIsNone(message.get_charset()) |
Brett Cannon | 77b7de6 | 2010-10-29 23:31:11 +0000 | [diff] [blame] | 922 | self.assertEqual("5", message.get("content-length")) |
| 923 | self.assertEqual(b'body\xc1', f.read()) |
Jeremy Hylton | 236654b | 2009-03-27 20:24:34 +0000 | [diff] [blame] | 924 | |
Senthil Kumaran | 9f8dc44 | 2010-08-02 11:04:58 +0000 | [diff] [blame] | 925 | |
| 926 | class HTTPResponseTest(TestCase): |
| 927 | |
| 928 | def setUp(self): |
| 929 | body = "HTTP/1.1 200 Ok\r\nMy-Header: first-value\r\nMy-Header: \ |
| 930 | second-value\r\n\r\nText" |
| 931 | sock = FakeSocket(body) |
| 932 | self.resp = client.HTTPResponse(sock) |
| 933 | self.resp.begin() |
| 934 | |
| 935 | def test_getting_header(self): |
| 936 | header = self.resp.getheader('My-Header') |
| 937 | self.assertEqual(header, 'first-value, second-value') |
| 938 | |
| 939 | header = self.resp.getheader('My-Header', 'some default') |
| 940 | self.assertEqual(header, 'first-value, second-value') |
| 941 | |
| 942 | def test_getting_nonexistent_header_with_string_default(self): |
| 943 | header = self.resp.getheader('No-Such-Header', 'default-value') |
| 944 | self.assertEqual(header, 'default-value') |
| 945 | |
| 946 | def test_getting_nonexistent_header_with_iterable_default(self): |
| 947 | header = self.resp.getheader('No-Such-Header', ['default', 'values']) |
| 948 | self.assertEqual(header, 'default, values') |
| 949 | |
| 950 | header = self.resp.getheader('No-Such-Header', ('default', 'values')) |
| 951 | self.assertEqual(header, 'default, values') |
| 952 | |
| 953 | def test_getting_nonexistent_header_without_default(self): |
| 954 | header = self.resp.getheader('No-Such-Header') |
| 955 | self.assertEqual(header, None) |
| 956 | |
| 957 | def test_getting_header_defaultint(self): |
| 958 | header = self.resp.getheader('No-Such-Header',default=42) |
| 959 | self.assertEqual(header, 42) |
| 960 | |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 961 | def test_main(verbose=None): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 962 | support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest, |
Antoine Pitrou | 803e6d6 | 2010-10-13 10:36:15 +0000 | [diff] [blame] | 963 | HTTPSTest, RequestBodyTest, SourceAddressTest, |
Senthil Kumaran | 9f8dc44 | 2010-08-02 11:04:58 +0000 | [diff] [blame] | 964 | HTTPResponseTest) |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 965 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 966 | if __name__ == '__main__': |
| 967 | test_main() |