def add_cookie_header(self, request):
"""Add correct Cookie: header to request (mechanize.Request object).
The Cookie2 header is also added unless policy.hide_cookie2 is true.
The request object (usually a mechanize.Request instance) must support
the methods get_full_url, get_host, is_unverifiable, get_type,
has_header, get_header, header_items and add_unredirected_header, as
documented by urllib2.
"""
debug("add_cookie_header")
cookies = self.cookies_for_request(request)
attrs = self._cookie_attrs(cookies)
if attrs:
if not request.has_header("Cookie"):
request.add_unredirected_header("Cookie", "; ".join(attrs))
# if necessary, advertise that we know RFC 2965
if self._policy.rfc2965 and not self._policy.hide_cookie2:
for cookie in cookies:
if cookie.version != 1 and not request.has_header("Cookie2"):
request.add_unredirected_header("Cookie2", '$Version="1"')
break
self.clear_expired_cookies()
_clientcookie.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录