Debugging tools
Mock Sets
Record responses from captured traffic, a whole domain or a HAR file, and replay them without the network to demo, test or debug an app offline.
A mock set is a snapshot of an API’s responses. While it’s on, Cloak Proxy answers matching requests from the snapshot instead of the network, so an app behaves exactly as it did when you recorded it. Use mock sets to demo an app without Wi-Fi, to keep testing while a backend is down, or to reproduce a bug from a teammate’s HAR file.
Record a domain and replay it offline
Section titled “Record a domain and replay it offline”-
Use your app normally so Cloak Proxy captures the screens you need.
-
In the sidebar, right-click the domain and choose Mock api.example.com Offline (the menu item shows the domain’s name).
Cloak Proxy turns every captured response from that host into a mock set named
api.example.com (offline), turns Mock Sets on and opens the set. -
Use the app again. Requests to the host are answered from the set, with a
Mockbadge in the traffic list. Nothing reaches the server. -
When you’re done, clear the set’s checkbox or turn Mock Sets off.
A mock set with one recorded response. With Offline on, nothing reaches api.example.com while the set is on.
- A mock set: its response count and hosts.
- Offline: unrecorded requests to these hosts get a 404.
- Match recordings regardless of the query string.
- Filter the responses by URL.
- A recorded response. Select it to edit it; clear its checkbox to skip it.
- New mock set from selected requests or a file.
Ways to create a mock set
Section titled “Ways to create a mock set”| From | How | The set is named |
|---|---|---|
| Selected requests | Select requests in the traffic list, right-click one of them and choose Tools › Mock N Responses (or Mock This Response for one). Or search for Mock Selected Responses in Search Everything. | After the request, or N requests from <host> |
| Selected requests, in the Tools window | Click + under the list and choose From Selected Requests. | N selected requests |
| A whole domain | Right-click the domain in the sidebar and choose Mock … Offline. | <host> (offline) |
| A file | Click + and choose Import HAR or Session…, or click Import HAR or Session… when the list is empty. Accepts .har, .cloaksession, Charles .chlsj and .json files. |
The file name |
| A command line run | cloakctl run --mock FILE answers requests from a recorded HAR or session. |
The file name |
Each way turns Mock Sets on. Only requests with a response are recorded; encrypted tunnels and requests still in progress are skipped.
What’s recorded
Section titled “What’s recorded”For each request, a mock set keeps the method, the full URL, the status code, the headers and the body.
- The body is stored decompressed, so you can read and edit it.
Content-Encoding,Content-Length,Transfer-Encoding,ConnectionandKeep-Aliveheaders are left out. Cloak Proxy sets the right length when it replays the response.
Mock set settings
Section titled “Mock set settings”| Setting | Default | What it does |
|---|---|---|
| Name | Shown in the list and in the offline 404 message. | |
| Offline: answer unrecorded requests to these hosts with 404 | On | Requests to any host in the set that have no recording get a 404 instead of going to the server. The note below the toggle lists the hosts. |
| Ignore query strings when matching | Off | Matches /users?page=2 with a recording of /users?page=1. |
With Offline off, recorded requests are answered from the set, and anything else goes to the real server.
The offline 404
Section titled “The offline 404”An unrecorded request to a host in an Offline set gets:
HTTP/1.1 404 Not FoundContent-Type: application/jsonX-Cloak-Proxy: mock-miss
{"error":"No response recorded in mock set “api.example.com (offline)” for GET /v1/settings"}Look for X-Cloak-Proxy: mock-miss to find screens you didn’t record.
Edit recorded responses
Section titled “Edit recorded responses”Select a set to see its responses.
| Column | What it shows |
|---|---|
| On | Clear it to skip this response. |
| Method | The request method. |
| URL | The full recorded URL. |
| Status | The status code, red for 400 and above. |
| Size | The body size. |
Type in Filter URLs to narrow the table. Select a response and click the minus button next to the filter to remove it.
Select a response to edit it below the table:
| Field | Notes |
|---|---|
| Status code | Any number; the reason phrase is shown next to it. |
| Headers | Edit, Add or remove headers. |
| Body | Text bodies are editable, with JSON validation, Format and Minify. Binary bodies show Binary body, N. It’s replayed as recorded. and can’t be edited. |
Changes apply to the next matching request.
How requests are matched
Section titled “How requests are matched”A request is answered from a set when its method and URL match a recorded response:
- The method must be the same (case doesn’t matter).
- The scheme and host are compared without case. Default ports (
:443,:80) and#fragmentsare ignored. - The path and query values are compared exactly, including case.
- Query parameter order doesn’t matter:
?b=2&a=1matches a recording of?a=1&b=2. - With Ignore query strings when matching on, the query string is ignored completely.
- If the same request was recorded more than once, the most recent recording wins.
- Responses whose On checkbox is cleared are skipped.
Several mock sets
Section titled “Several mock sets”Sets are checked from the top of the list down, and the first set that answers wins (First matching set wins). Drag sets to change the order. Clear a set’s checkbox to skip it, or right-click it and choose Delete.
How Mock Sets works with other tools
Section titled “How Mock Sets works with other tools”- Map Local runs first: a matching Map Local rule wins over a mock set.
- Mock Sets match the request after request scripts and the request breakpoint. Map Remote runs after Mock Sets, so a mocked request is never remapped.
- Mocked responses still go through No Caching, response scripts, the response breakpoint and the download delay of Network Conditions. You can script small changes on top of a recording, or test the recording on a slow network.