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