clarified documentation from e-mail discussion
authorShivaram Lingamneni <slingamn@cs.stanford.edu>
Wed, 25 Apr 2012 20:40:17 +0000 (13:40 -0700)
committerShivaram Lingamneni <slingamn@cs.stanford.edu>
Wed, 2 May 2012 00:00:19 +0000 (17:00 -0700)
AUTHORS.rst
requests/cookies.py

index 6d4f9793357ef40bf4ea900816e402e872914b0d..2f7de0e127699afe024c486355c0db75feacf2a2 100644 (file)
@@ -96,4 +96,4 @@ Patches and Suggestions
 - Michael Newman <newmaniese@gmail.com>
 - Jonty Wareing <jonty@jonty.co.uk>
 - Shivaram Lingamneni
-- Miguel (dhagrow)
+- Miguel Turner
index bb68031798b99b3b8bcc2104d25efb94afed7f8b..7b50b4f97c77f5c1d15b4893ad9ea6a2b539c1bc 100644 (file)
@@ -87,14 +87,20 @@ class MockResponse(object):
         self._headers.getheaders(name)
 
 def extract_cookies_to_jar(jar, request, response):
-    """Extract the cookies from the headers of `response`, into `jar`."""
-    if response._original_response is None:
-        # TODO why would this happen?
-        return
-    req = MockRequest(request)
-    # pull out the HTTPMessage with the headers and put it in the mock:
-    res = MockResponse(response._original_response.msg)
-    jar.extract_cookies(res, req)
+    """Extract the cookies from the response into a CookieJar.
+
+    :param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
+    :param request: our own requests.Request object
+    :param response: urllib3.HTTPResponse object
+    """
+    # the _original_response field is the wrapped httplib.HTTPResponse object,
+    # and in safe mode, it may be None if the request didn't actually complete.
+    # in that case, just skip the cookie extraction.
+    if response._original_response is not None:
+        req = MockRequest(request)
+        # pull out the HTTPMessage with the headers and put it in the mock:
+        res = MockResponse(response._original_response.msg)
+        jar.extract_cookies(res, req)
 
 def get_cookie_header(jar, request):
     """Produce an appropriate Cookie header string to be sent with `request`, or None."""