Support aborting requests in handlers #2104
kettanaito
started this conversation in
Ideas
Replies: 1 comment
-
Relevant issue opened in the Interceptors: mswjs/interceptors#520. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Scope
Adds a new behavior
Compatibility
Feature description
I think it would be useful to give the user the API to abort any intercepted request in a matching request handler.
How would this work?
The
controller
API would hook into the existingrequest.signal
, or create one, if it's not defined. Internally, we will have thecontroller.signal.on('abort')
listener to know if the user aborted the request in the handler. If they did, we will translate that event to the appropriate mechanism to abort the request:Browser
request.signal
abort controller to abort the request for free.Node.js
controller.signal.on('abort')
and abort the request via appropriate means:this.abort()
on the ClientRequest instance. I'm not proposing to attach thesignal
on the request instance to have as little meddling with the user-defined signal as possible. The downside of tapping intothis.abort()
directly may be that the user-defined signal will never receive that abort event (because there's no event, we are aborting the request on the lower level).this.abort()
on the XMLHttpRequest instance.request
instance.Questions
Beta Was this translation helpful? Give feedback.
All reactions