Skip to content

Commit 8951a2c

Browse files
committed
feat: Expose the flow ID through the WebSocket API
1 parent 5cb008f commit 8951a2c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

API.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ While the type of API request object varies with each stage, they each have the
2727
| Key | Type |
2828
|-----------|--------------------------------------------|
2929
| `stage` | The stage of the flow (e.g. `pre-request`) |
30+
| `flow_id` | An ID unique to the flow |
3031

3132
Failure to respond to an API request will leave the flow hanging indefinitely.
3233

src/mitmproxy_remote_interceptions.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def _perform_transaction(
106106

107107
return api_response
108108

109-
async def _handle_http_message(self, http_flow: http.HTTPFlow, is_request: bool):
109+
async def _handle_http_message(self, flow: http.HTTPFlow, is_request: bool):
110110
# Iterate over every connected client, allowing them to intercept the message one by one such that the output
111111
# of the previous client (accepted by the provided handler) is the input of the next client.
112112
# Copy the websocket list to avoid modification during iteration.
@@ -119,9 +119,10 @@ async def _handle_http_message(self, http_flow: http.HTTPFlow, is_request: bool)
119119
requested_message_settings: MessageSetSettings = MessageSetSettings.from_json(
120120
await self._perform_transaction(websocket, {
121121
"stage": "pre_request" if is_request else "pre_response",
122-
"request_summary": _request_to_summary_json(http_flow.request),
122+
"flow_id": flow.id,
123+
"request_summary": _request_to_summary_json(flow.request),
123124
"response_summary":
124-
_response_to_summary_json(http_flow.response) if http_flow.response is not None else None,
125+
_response_to_summary_json(flow.response) if flow.response is not None else None,
125126
})
126127
)
127128

@@ -133,17 +134,18 @@ async def _handle_http_message(self, http_flow: http.HTTPFlow, is_request: bool)
133134
message_set: MessageSet = MessageSet.from_json(
134135
await self._perform_transaction(websocket, {
135136
"stage": "request" if is_request else "response",
136-
"request": _request_to_json(http_flow.request) if requested_message_settings.send_request else None,
137-
"response": _response_to_json(http_flow.response) if (requested_message_settings.send_response
138-
and http_flow.response is not None) else None,
137+
"flow_id": flow.id,
138+
"request": _request_to_json(flow.request) if requested_message_settings.send_request else None,
139+
"response": _response_to_json(flow.response) if (requested_message_settings.send_response
140+
and flow.response is not None) else None,
139141
})
140142
)
141143

142144
# Use the received messages.
143145
if message_set.request is not None:
144-
http_flow.request = message_set.request
146+
flow.request = message_set.request
145147
if message_set.response is not None:
146-
http_flow.response = message_set.response
148+
flow.response = message_set.response
147149

148150

149151
addons: list[object] = [

0 commit comments

Comments
 (0)