multipart-fix

This commit is contained in:
rjt-gupta 2018-12-14 21:31:34 +05:30
parent 70777a1b6e
commit 4df325335b
3 changed files with 15 additions and 5 deletions

View File

@ -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):

View File

@ -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):
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): 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

View File

@ -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