Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause the network flow and apply some changes to ongoing request #130

Open
rainb3rry opened this issue Feb 9, 2023 · 1 comment
Open

Comments

@rainb3rry
Copy link

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.

@pimterry
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants