aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/cookies.py
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-09-06 11:42:26 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-09-27 16:44:09 +0530
commit7802a0ba228df11f3c3defaf9a06c9f78745b701 (patch)
tree7c6a4405c7cbd5047b8b9a9430124af2abdead87 /netlib/http/cookies.py
parent90a48ccc06d01a13c52d8038b1300ff6b80a1292 (diff)
downloadmitmproxy-7802a0ba228df11f3c3defaf9a06c9f78745b701.tar.gz
mitmproxy-7802a0ba228df11f3c3defaf9a06c9f78745b701.tar.bz2
mitmproxy-7802a0ba228df11f3c3defaf9a06c9f78745b701.zip
Rename _read_pairs to _read_cookie_pairs
We will have a separate _read_set_cookie_pairs
Diffstat (limited to 'netlib/http/cookies.py')
-rw-r--r--netlib/http/cookies.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py
index cdf742ce..3b5568c9 100644
--- a/netlib/http/cookies.py
+++ b/netlib/http/cookies.py
@@ -103,12 +103,31 @@ def _read_value(s, start, delims):
return _read_until(s, start, delims)
-def _read_pairs(s, off=0):
+def _read_cookie_pairs(s, off=0):
"""
- Read pairs of lhs=rhs values while handling multiple cookies.
+ Read pairs of lhs=rhs values from Cookie headers.
off: start offset
"""
+ pairs = []
+
+ while True:
+ lhs, off = _read_key(s, off)
+ lhs = lhs.lstrip()
+
+ if lhs:
+ rhs = None
+ if off < len(s) and s[off] == "=":
+ rhs, off = _read_value(s, off + 1, ";")
+
+ pairs.append([lhs, rhs])
+
+ off += 1
+
+ if not off < len(s):
+ break
+
+ return pairs, off
cookies = []
pairs = []
@@ -185,7 +204,7 @@ def _parse_set_cookie_pairs(s):
For Set-Cookie, we support multiple cookies as described in RFC2109.
This function therefore returns a list of lists.
"""
- pairs, off_ = _read_pairs(s)
+ pairs, off_ = _read_cookie_pairs(line)
return pairs