[Python-checkins] cpython (2.7): Fix Issue23300 : httplib.HTTP classe's connect method should use _get_hostport

senthil.kumaran python-checkins at python.org
Sat Jan 24 21:59:01 CET 2015


https://hg.python.org/cpython/rev/c2bba3c9424b
changeset:   94268:c2bba3c9424b
branch:      2.7
parent:      94265:94ec4d8cf104
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Sat Jan 24 12:58:10 2015 -0800
summary:
  Fix Issue23300 : httplib.HTTP classe's connect method should use _get_hostport
instead of (non-existing) _set_hostport. (Fix the regression introduced in
568041fd8090 )

files:
  Lib/httplib.py           |   4 +-
  Lib/test/test_httplib.py |  29 ++++++++++++++++++++++++++-
  2 files changed, 29 insertions(+), 4 deletions(-)


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 TestServerMixin:
+    """A limited socket server mixin.
+
+    This is used by test cases 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(TestServerMixin, TestCase):
     def testHTTPConnectionSourceAddress(self):
         self.conn = httplib.HTTPConnection(HOST, self.port,
                 source_address=('', self.source_port))
@@ -492,6 +497,24 @@
         # for an ssl_wrapped connect() to actually return from.
 
 
+class HTTPTest(TestServerMixin, TestCase):
+    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 testHTTPWithConnectHostPort(self):
+        testhost = 'unreachable.test.domain'
+        testport = '80'
+        self.conn = httplib.HTTP(host=testhost, port=testport)
+        self.conn.connect(host=HOST, port=self.port)
+        self.assertNotEqual(self.conn._conn.host, testhost)
+        self.assertNotEqual(self.conn._conn.port, testport)
+        self.assertEqual(self.conn._conn.host, HOST)
+        self.assertEqual(self.conn._conn.port, self.port)
+
+
 class TimeoutTest(TestCase):
     PORT = None
 
@@ -537,6 +560,7 @@
         self.assertEqual(httpConn.sock.gettimeout(), 30)
         httpConn.close()
 
+
 class HTTPSTest(TestCase):
 
     def setUp(self):
@@ -713,7 +737,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()

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list