http icon indicating copy to clipboard operation
http copied to clipboard

(Draft) Feat: ability to abort requests

Open dfidalg0 opened this issue 3 years ago • 0 comments

This is basically the same as #193, but as a draft PR as suggested by @thomasvidas.

The proposal is to have a request abort API that behaves similar to the standard fetch API.

const controller = new AbortController();

Http.request({
  url: 'some.api.com',
  method: 'get',
  signal: controller.signal
}).then(...);

...

if (requestShouldBeAborted) {
  controller.abort();
}

Currently, the implementation supports only web and Android, since I don't have a Macbook and don't know how to properly implement this in Swift. So, any help is welcome :nerd_face:

For those willing to implement the iOS part, the main ideia is

  • Pick the signal parameter ({ aborted: boolean; abortCode: integer; }) passed down to the plugin call and track the corresponding socket (requests that don't have a signal shouldn't be tracked).
  • Implement a plugin method called __abortRequest that receives a { abortCode: integer } and interrupts the corresponding socket.

dfidalg0 avatar Nov 18 '21 15:11 dfidalg0