urllib3 fix
authorKenneth Reitz <me@kennethreitz.com>
Tue, 11 Oct 2011 00:59:10 +0000 (20:59 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Tue, 11 Oct 2011 00:59:10 +0000 (20:59 -0400)
requests/packages/urllib3/connectionpool.py

index 7f974dfce62027f0c01cf3707a885409e028c09f..8da425a03290b0255436671590a38d6f6c8ccd87 100644 (file)
@@ -258,8 +258,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
             these headers completely replace any pool-specific headers.
 
         :param retries:
-            Number of retries to allow before raising
-            a MaxRetryError exception.
+            Number of retries to allow before raising a MaxRetryError exception.
 
         :param redirect:
             Automatically handle redirects (status codes 301, 302, 303, 307),
@@ -320,16 +319,19 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
                                                   timeout=timeout,
                                                   body=body, headers=headers)
 
+            # If we're going to release the connection in ``finally:``, then
+            # the request doesn't need to know about the connection. Otherwise
+            # it will also try to release it and we'll have a double-release
+            # mess.
+            response_conn = not release_conn and conn
+
+
             # Import httplib's response into our own wrapper object
             response = HTTPResponse.from_httplib(httplib_response,
                                                  pool=self,
-                                                 connection=conn,
+                                                 connection=response_conn,
                                                  **response_kw)
 
-            if release_conn:
-                # The connection will be released manually in the ``finally:``
-                response.connection = None
-
             # else:
             #     The connection will be put back into the pool when
             #     ``response.release_conn()`` is called (implicitly by