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

Function raw

mitmproxy/addons/export.py:135–156  ·  view source on GitHub ↗

Return either the request or response if only one exists, otherwise return both

(f: flow.Flow, separator=b"\r\n\r\n")

Source from the content-addressed store, hash-verified

133
134
135def raw(f: flow.Flow, separator=b"\r\n\r\n") -> bytes:
136 """Return either the request or response if only one exists, otherwise return both"""
137 request_present = (
138 isinstance(f, http.HTTPFlow) and f.request and f.request.raw_content is not None
139 )
140 response_present = (
141 isinstance(f, http.HTTPFlow)
142 and f.response
143 and f.response.raw_content is not None
144 )
145
146 if request_present and response_present:
147 parts = [raw_request(f), raw_response(f)]
148 if isinstance(f, http.HTTPFlow) and f.websocket:
149 parts.append(f.websocket._get_formatted_messages())
150 return separator.join(parts)
151 elif request_present:
152 return raw_request(f)
153 elif response_present:
154 return raw_response(f)
155 else:
156 raise exceptions.CommandError("Can't export flow with no request or response.")
157
158
159formats: dict[str, Callable[[flow.Flow], str | bytes]] = dict(

Callers 1

errorMethod · 0.90

Calls 5

raw_requestFunction · 0.85
raw_responseFunction · 0.85
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected