Add correct Cookie: header to request (urllib.request.Request object). The Cookie2 header is also added unless policy.hide_cookie2 is true.
(self, request)
| 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. |