diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-05-21 15:01:19 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-05-21 15:01:19 +1200 |
commit | 97f3077082371a078380ec28e1425de3dc2a0021 (patch) | |
tree | 9bb2e4dfeacec85209174672fee3e78df32dcfaf /netlib/http/response.py | |
parent | 14fb2eeb1ea734d161e84be3920691591f6531a3 (diff) | |
parent | 43d796553292a9bbf2c174e31e5e0e39e1068be1 (diff) | |
download | mitmproxy-97f3077082371a078380ec28e1425de3dc2a0021.tar.gz mitmproxy-97f3077082371a078380ec28e1425de3dc2a0021.tar.bz2 mitmproxy-97f3077082371a078380ec28e1425de3dc2a0021.zip |
Merge branch 'mhils-multidict'
Diffstat (limited to 'netlib/http/response.py')
-rw-r--r-- | netlib/http/response.py | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/netlib/http/response.py b/netlib/http/response.py index 2f06149e..7d272e10 100644 --- a/netlib/http/response.py +++ b/netlib/http/response.py @@ -1,14 +1,13 @@ from __future__ import absolute_import, print_function, division -import warnings from email.utils import parsedate_tz, formatdate, mktime_tz import time from . import cookies from .headers import Headers from .message import Message, _native, _always_bytes, MessageData +from ..multidict import MultiDictView from .. import utils -from ..odict import ODict class ResponseData(MessageData): @@ -72,29 +71,35 @@ class Response(Message): @property def cookies(self): + # type: () -> MultiDictView """ - Get the contents of all Set-Cookie headers. + The response cookies. A possibly empty :py:class:`MultiDictView`, where the keys are + cookie name strings, and values are (value, attr) tuples. 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. - A possibly empty :py:class:`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. + Caveats: + Updating the attr """ - ret = [] - for header in self.headers.get_all("set-cookie"): - v = cookies.parse_set_cookie_header(header) - if v: - name, value, attrs = v - ret.append([name, [value, attrs]]) - return ODict(ret) + return MultiDictView( + self._get_cookies, + self._set_cookies + ) + + def _get_cookies(self): + h = self.headers.get_all("set-cookie") + return tuple(cookies.parse_set_cookie_headers(h)) + + def _set_cookies(self, value): + cookie_headers = [] + for k, v in value: + header = cookies.format_set_cookie_header(k, v[0], v[1]) + cookie_headers.append(header) + self.headers.set_all("set-cookie", cookie_headers) @cookies.setter - def cookies(self, odict): - values = [] - for i in odict.lst: - header = cookies.format_set_cookie_header(i[0], i[1][0], i[1][1]) - values.append(header) - self.headers.set_all("set-cookie", values) + def cookies(self, value): + self._set_cookies(value) def refresh(self, now=None): """ |