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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cancellation via .destroy() and AbortSignal, and setting a timeout #203

Closed
2 tasks done
segevfiner opened this issue Jul 12, 2022 · 4 comments
Closed
2 tasks done

Comments

@segevfiner
Copy link
Contributor

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

It would be nice to support a way to cancel the request via a .destroy() method and/or an AbortSignal like the plain Node.js http.request, and also setting a timeout with a similar interface to http.request or something more suitable for light-my-request.

Motivation

https://github.com/segevfiner/axios-light-my-request-adapter

Example

const controller = new AbortController();
const req = inject(/* ... */, {signal: controller.signal, timeout: 1000});
controller.abort();
const res = await req;
@mcollina
Copy link
Member

I have absolutely no idea how this could be implemented. HTTP is not canceleable.

@segevfiner
Copy link
Contributor Author

It's essentially closing the connection, simulating a client disconnect. That's what ClientRequeat.destroy or using an AbortController with it does.

@mcollina
Copy link
Member

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@piotr-cz
Copy link

Sadly, this doesn't work when server response is a stream.

Executing controller.abort() throws an AbortError: The operation was aborted within Fastify lib

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

No branches or pull requests

4 participants