mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
multipart-fix
This commit is contained in:
parent
70777a1b6e
commit
4df325335b
@ -468,7 +468,8 @@ class Request(message.Message):
|
||||
return ()
|
||||
|
||||
def _set_multipart_form(self, value):
|
||||
raise NotImplementedError()
|
||||
self.headers["content-type"] = "multipart/form-data"
|
||||
self.content = mitmproxy.net.http.url.encode(value, self.get_text(strict=False)).encode()
|
||||
|
||||
@property
|
||||
def multipart_form(self):
|
||||
|
@ -54,16 +54,24 @@ class ResponseHeaderEditor(HeaderEditor):
|
||||
|
||||
|
||||
class RequestFormEditor(base.FocusEditor):
|
||||
title = "Edit URL-encoded Form"
|
||||
title = "Edit Form"
|
||||
columns = [
|
||||
col_text.Column("Key"),
|
||||
col_text.Column("Value")
|
||||
]
|
||||
|
||||
def get_data(self, flow):
|
||||
return flow.request.urlencoded_form.items(multi=True)
|
||||
|
||||
if "application/x-www-form-urlencoded" in flow.request.headers['Content-Type']:
|
||||
return flow.request.urlencoded_form.items(multi=True)
|
||||
|
||||
return flow.request.multipart_form.items(multi=True)
|
||||
|
||||
def set_data(self, vals, flow):
|
||||
|
||||
if "multipart/form-data" in flow.request.headers['Content-Type']:
|
||||
flow.request.multipart_form = vals
|
||||
|
||||
flow.request.urlencoded_form = vals
|
||||
|
||||
|
||||
|
@ -372,5 +372,6 @@ class TestRequestUtils:
|
||||
|
||||
def test_set_multipart_form(self):
|
||||
request = treq(content=b"foobar")
|
||||
with pytest.raises(NotImplementedError):
|
||||
request.multipart_form = "foobar"
|
||||
request.multipart_form = [("filename", "shell.jpg"), ("file_size", "1000")]
|
||||
assert request.headers['Content-Type'] == "multipart/form-data"
|
||||
assert request.content
|
||||
|
Loading…
Reference in New Issue
Block a user