diff options
-rw-r--r-- | mitmproxy/net/http/cookies.py | 14 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_cookies.py | 21 |
2 files changed, 30 insertions, 5 deletions
diff --git a/mitmproxy/net/http/cookies.py b/mitmproxy/net/http/cookies.py index 7bef8757..39e8d60f 100644 --- a/mitmproxy/net/http/cookies.py +++ b/mitmproxy/net/http/cookies.py @@ -159,13 +159,17 @@ def _read_set_cookie_pairs(s: str, off=0) -> Tuple[List[TPairs], int]: if len(rhs) <= 3: trail, off = _read_value(s, off + 1, ";,") rhs = rhs + "," + trail - if rhs or lhs: + + # as long as there's a "=", we consider it a pair + pairs.append([lhs, rhs]) + + elif lhs: pairs.append([lhs, rhs]) - # comma marks the beginning of a new cookie - if off < len(s) and s[off] == ",": - cookies.append(pairs) - pairs = [] + # comma marks the beginning of a new cookie + if off < len(s) and s[off] == ",": + cookies.append(pairs) + pairs = [] off += 1 diff --git a/test/mitmproxy/net/http/test_cookies.py b/test/mitmproxy/net/http/test_cookies.py index e12b0f00..74233cca 100644 --- a/test/mitmproxy/net/http/test_cookies.py +++ b/test/mitmproxy/net/http/test_cookies.py @@ -143,6 +143,27 @@ def test_cookie_roundtrips(): def test_parse_set_cookie_pairs(): pairs = [ [ + "=", + [[ + ["", ""] + ]] + ], + [ + "=;foo=bar", + [[ + ["", ""], + ["foo", "bar"] + ]] + ], + [ + "=;=;foo=bar", + [[ + ["", ""], + ["", ""], + ["foo", "bar"] + ]] + ], + [ "=uno", [[ ["", "uno"] |