aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addons
diff options
context:
space:
mode:
authorMatías Lang <yo@matiaslang.me>2019-01-13 23:53:51 -0300
committerMatías Lang <yo@matiaslang.me>2019-01-13 23:53:51 -0300
commit674f92a7c164c538047c970fc42194211856276a (patch)
treedfdc1499dd28f0a2a8310d815680f7c6431ac694 /mitmproxy/addons
parenteab4174b87c7ba0b7dab2c8d7e0b13253833abe8 (diff)
downloadmitmproxy-674f92a7c164c538047c970fc42194211856276a.tar.gz
mitmproxy-674f92a7c164c538047c970fc42194211856276a.tar.bz2
mitmproxy-674f92a7c164c538047c970fc42194211856276a.zip
Refactor curl_command and httpie_command
To avoid calling to shlex.quote many times
Diffstat (limited to 'mitmproxy/addons')
-rw-r--r--mitmproxy/addons/export.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/mitmproxy/addons/export.py b/mitmproxy/addons/export.py
index 761b3915..04c0349a 100644
--- a/mitmproxy/addons/export.py
+++ b/mitmproxy/addons/export.py
@@ -23,10 +23,10 @@ def curl_command(f: flow.Flow) -> str:
request = f.request.copy() # type: ignore
request.decode(strict=False)
for k, v in request.headers.items(multi=True):
- args += ["-H", shlex.quote("%s:%s" % (k, v))]
+ args += ["-H", "%s:%s" % (k, v)]
if request.method != "GET":
- args += ["-X", shlex.quote(request.method)]
- args.append(shlex.quote(request.url))
+ args += ["-X", request.method]
+ args.append(request.url)
if request.content:
try:
content = strutils.always_str(request.content)
@@ -36,20 +36,19 @@ def curl_command(f: flow.Flow) -> str:
raise exceptions.CommandError("Request content must be valid unicode")
args += [
"--data-binary",
- shlex.quote(strutils.always_str(request.content))
+ strutils.always_str(request.content)
]
- return ' '.join(args)
+ return ' '.join(shlex.quote(arg) for arg in args)
def httpie_command(f: flow.Flow) -> str:
raise_if_missing_request(f)
request = f.request.copy() # type: ignore
- args = ["http"]
- args.append(shlex.quote(request.method))
request.decode(strict=False)
- args.append(shlex.quote(request.url))
+ args = ["http", request.method, request.url]
for k, v in request.headers.items(multi=True):
- args.append(shlex.quote("%s:%s" % (k, v)))
+ args.append("%s:%s" % (k, v))
+ cmd = ' '.join(shlex.quote(arg) for arg in args)
if request.content:
try:
content = strutils.always_str(request.content)
@@ -57,8 +56,8 @@ def httpie_command(f: flow.Flow) -> str:
# shlex.quote doesn't support a bytes object
# see https://github.com/python/cpython/pull/10871
raise exceptions.CommandError("Request content must be valid unicode")
- args += ["<<<", shlex.quote(content)]
- return ' '.join(args)
+ cmd += " <<< " + shlex.quote(content)
+ return cmd
def raw(f: flow.Flow) -> bytes: