aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-08-19 13:03:21 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-08-19 13:03:21 +1200
commita77ccc406dc23a419b32cd37ca3a83542bd6681a (patch)
tree6db078678712a66c469441d504fab16748106086 /libmproxy
parent60659a89c38cdbae3f7163d46aab12f49261ab6a (diff)
downloadmitmproxy-a77ccc406dc23a419b32cd37ca3a83542bd6681a.tar.gz
mitmproxy-a77ccc406dc23a419b32cd37ca3a83542bd6681a.tar.bz2
mitmproxy-a77ccc406dc23a419b32cd37ca3a83542bd6681a.zip
Getter and setter for path component on Requests.
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/flow.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index 6076d202..868419e5 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -18,7 +18,7 @@
with their responses, and provide filtering and interception facilities.
"""
import hashlib, Cookie, cookielib, copy, re, urlparse, os
-import time
+import time, urllib
import tnetstring, filt, script, utils, encoding, proxy
from email.utils import parsedate_tz, formatdate, mktime_tz
from netlib import odict, http, certutils
@@ -397,6 +397,26 @@ class Request(HTTPMsg):
self.headers["Content-Type"] = [HDR_FORM_URLENCODED]
self.content = utils.urlencode(odict.lst)
+ def get_path_components(self):
+ """
+ Returns the path components of the URL as a list of strings.
+
+ Components are unquoted.
+ """
+ _, _, path, _, _, _ = urlparse.urlparse(self.get_url())
+ return [urllib.unquote(i) for i in path.split("/") if i]
+
+ def set_path_components(self, lst):
+ """
+ Takes a list of strings, and sets the path component of the URL.
+
+ Components are quoted.
+ """
+ lst = [urllib.quote(i, safe="") for i in lst]
+ path = "/" + "/".join(lst)
+ scheme, netloc, _, params, query, fragment = urlparse.urlparse(self.get_url())
+ self.set_url(urlparse.urlunparse([scheme, netloc, path, params, query, fragment]))
+
def get_query(self):
"""
Gets the request query string. Returns an ODict object.