diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-03-26 18:17:36 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-03-26 18:17:36 +0100 |
commit | 04f2467e84905d44483469cf43ada4ec44faa203 (patch) | |
tree | 9076642f7439a877d1839293739b75d3c0f805c5 /libmproxy/protocol/http.py | |
parent | 9854379046a5464f4fd638785bafca87b91a495a (diff) | |
parent | 423530fc258ddd09642de401c4fd5cf71ed06be6 (diff) | |
download | mitmproxy-04f2467e84905d44483469cf43ada4ec44faa203.tar.gz mitmproxy-04f2467e84905d44483469cf43ada4ec44faa203.tar.bz2 mitmproxy-04f2467e84905d44483469cf43ada4ec44faa203.zip |
Merge branch 'master' of github.com:mitmproxy/mitmproxy
Diffstat (limited to 'libmproxy/protocol/http.py')
-rw-r--r-- | libmproxy/protocol/http.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 00086c21..c763db4c 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -15,6 +15,7 @@ from ..proxy.connection import ServerConnection from .. import encoding, utils, controller, stateobject, proxy HDR_FORM_URLENCODED = "application/x-www-form-urlencoded" +HDR_FORM_MULTIPART = "multipart/form-data" CONTENT_MISSING = 0 @@ -509,6 +510,19 @@ class HTTPRequest(HTTPMessage): """ self.headers["Host"] = [self.host] + def get_form(self): + """ + Retrieves the URL-encoded or multipart form data, returning an ODict object. + Returns an empty ODict if there is no data or the content-type + indicates non-form data. + """ + if self.content: + if self.headers.in_any("content-type", HDR_FORM_URLENCODED, True): + return self.get_form_urlencoded() + elif self.headers.in_any("content-type", HDR_FORM_MULTIPART, True): + return self.get_form_multipart() + return ODict([]) + def get_form_urlencoded(self): """ Retrieves the URL-encoded form data, returning an ODict object. @@ -516,7 +530,12 @@ class HTTPRequest(HTTPMessage): indicates non-form data. """ if self.content and self.headers.in_any("content-type", HDR_FORM_URLENCODED, True): - return ODict(utils.urldecode(self.content)) + return ODict(utils.urldecode(self.content)) + return ODict([]) + + def get_form_multipart(self): + if self.content and self.headers.in_any("content-type", HDR_FORM_MULTIPART, True): + return ODict(utils.multipartdecode(self.headers, self.content)) return ODict([]) def set_form_urlencoded(self, odict): |