diff --git a/Lib/httplib.py b/Lib/httplib.py --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -723,7 +723,7 @@ endpoint passed to set_tunnel. This is done by sending a HTTP CONNECT request to the proxy server when the connection is established. - This method must be called before the HTML connection has been + This method must be called before the HTTP connection has been established. The headers argument should be a mapping of extra HTTP headers @@ -1129,7 +1129,7 @@ "Accept arguments to set the host/port, since the superclass doesn't." if host is not None: - self._conn._set_hostport(host, port) + self._conn.host, self._conn.port = self._conn._get_hostport(host, port) self._conn.connect() def getfile(self): diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -461,7 +461,11 @@ self.assertEqual(httplib.responses[httplib.NOT_FOUND], "Not Found") -class SourceAddressTest(TestCase): +class TestServer(TestCase): + """A limited socket server for testing. + + This is used by subclasses for testing http connection end points. + """ def setUp(self): self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.port = test_support.bind_port(self.serv) @@ -476,6 +480,7 @@ self.serv.close() self.serv = None +class SourceAddressTest(TestServer): def testHTTPConnectionSourceAddress(self): self.conn = httplib.HTTPConnection(HOST, self.port, source_address=('', self.source_port)) @@ -492,6 +497,22 @@ # for an ssl_wrapped connect() to actually return from. +class HTTPTest(TestServer): + def testHTTPConnection(self): + self.conn = httplib.HTTP(host=HOST, port=self.port, strict=None) + self.conn.connect() + self.assertEqual(self.conn._conn.host, HOST) + self.assertEqual(self.conn._conn.port, self.port) + + def testHTTPWithConnectHostPost(self): + constructor_host = 'localhost' + constructor_port = '8080' + self.conn = httplib.HTTP(host=constructor_host, port=constructor_port) + self.conn.connect(host=HOST, port=self.port) + self.assertEqual(self.conn._conn.host, HOST) + self.assertEqual(self.conn._conn.port, self.port) + + class TimeoutTest(TestCase): PORT = None @@ -537,6 +558,7 @@ self.assertEqual(httpConn.sock.gettimeout(), 30) httpConn.close() + class HTTPSTest(TestCase): def setUp(self): @@ -713,7 +735,8 @@ @test_support.reap_threads def test_main(verbose=None): test_support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest, - HTTPSTest, SourceAddressTest, TunnelTests) + HTTPTest, HTTPSTest, SourceAddressTest, + TunnelTests) if __name__ == '__main__': test_main()