Skip to content

Instantly share code, notes, and snippets.

@richardscarrott
Created January 9, 2020 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardscarrott/6d02efb0a150aa36d5e1ab793d921e4a to your computer and use it in GitHub Desktop.
Save richardscarrott/6d02efb0a150aa36d5e1ab793d921e4a to your computer and use it in GitHub Desktop.
HTTP retry
const express = require('express');
console.log(process.version);
const app = express();
app.get('/hello', (req, res) => {
console.log('HANDLING REQUEST');
res.setHeader('content-type', 'application/json');
res.flushHeaders(); // `flushHeaders` to prevent http client from retrying and therefore invoking this handler multiple times.
res.destroy();
});
app.listen(9000, () => {
console.log('Listening');
});
// https://blogs.oracle.com/ravello/beware-http-requests-automatic-retries
@nfcampos
Copy link

With POST, and without flushHeaders (request done using fetch in Chrome console) the browser does not repeat the request and HANDLING REQUEST is printed only once)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment