Display warning message for each cookie parsing error.

This commit is contained in:
Bastian Kleineidam 2011-08-03 19:27:36 +02:00
parent ef6a3b99af
commit 48413de418
2 changed files with 15 additions and 11 deletions

View file

@ -39,6 +39,7 @@ class CookieJar (object):
@synchronized(_lock)
def add (self, headers, scheme, host, path):
"""Parse cookie values, add to cache."""
errors = []
jar = self.cache.setdefault(host, set())
for h in headers.getallmatchingheaders("Set-Cookie"):
# RFC 2109 (Netscape) cookie type
@ -49,8 +50,9 @@ class CookieJar (object):
if not cookie.is_expired():
jar.add(cookie)
except cookies.CookieError, msg:
log.debug(LOG_CACHE,
"Invalid cookie %r for %s:%s%s: %s", h, scheme, host, path, msg)
errmsg = "Invalid cookie %r for %s:%s%s: %s" % (
h, scheme, host, path, msg)
errors.append(errmsg)
for h in headers.getallmatchingheaders("Set-Cookie2"):
# RFC 2965 cookie type
try:
@ -60,10 +62,11 @@ class CookieJar (object):
if not cookie.is_expired():
jar.add(cookie)
except cookies.CookieError, msg:
log.debug(LOG_CACHE,
"Invalid cookie2 %r for %s:%s%s: %s", h, scheme, host, path, msg)
errmsg = "Invalid cookie2 %r for %s:%s%s: %s" % (
h, scheme, host, path, msg)
errors.append(errmsg)
self.cache[host] = jar
return jar
return errors
@synchronized(_lock)
def get (self, scheme, host, port, path):

View file

@ -466,12 +466,13 @@ class HttpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport):
for c in self.cookies:
self.add_info(_("Sent cookie: %(cookie)s.") %
{"cookie": c})
jar = self.aggregate.cookies.add(self.headers, self.urlparts[0],
self.urlparts[1], self.urlparts[2])
if not jar:
self.add_warning(_("Could not store cookies from headers: %(headers)s.") %
{'headers': str(self.headers)},
tag=WARN_HTTP_COOKIE_STORE_ERROR)
errors = self.aggregate.cookies.add(self.headers,
self.urlparts[0], self.urlparts[1], self.urlparts[2])
if errors:
self.add_warning(
_("Could not store cookies from headers: %(error)s.") %
{'error': "\n".join(errors)},
tag=WARN_HTTP_COOKIE_STORE_ERROR)
if response.status >= 200:
self.set_result(u"%r %s" % (response.status, response.reason))
else: