mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
Merge pull request #2886 from tran-tien-dat/set-cookie
Parse Set-Cookie header more permissively. Fix #2829
This commit is contained in:
commit
16dd7f3ddf
@ -159,13 +159,17 @@ def _read_set_cookie_pairs(s: str, off=0) -> Tuple[List[TPairs], int]:
|
|||||||
if len(rhs) <= 3:
|
if len(rhs) <= 3:
|
||||||
trail, off = _read_value(s, off + 1, ";,")
|
trail, off = _read_value(s, off + 1, ";,")
|
||||||
rhs = rhs + "," + trail
|
rhs = rhs + "," + trail
|
||||||
if rhs or lhs:
|
|
||||||
|
# as long as there's a "=", we consider it a pair
|
||||||
pairs.append([lhs, rhs])
|
pairs.append([lhs, rhs])
|
||||||
|
|
||||||
# comma marks the beginning of a new cookie
|
elif lhs:
|
||||||
if off < len(s) and s[off] == ",":
|
pairs.append([lhs, rhs])
|
||||||
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
|
off += 1
|
||||||
|
|
||||||
|
@ -142,6 +142,27 @@ def test_cookie_roundtrips():
|
|||||||
|
|
||||||
def test_parse_set_cookie_pairs():
|
def test_parse_set_cookie_pairs():
|
||||||
pairs = [
|
pairs = [
|
||||||
|
[
|
||||||
|
"=",
|
||||||
|
[[
|
||||||
|
["", ""]
|
||||||
|
]]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"=;foo=bar",
|
||||||
|
[[
|
||||||
|
["", ""],
|
||||||
|
["foo", "bar"]
|
||||||
|
]]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"=;=;foo=bar",
|
||||||
|
[[
|
||||||
|
["", ""],
|
||||||
|
["", ""],
|
||||||
|
["foo", "bar"]
|
||||||
|
]]
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"=uno",
|
"=uno",
|
||||||
[[
|
[[
|
||||||
|
Loading…
Reference in New Issue
Block a user