question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Delay request/response

See original GitHub issue

Hi! Would be great to have ability to delay request to backend server or response to client in onProxyReq or onProxyRes hooks respectively. I think this can be done by returning promise from this hooks (just proposal) This is needed sometimes to emulate long backend response for some concrete url, not for all of them (this can be done with devtools network throttling).

Thank you!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chimuraicommented, Jun 6, 2016

Hi @klimashkin,

Been thinking about this feature too…

Decided not to implement this for the various reasons:

  • Simulating network conditions properly is tough and is beyond the scope of this middleware.
  • Adds complexity to project
  • Other tools allow you to simulate network conditions; for example Chrome Dev Tools.

If you still want to delay (certain) requests, you can do it quite easily by chaining middlewares:

var exampleProxy = proxy({
    target: 'http://www.example.com',
    changeOrigin: true
});

var delay = function (req, res, next) {
    console.log('[debug] Delaying %s for %sms ', req.originalUrl, 10000);
    setTimeout(next, 10000);
};

app.use('/api', delay, exampleProxy);
0reactions
chimuraicommented, Jun 7, 2016

Awesome! Thanks for sharing the answer.

Think it would make an excellent candidate for a delay/latency recipe.

Do you mind creating a PR of the snippet and add it to the http-proxy-middleware recipes? https://github.com/chimurai/http-proxy-middleware/tree/master/recipes

All credits are yours of course.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delay request-response mechanism of the PTP timing ...
... the standard PTP, the timing-exchange mechanism is called a delay request-response mechanism. This mechanism identifies the path of the time information ...
Read more >
Delay between request/response - java - Stack Overflow
When there is no delay in between, response is not yet there (because it takes much more time to produce it than spent...
Read more >
Best way to approach delay on Request/Response
My goal, is to move the delay mechanisms from the parent orchestration and manage them within the children processes. If the delay fires,...
Read more >
Acceptable HTTP request-response delay - Server Fault
What is the acceptable HTTP request-response delay? I have a client-server application that takes 0.4 milliseconds as request-response ...
Read more >
Delay request response in browser - SQA Stack Exchange
Fiddler from Telerik can be used to do that. Using these examples, you can put in a specified delay in ms per KB...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found