diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-04-14 15:14:36 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-04-14 15:14:36 +1200 |
commit | ab7e2857cc9095c4cee8ca9b569c16516aa520ba (patch) | |
tree | 37ceeb9370695e4ad40b07696d780bd1d5f19bf1 /libmproxy | |
parent | e17eacd8d77c78daa88d8f89ace990463378d98d (diff) | |
download | mitmproxy-ab7e2857cc9095c4cee8ca9b569c16516aa520ba.tar.gz mitmproxy-ab7e2857cc9095c4cee8ca9b569c16516aa520ba.tar.bz2 mitmproxy-ab7e2857cc9095c4cee8ca9b569c16516aa520ba.zip |
New get_cookies for HttpResponse
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/protocol/http.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index cd9458f2..da8eaa01 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -902,20 +902,21 @@ class HTTPResponse(HTTPMessage): self.headers["set-cookie"] = c def get_cookies(self): - cookie_headers = self.headers.get("set-cookie") - if not cookie_headers: - return None + """ + Get the contents of all Set-Cookie headers. - cookies = [] - for header in cookie_headers: - pairs = [pair.partition("=") for pair in header.split(';')] - cookie_name = pairs[0][0] # the key of the first key/value pairs - cookie_value = pairs[0][2] # the value of the first key/value pairs - cookie_parameters = { - key.strip().lower(): value.strip() for key, sep, value in pairs[1:] - } - cookies.append((cookie_name, (cookie_value, cookie_parameters))) - return dict(cookies) + Returns a possibly empty ODict, where keys are cookie name strings, + and values are [value, attr] lists. Value is a string, and attr is + an ODictCaseless containing cookie attributes. Within attrs, unary + attributes (e.g. HTTPOnly) are indicated by a Null value. + """ + ret = [] + for header in self.headers["set-cookie"]: + v = http_cookies.parse_set_cookie_header(header) + if v: + name, value, attrs = v + ret.append([name, [value, attrs]]) + return odict.ODict(ret) class HTTPFlow(Flow): |