MCPcopy
hub / github.com/psf/requests / extract_cookies_to_jar

Function extract_cookies_to_jar

src/requests/cookies.py:135–150  ·  view source on GitHub ↗

Extract the cookies from the response into a CookieJar. :param jar: http.cookiejar.CookieJar (not necessarily a RequestsCookieJar) :param request: our own requests.Request object :param response: urllib3.HTTPResponse object

(
    jar: CookieJar, request: PreparedRequest, response: Any
)

Source from the content-addressed store, hash-verified

133
134
135def extract_cookies_to_jar(
136 jar: CookieJar, request: PreparedRequest, response: Any
137) -> None:
138 """Extract the cookies from the response into a CookieJar.
139
140 :param jar: http.cookiejar.CookieJar (not necessarily a RequestsCookieJar)
141 :param request: our own requests.Request object
142 :param response: urllib3.HTTPResponse object
143 """
144 if not (hasattr(response, "_original_response") and response._original_response):
145 return
146 # the _original_response field is the wrapped httplib.HTTPResponse object,
147 req = MockRequest(request)
148 # pull out the HTTPMessage with the headers and put it in the mock:
149 res = MockResponse(response._original_response.msg)
150 jar.extract_cookies(res, req) # type: ignore[arg-type]
151
152
153def get_cookie_header(jar: CookieJar, request: PreparedRequest) -> str | None:

Callers 4

handle_401Method · 0.85
build_responseMethod · 0.85
resolve_redirectsMethod · 0.85
sendMethod · 0.85

Calls 2

MockRequestClass · 0.85
MockResponseClass · 0.85

Tested by

no test coverage detected