MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / curl_command

Function curl_command

mitmproxy/addons/export.py:63–100  ·  view source on GitHub ↗
(f: flow.Flow)

Source from the content-addressed store, hash-verified

61
62
63def curl_command(f: flow.Flow) -> str:
64 request = cleanup_request(f)
65 pop_headers(request)
66
67 args = ["curl"]
68
69 server_addr = f.server_conn.peername[0] if f.server_conn.peername else None
70
71 if (
72 ctx.options.export_preserve_original_ip
73 and server_addr
74 and request.pretty_host != server_addr
75 ):
76 resolve = f"{request.pretty_host}:{request.port}:[{server_addr}]"
77 args.append("--resolve")
78 args.append(resolve)
79
80 for k, v in request.headers.items(multi=True):
81 if k.lower() == "accept-encoding":
82 args.append("--compressed")
83 else:
84 args += ["-H", f"{k}: {v}"]
85
86 if request.method != "GET":
87 if not request.content:
88 # curl will not calculate content-length if there is no content
89 # some server/verb combinations require content-length headers
90 # (ex. nginx and POST)
91 args += ["-H", "content-length: 0"]
92
93 args += ["-X", request.method]
94
95 args.append(request.pretty_url)
96
97 command = " ".join(shlex.quote(arg) for arg in args)
98 if request.content:
99 command += f" -d {request_content_for_console(request)}"
100 return command
101
102
103def httpie_command(f: flow.Flow) -> str:

Callers 1

errorMethod · 0.90

Calls 6

cleanup_requestFunction · 0.85
pop_headersFunction · 0.85
appendMethod · 0.45
itemsMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…