mockttp
mockttp copied to clipboard
Pause the network flow and apply some changes to ongoing request
I know beforeRequest method to manipulate ongoing request data but as I know there is no delay/pause option to specify after how many seconds the request will be continue and eventually sent.
basically I need to be able to pause/hold network flow (interception) and manipulate the request just like beforeRequest method then sent to target server anytime specified (like 30 seconds later) just like the interception feature on the BurpSuite.
something like server.pause() or any solution would be appreciated, thanks.
To be clear: are you trying to pause all requests through the server, or just one specific request when it's matched?
The former is tricky, but that seems pretty unusual. The latter is definitely possible though: if you return a promise from beforeRequest, the request won't be sent until that promise resolves. You can use async callbacks for example to wait for anything you like, including a fixed time.
Like so:
await server.forAnyRequest().thenPassThrough({
beforeRequest: async (req) => {
await delay(30 * 1000); // Wait 30 seconds
// Return an empty object or undefined to send the request on as-is,
// or set props here to change it before it's forwarded:
return {};
}
});
(Assuming a common Promise-based delay function, like delay = (duration) => new Promise((resolve) => setTimeout(resolve, duration)))
Given that code, each request will be independently delayed by 30 seconds before it's sent upstream.
Does that work for you?