MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / request_content_for_console

Function request_content_for_console

mitmproxy/addons/export.py:46–60  ·  view source on GitHub ↗
(request: http.Request)

Source from the content-addressed store, hash-verified

44
45
46def request_content_for_console(request: http.Request) -> str:
47 try:
48 text = request.get_text(strict=True)
49 assert text
50 except ValueError:
51 # shlex.quote doesn't support a bytes object
52 # see https://github.com/python/cpython/pull/10871
53 raise exceptions.CommandError("Request content must be valid unicode")
54 escape_control_chars = {chr(i): f"\\x{i:02x}" for i in range(32)}
55 escaped_text = "".join(escape_control_chars.get(x, x) for x in text)
56 if any(char in escape_control_chars for char in text):
57 # Escaped chars need to be unescaped by the shell to be properly inperpreted by curl and httpie
58 return f'"$(printf {shlex.quote(escaped_text)})"'
59
60 return shlex.quote(escaped_text)
61
62
63def curl_command(f: flow.Flow) -> str:

Callers 2

curl_commandFunction · 0.85
httpie_commandFunction · 0.85

Calls 3

get_textMethod · 0.45
joinMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…