In order to halt and continue an HTTP request from JavaScript methods, aside from the AbortController, there are a few approaches you can take.
i) One method involves using the fetch() call within a promise, allowing you to choose whether to reject or resolve the request based on whether you wish to pause or reject it. However, this approach does not support the ability to resume the request.
ii) The AbortController can be used to achieve a similar functionality by pausing requests (aborting the ongoing request) and then resuming the requests again using the same controller.
const controller = new AbortController();
const signal = controller.signal;
fetch(url, {..., signal: signal}).then(response => ...);
To pause:
controller.abort()
To resume:
fetch(url, {..., signal: signal}).then(response => ...);
Essentially, this involves making another request using the same controller object.
For more information, you can refer to: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
iii) If you are interested in pausing/resuming stream processing through HTTP, you can refer to the following sample method I discovered: https://gist.github.com/Grigore147/4611134
var Http = require('http');
var Fs = require('fs');
// Provide a URL to a large video file
var url = 'url';
var path = 'save_path';
var downloaded = 0;
var percents = 0;
var size = 0;
var request = Http.request(url, function(response) {
size = parseInt(response.headers['content-length']);
response.on('data', function(chunk) {
downloaded += chunk.length;
percents = parseInt((downloaded / size) * 100);
console.log(percents +'%', downloaded +'/'+size);
});
response.on('error', function(error) {
console.log(error);
});
response.pipe(Fs.createWriteStream(path));
setTimeout(function() {
response.pause(); console.log('stream paused');
setTimeout(function() {
response.resume(); console.log('stream resumed');
}, 5000);
}, 5000);
}).end();