From 0fd06af30e6ec943b6ddcfed2e2cf4cd64095309 Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 22 Dec 2010 20:33:23 +0100 Subject: cookie handling WIP -.- --- module/network/CookieJar.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'module/network/CookieJar.py') diff --git a/module/network/CookieJar.py b/module/network/CookieJar.py index fc6b5e076..372e2001e 100644 --- a/module/network/CookieJar.py +++ b/module/network/CookieJar.py @@ -19,7 +19,7 @@ from cookielib import CookieJar as PyCookieJar from cookielib import Cookie - +from time import time class CookieJar(PyCookieJar): def __init__(self, pluginName=None, account=None): @@ -27,7 +27,6 @@ class CookieJar(PyCookieJar): self.plugin = pluginName self.account = account - def getCookie(self, name): print "getCookie not implemented!" return None @@ -38,4 +37,32 @@ class CookieJar(PyCookieJar): domain_initial_dot=(domain.startswith(".")), path=path, path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False) - self.set_cookie(c) \ No newline at end of file + self.set_cookie(c) + + def add_cookie_header(self, request): + self._cookies_lock.acquire() + try: + + self._policy._now = self._now = int(time()) + + cookies = self._cookies_for_request(request) + + attrs = self._cookie_attrs(cookies) + print attrs + if attrs: + if not request.has_header("Cookie"): + request.add_header( + "Cookie", "; ".join(attrs)) + + # if necessary, advertise that we know RFC 2965 + if (self._policy.rfc2965 and not self._policy.hide_cookie2 and + not request.has_header("Cookie2")): + for cookie in cookies: + if cookie.version != 1: + request.add_header("Cookie2", '$Version="1"') + break + + finally: + self._cookies_lock.release() + + self.clear_expired_cookies() -- cgit v1.2.3