Skip to content

Added progress capturing support, data rate limiting and aborting the response stream in node.js env;#4772

Closed
DigitalBrainJS wants to merge 15 commits intoaxios:v1.xfrom
DigitalBrainJS:next/progress
Closed

Added progress capturing support, data rate limiting and aborting the response stream in node.js env;#4772
DigitalBrainJS wants to merge 15 commits intoaxios:v1.xfrom
DigitalBrainJS:next/progress

Conversation

@DigitalBrainJS
Copy link
Collaborator

@DigitalBrainJS DigitalBrainJS commented Jun 3, 2022

(This PR is based on #4753)

  • added the ability to capture the request progress in the node.js environment. Progress listeners will handle the following data structure:
{
  loaded: 541440
  total: 10486525
  progress: 0.0516319753207092,
  bytes: 5760,
  rate: 1106392,
  estimated: 71.91002827207717
  download: true
}
  • browser progress listeners have been refactored to receive the same data structures and have the same TypeScript interface.
  • added maxRate option has been added to limit the request & response data rate.
  • added ability to abort the response stream
  • added Brotli encoding support;
  • added Accept-Encoding : gzip, deflate, gzip, br header
  • added ability to abort the response stream
  • added ability to handle request stream destroying as an abortion request; (Refers Fixing error handling when stream is destroyed while reading #3966, PR #3966 status ? #4775)
     const buf = Buffer.alloc(1024 * 1024);

      const controller = new AbortController();

      var {data} = await axios.post(LOCAL_SERVER_URL, buf, {
        responseType: 'stream',
        signal: controller.signal,
        maxRedirects: 0
      });

      setTimeout(() => {
        controller.abort();
      }, 500);

      try {
        await pipelineAsync(data, devNull());
        assert.fail('stream was not aborted');
      } catch (err) {
        assert.ok(err.code === axios.AxiosError.ERR_CANCELED);
       // in legacy node versions the error code will be `ERR_STREAM_PREMATURE_CLOSE`
      }

…osHeaders

� Conflicts:
�	lib/core/dispatchRequest.js
Refactored accessor building routine;
Refactored default transforms;
Removed `normalizeHeaderName` helper;
Added missed `has` accessor to TS types;
Added progress capturing ability for node.js environment;
Added `maxRate` option to limit the data rate in node.js environment;
Refactored event handled by `onUploadProgress` && `onDownloadProgress` listeners in browser environment;
Added progress & data rate tests for the http adapter;
Added response stream aborting test;
Added a manual progress capture test for the browser;
Updated TS types;
Added TS tests;
Refactored request abort logic for the http adapter;
Added ability to abort the response stream;
� Conflicts:
�	lib/core/transformData.js
�	lib/defaults/index.js
�	lib/helpers/parseHeaders.js
�	lib/utils.js
@DigitalBrainJS DigitalBrainJS marked this pull request as draft June 4, 2022 15:33
@DigitalBrainJS DigitalBrainJS marked this pull request as ready for review June 6, 2022 13:42
@DigitalBrainJS DigitalBrainJS marked this pull request as draft June 10, 2022 22:45
…mption;

Added throwing an error if the request stream was silently destroying (without error) Refers to axios#3966;
@DigitalBrainJS DigitalBrainJS marked this pull request as ready for review June 13, 2022 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants