mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 14:58:38 +00:00
Re-enable simple multipart form parsing and preview.
This commit is contained in:
parent
62e51018d0
commit
74c51df580
@ -1,3 +1,4 @@
|
||||
import re
|
||||
import urwid
|
||||
import common
|
||||
from .. import utils, encoding, flow
|
||||
@ -18,18 +19,21 @@ VIEW_CONTENT_PRETTY_TYPE_AUTO = 0
|
||||
VIEW_CONTENT_PRETTY_TYPE_JSON = 1
|
||||
VIEW_CONTENT_PRETTY_TYPE_XML = 2
|
||||
VIEW_CONTENT_PRETTY_TYPE_URLENCODED = 3
|
||||
VIEW_CONTENT_PRETTY_TYPE_MULTIPART = 4
|
||||
|
||||
CONTENT_PRETTY_NAMES = {
|
||||
VIEW_CONTENT_PRETTY_TYPE_JSON: "JSON",
|
||||
VIEW_CONTENT_PRETTY_TYPE_XML: "XML",
|
||||
VIEW_CONTENT_PRETTY_TYPE_URLENCODED: "URL-encoded"
|
||||
VIEW_CONTENT_PRETTY_TYPE_URLENCODED: "URL-encoded",
|
||||
VIEW_CONTENT_PRETTY_TYPE_MULTIPART: "Multipart Form"
|
||||
}
|
||||
|
||||
CONTENT_TYPES_MAP = {
|
||||
"text/html": VIEW_CONTENT_PRETTY_TYPE_XML,
|
||||
"application/json": VIEW_CONTENT_PRETTY_TYPE_JSON,
|
||||
"text/xml": VIEW_CONTENT_PRETTY_TYPE_XML,
|
||||
"multipart/form-data": VIEW_CONTENT_PRETTY_TYPE_URLENCODED
|
||||
"multipart/form-data": VIEW_CONTENT_PRETTY_TYPE_MULTIPART,
|
||||
"application/x-www-form-urlencoded": VIEW_CONTENT_PRETTY_TYPE_URLENCODED,
|
||||
}
|
||||
|
||||
def trailer(clen, txt):
|
||||
@ -95,8 +99,16 @@ def view_json(hdrs, content):
|
||||
return "JSON", txt
|
||||
|
||||
|
||||
# FIXME
|
||||
def view_formdata(content, boundary):
|
||||
def view_multipart(hdrs, content):
|
||||
v = hdrs.get("content-type")
|
||||
if v:
|
||||
v = utils.parse_content_type(v[0])
|
||||
if not v:
|
||||
return
|
||||
boundary = v[2].get("boundary")
|
||||
if not boundary:
|
||||
return
|
||||
|
||||
rx = re.compile(r'\bname="([^"]+)"')
|
||||
keys = []
|
||||
vals = []
|
||||
@ -118,7 +130,7 @@ def view_formdata(content, boundary):
|
||||
key = "header",
|
||||
val = "text"
|
||||
))
|
||||
return r
|
||||
return "Multipart form", r
|
||||
|
||||
|
||||
def view_urlencoded(hdrs, content):
|
||||
@ -135,7 +147,8 @@ def view_urlencoded(hdrs, content):
|
||||
PRETTY_FUNCTION_MAP = {
|
||||
VIEW_CONTENT_PRETTY_TYPE_XML: view_xmlish,
|
||||
VIEW_CONTENT_PRETTY_TYPE_JSON: view_json,
|
||||
VIEW_CONTENT_PRETTY_TYPE_URLENCODED: view_urlencoded
|
||||
VIEW_CONTENT_PRETTY_TYPE_URLENCODED: view_urlencoded,
|
||||
VIEW_CONTENT_PRETTY_TYPE_MULTIPART: view_multipart,
|
||||
}
|
||||
|
||||
def get_view_func(viewmode, pretty_type, hdrs, content):
|
||||
|
@ -78,6 +78,32 @@ class uContentView(libpry.AutoTree):
|
||||
def test_view_raw(self):
|
||||
assert cv.view_hex([], "foo")
|
||||
|
||||
def test_view_multipart(self):
|
||||
v = """
|
||||
--AaB03x
|
||||
Content-Disposition: form-data; name="submit-name"
|
||||
|
||||
Larry
|
||||
--AaB03x
|
||||
""".strip()
|
||||
h = flow.ODictCaseless(
|
||||
[("Content-Type", "multipart/form-data; boundary=AaB03x")]
|
||||
)
|
||||
assert cv.view_multipart(h, v)
|
||||
|
||||
h = flow.ODictCaseless()
|
||||
assert not cv.view_multipart(h, v)
|
||||
|
||||
h = flow.ODictCaseless(
|
||||
[("Content-Type", "multipart/form-data")]
|
||||
)
|
||||
assert not cv.view_multipart(h, v)
|
||||
|
||||
h = flow.ODictCaseless(
|
||||
[("Content-Type", "unparseable")]
|
||||
)
|
||||
assert not cv.view_multipart(h, v)
|
||||
|
||||
def test_get_content_view(self):
|
||||
r = cv.get_content_view(
|
||||
cv.VIEW_CONTENT_RAW,
|
||||
|
Loading…
Reference in New Issue
Block a user