|
| 1 | +# WebSocket API |
| 2 | + |
| 3 | +This is the WebSocket API specification. |
| 4 | + |
| 5 | +# Message format |
| 6 | + |
| 7 | +Bidirectional messages are implemented in the form of JSON objects. Each API request sent from this addon has a |
| 8 | +transaction ID in the `id` field, which should be duplicated in the API response from the client. |
| 9 | + |
| 10 | +_This `id` field isn't mentioned in any object documentation - remember to include it in the responses, or else the |
| 11 | +addon won't know what to do with them._ |
| 12 | + |
| 13 | +# Multiple clients |
| 14 | +This addon supports chaining multiple clients. Requests and responses will be sent through each client in the order of connection, |
| 15 | +such that the modifications done by one client become the input of the next. |
| 16 | + |
| 17 | +# Flow stages |
| 18 | + |
| 19 | +The WebSocket API sends an API request object at four stages in every HTTP flow. At each stage, the client is expected |
| 20 | +to send a certain API response object back. |
| 21 | + |
| 22 | +Failure to respond to an API request will leave the flow hanging indefinitely. |
| 23 | + |
| 24 | +The following is a brief overview of the interception flow. |
| 25 | +> `>` indicates a message sent from the addon to the |
| 26 | +> client |
| 27 | +`<` indicates a message sent from the client to the addon |
| 28 | + |
| 29 | +`>` Pre-request stage (summarised request and existing fake response messages) |
| 30 | +`<` Pre-request settings (which complete messages to send to the client) |
| 31 | +`>` Request stage (the complete request and existing fake response messages) |
| 32 | +`<` Request overwrites (request and response modifications) |
| 33 | + |
| 34 | +`>` Pre-response stage (summarised request and response messages) |
| 35 | +`<` Pre-response settings (which complete messages to send to the client) |
| 36 | +`>` Response stage (the complete request and response messages) |
| 37 | +`<` Response overwrites (request and response modifications) |
| 38 | + |
| 39 | +The next few sections describe each stage in detail. |
| 40 | + |
| 41 | +## Pre-request stage |
| 42 | + |
| 43 | +At the `pre_request` stage, message set settings are requested from the client. These settings determine which HTTP |
| 44 | +messages are sent to the client at the request stage. |
| 45 | + |
| 46 | +This allows for the client to prevent being sent messages that it doesn't need, which can minimize resource usage. |
| 47 | + |
| 48 | +If the sending of both the request and the response messages is disabled, the request stage will be skipped. |
| 49 | + |
| 50 | +### API request object |
| 51 | + |
| 52 | +| Key | Type | Optional? | |
| 53 | +|--------------------|---------------------------|--------------------------------------------| |
| 54 | +| `request_summary` | A request summary object | No | |
| 55 | +| `response_summary` | A response summary object | Yes (provided if set by an earlier client) | |
| 56 | + |
| 57 | +### API response object |
| 58 | + |
| 59 | +The client should respond to this API request with a message set settings object. |
| 60 | + |
| 61 | +## Request stage |
| 62 | + |
| 63 | +At the request stage, the complete request (and any response set by earlier clients) can be sent to the client. At this |
| 64 | +point, the client can replace both the request and response data. |
| 65 | + |
| 66 | +If response data is provided by the client, the request will never be sent. |
| 67 | + |
| 68 | +### API request object |
| 69 | + |
| 70 | +The addon will send a message set object to the client. |
| 71 | + |
| 72 | +### API response object |
| 73 | + |
| 74 | +The client must respond to this API request with another message set object. |
| 75 | +Any messages in the new message set will overwrite the corresponding messages in the original message set if provided. |
| 76 | + |
| 77 | +## Pre-response stage |
| 78 | + |
| 79 | +This stage serves a similar purpose to the pre-request stage, but it occurs after a request has been sent and a response |
| 80 | +has been received. |
| 81 | + |
| 82 | +As with the pre-request stage, if the sending of both the request and the response messages is disabled, the response |
| 83 | +stage will be skipped. |
| 84 | + |
| 85 | +### API request object |
| 86 | + |
| 87 | +| Key | Type | Optional? | |
| 88 | +|--------------------|---------------------------|-----------| |
| 89 | +| `request_summary` | A request summary object | No | |
| 90 | +| `response_summary` | A response summary object | No | |
| 91 | + |
| 92 | +### API response object |
| 93 | + |
| 94 | +The client must respond to this API request with a message set settings object. |
| 95 | + |
| 96 | +## Response stage |
| 97 | + |
| 98 | +This stage works in the same way as the request stage. |
| 99 | + |
| 100 | +### API request object |
| 101 | + |
| 102 | +The addon will send a message set object to the client. |
| 103 | + |
| 104 | +### API response object |
| 105 | + |
| 106 | +The client must respond to this API request with another message set object. |
| 107 | +Any messages in the new message set will overwrite the corresponding messages in the original message set if provided. |
| 108 | + |
| 109 | +Setting request data at this stage will affect the mitmproxy UI and later clients. |
| 110 | + |
| 111 | +# JSON objects |
| 112 | + |
| 113 | +## Message set settings |
| 114 | + |
| 115 | +| Key | Value | Type | Optional? | |
| 116 | +|-----------------|----------------------------------------------------------|---------|--------------------------| |
| 117 | +| `send_request` | `true` if the full request should be sent to the client | Boolean | Yes (default is `false`) | |
| 118 | +| `send_response` | `true` if the full response should be sent to the client | Boolean | Yes (default is `false`) | |
| 119 | + |
| 120 | +## Message set |
| 121 | + |
| 122 | +| Key | Type | Optional? | |
| 123 | +|------------|-------------------|-------------------------------------------------------------------------------------------------------------| |
| 124 | +| `request` | A request object | Yes (provided by the addon if requested in the message set settings, or by the client to set request data) | |
| 125 | +| `response` | A response object | Yes (provided by the addon if requested in the message set settings, or by the client to set response data) | |
| 126 | + |
| 127 | +## Request summary |
| 128 | + |
| 129 | +| Key | Value | Type | Optional? | |
| 130 | +|----------|----------------------------------------|--------------|-----------| |
| 131 | +| `method` | The HTTP method (e.g. "GET" or "POST") | String | No | |
| 132 | +| `url` | The request URL | String (URI) | No | |
| 133 | + |
| 134 | +## Request |
| 135 | + |
| 136 | +| Key | Value | Type | Optional? | |
| 137 | +|-----------|----------------------------------------|------------------------------|-----------| |
| 138 | +| `method` | The HTTP method (e.g. "GET" or "POST") | String | No | |
| 139 | +| `url` | The request URL | String (URI) | No | |
| 140 | +| `headers` | The request headers | Object(String: List(String)) | No | |
| 141 | +| `body` | The request body | String (base64) | No | |
| 142 | + |
| 143 | +## Response summary |
| 144 | + |
| 145 | +| Key | Value | Type | Optional? | |
| 146 | +|---------------|----------------------------|---------|------------------------------------------------------------| |
| 147 | +| `status_code` | The response status code | Integer | No | |
| 148 | +| `reason` | The response reason phrase | String | Yes (a default value based on the status code may be used) | |
| 149 | + |
| 150 | +## Response |
| 151 | + |
| 152 | +| Key | Value | Type | Optional? | |
| 153 | +|---------------|----------------------------|------------------------------|------------------------------------------------------------| |
| 154 | +| `status_code` | The response status code | Integer | No | |
| 155 | +| `reason` | The response reason phrase | String | Yes (a default value based on the status code may be used) | |
| 156 | +| `headers` | The response headers | Object(String: List(String)) | No | |
| 157 | +| `body` | The response body | String (base64) | No | |
0 commit comments