mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Fix detection of URL-encoded forms.
Thanks to Paul Capestany <capestany@gmail.com> for reporting this.
This commit is contained in:
parent
ddc9155c24
commit
25fa596cd6
@ -146,6 +146,21 @@ class ODict:
|
||||
elements.append("")
|
||||
return "\r\n".join(elements)
|
||||
|
||||
def in_any(self, key, value, caseless=False):
|
||||
"""
|
||||
Do any of the values matching key contain value?
|
||||
|
||||
If caseless is true, value comparison is case-insensitive.
|
||||
"""
|
||||
if caseless:
|
||||
value = value.lower()
|
||||
for i in self[key]:
|
||||
if caseless:
|
||||
i = i.lower()
|
||||
if value in i:
|
||||
return True
|
||||
return False
|
||||
|
||||
def match_re(self, expr):
|
||||
"""
|
||||
Match the regular expression against each (key, value) pair. For
|
||||
@ -347,8 +362,7 @@ class Request(HTTPMsg):
|
||||
Returns an empty ODict if there is no data or the content-type
|
||||
indicates non-form data.
|
||||
"""
|
||||
hv = [i.lower() for i in self.headers["content-type"]]
|
||||
if HDR_FORM_URLENCODED in hv:
|
||||
if self.headers.in_any("content-type", HDR_FORM_URLENCODED, True):
|
||||
return ODict(utils.urldecode(self.content))
|
||||
return ODict([])
|
||||
|
||||
|
@ -345,7 +345,7 @@ class uState(libpry.AutoTree):
|
||||
c.add_request(req)
|
||||
assert len(c.view) == 2
|
||||
c.set_limit("~q")
|
||||
assert len(c.view) == 2
|
||||
assert len(c.view) == 1
|
||||
c.set_limit("~s")
|
||||
assert len(c.view) == 1
|
||||
|
||||
@ -931,6 +931,15 @@ class uODict(libpry.AutoTree):
|
||||
nd = flow.ODict._from_state(state)
|
||||
assert nd == self.od
|
||||
|
||||
def test_in_any(self):
|
||||
self.od["one"] = ["atwoa", "athreea"]
|
||||
assert self.od.in_any("one", "two")
|
||||
assert self.od.in_any("one", "three")
|
||||
assert not self.od.in_any("one", "four")
|
||||
assert not self.od.in_any("nonexistent", "foo")
|
||||
assert not self.od.in_any("one", "TWO")
|
||||
assert self.od.in_any("one", "TWO", True)
|
||||
|
||||
def test_copy(self):
|
||||
self.od.add("foo", 1)
|
||||
self.od.add("foo", 2)
|
||||
|
Loading…
Reference in New Issue
Block a user