MCPcopy Index your code
hub / github.com/python/cpython / add_cookie_header

Method add_cookie_header

Lib/http/cookiejar.py:1357–1388  ·  view source on GitHub ↗

Add correct Cookie: header to request (urllib.request.Request object). The Cookie2 header is also added unless policy.hide_cookie2 is true.

(self, request)

Source from the content-addressed store, hash-verified

1355 return attrs
1356
1357 def add_cookie_header(self, request):
1358 """Add correct Cookie: header to request (urllib.request.Request object).
1359
1360 The Cookie2 header is also added unless policy.hide_cookie2 is true.
1361
1362 """
1363 _debug("add_cookie_header")
1364 self._cookies_lock.acquire()
1365 try:
1366
1367 self._policy._now = self._now = int(time.time())
1368
1369 cookies = self._cookies_for_request(request)
1370
1371 attrs = self._cookie_attrs(cookies)
1372 if attrs:
1373 if not request.has_header("Cookie"):
1374 request.add_unredirected_header(
1375 "Cookie", "; ".join(attrs))
1376
1377 # if necessary, advertise that we know RFC 2965
1378 if (self._policy.rfc2965 and not self._policy.hide_cookie2 and
1379 not request.has_header("Cookie2")):
1380 for cookie in cookies:
1381 if cookie.version != 1:
1382 request.add_unredirected_header("Cookie2", '$Version="1"')
1383 break
1384
1385 finally:
1386 self._cookies_lock.release()
1387
1388 self.clear_expired_cookies()
1389
1390 def _normalized_cookie_tuples(self, attrs_set):
1391 """Return list of tuples containing normalised cookie information.

Callers 10

test_domain_allowMethod · 0.95
test_domain_blockMethod · 0.95
test_secure_blockMethod · 0.95
test_netscape_miscMethod · 0.95
test_empty_pathMethod · 0.95
http_requestMethod · 0.45

Calls 10

_cookies_for_requestMethod · 0.95
_cookie_attrsMethod · 0.95
clear_expired_cookiesMethod · 0.95
_debugFunction · 0.85
acquireMethod · 0.45
timeMethod · 0.45
has_headerMethod · 0.45
joinMethod · 0.45
releaseMethod · 0.45

Tested by 9

test_domain_allowMethod · 0.76
test_domain_blockMethod · 0.76
test_secure_blockMethod · 0.76
test_netscape_miscMethod · 0.76
test_empty_pathMethod · 0.76