comparison mercurial/httpclient/tests/test_proxy_support.py @ 14376:a75e0f4ba0ab

httpclient: import revision fc731618702a of py-nonblocking-http
author Augie Fackler <durin42@gmail.com>
date Tue, 17 May 2011 10:28:03 -0500
parents 5c3de67e7402
children 24dbef11f477
comparison
equal deleted inserted replaced
14375:436e5379d7ba 14376:a75e0f4ba0ab
41 Useful for https proxy tests because we have to read from the 41 Useful for https proxy tests because we have to read from the
42 socket during _connect rather than later on. 42 socket during _connect rather than later on.
43 """ 43 """
44 def s(*args, **kwargs): 44 def s(*args, **kwargs):
45 sock = util.MockSocket(*args, **kwargs) 45 sock = util.MockSocket(*args, **kwargs)
46 sock.data = data[:] 46 sock.early_data = data[:]
47 return sock 47 return sock
48 return s 48 return s
49 49
50 50
51 class ProxyHttpTest(util.HttpTestBase, unittest.TestCase): 51 class ProxyHttpTest(util.HttpTestBase, unittest.TestCase):
95 'Server: BogusServer 1.0\r\n', 95 'Server: BogusServer 1.0\r\n',
96 'Content-Length: 10\r\n', 96 'Content-Length: 10\r\n',
97 '\r\n' 97 '\r\n'
98 '1234567890']) 98 '1234567890'])
99 con._connect() 99 con._connect()
100 con.sock.data.extend(['HTTP/1.1 200 OK\r\n', 100 con.sock.data = ['HTTP/1.1 200 OK\r\n',
101 'Server: BogusServer 1.0\r\n', 101 'Server: BogusServer 1.0\r\n',
102 'Content-Length: 10\r\n', 102 'Content-Length: 10\r\n',
103 '\r\n' 103 '\r\n'
104 '1234567890' 104 '1234567890'
105 ]) 105 ]
106 connect_sent = con.sock.sent
107 con.sock.sent = ''
106 con.request('GET', '/') 108 con.request('GET', '/')
107 109
108 expected_req = ('CONNECT 1.2.3.4:443 HTTP/1.0\r\n' 110 expected_connect = ('CONNECT 1.2.3.4:443 HTTP/1.0\r\n'
109 'Host: 1.2.3.4\r\n' 111 'Host: 1.2.3.4\r\n'
110 'accept-encoding: identity\r\n' 112 'accept-encoding: identity\r\n'
111 '\r\n' 113 '\r\n')
112 'GET / HTTP/1.1\r\n' 114 expected_request = ('GET / HTTP/1.1\r\n'
113 'Host: 1.2.3.4\r\n' 115 'Host: 1.2.3.4\r\n'
114 'accept-encoding: identity\r\n\r\n') 116 'accept-encoding: identity\r\n\r\n')
115 117
116 self.assertEqual(('127.0.0.42', 4242), con.sock.sa) 118 self.assertEqual(('127.0.0.42', 4242), con.sock.sa)
117 self.assertStringEqual(expected_req, con.sock.sent) 119 self.assertStringEqual(expected_connect, connect_sent)
120 self.assertStringEqual(expected_request, con.sock.sent)
118 resp = con.getresponse() 121 resp = con.getresponse()
119 self.assertEqual(resp.status, 200) 122 self.assertEqual(resp.status, 200)
120 self.assertEqual('1234567890', resp.read()) 123 self.assertEqual('1234567890', resp.read())
121 self.assertEqual(['BogusServer 1.0'], 124 self.assertEqual(['BogusServer 1.0'],
122 resp.headers.getheaders('server')) 125 resp.headers.getheaders('server'))