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

Support AbortSignal in http requests #2478

Open
2 tasks done
paulbrimicombe opened this issue May 9, 2023 · 0 comments
Open
2 tasks done

Support AbortSignal in http requests #2478

paulbrimicombe opened this issue May 9, 2023 · 0 comments
Labels

Comments

@paulbrimicombe
Copy link

Please avoid duplicates

Context

Since NodeJS 14.17 and 15.3 it has been possible to abort an HTTP(S) request using an AbortSignal (see https://nodejs.org/api/http.html#httprequesturl-options-callback).

A simple example of this might be:

const https = require("https");

// Abort the request after 1 ms
const signal = AbortSignal.timeout(1);

// Make the request
https
  .request("https://www.google.co.uk", { signal })
  .on("error", (error) => {
    console.log(error.message, "CAUSED BY", error.cause?.message);
  })
  .on("response", (res) => {
    res
      .on("data", () => {
        // do something with the response body
      })
      .on("close", () => console.log("Finished"));
  })
  .end();

This doesn't appear to be supported by nock — if I create a scope for https://www.google.co.uk, the request is not aborted after the appropriate time (e.g. if I add a delay using nock).

This appears to be the NodeJS source code that adds support for Abort Signals:

https://github.com/nodejs/node/blob/259ea3ed59a655ed0263746365c4538ec9c561a5/lib/internal/streams/add-abort-signal.js#L27-L53

Alternatives

No response

If the feature request is accepted, would you be willing to submit a PR?

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

No branches or pull requests

1 participant