yakovkhalinsky/backblaze-b2

Set maxRedirects:0 on all axios calls

cdhowie opened this issue · 5 comments

B2 does not return any redirect codes under any circumstances, so there is no need to handle the redirect case. When uploading a stream, axios will buffer the entire request body if maxRedirects is not 0 (the default is 5) so it can correctly handle HTTP codes 307 and 308. When uploading files, this causes axios to hold the entire stream contents in memory to handle a situation that will never occur. This is wasteful, particularly for very large uploads.

uploadFile() and uploadPart() should set maxRedirects:0 on the axios request config. (It should be safe to set this everywhere, as a global default, but these two functions are the most critical.)

cbess commented

Good observation. I concur with your conclusion.

Sounds good. (ref: axios/axios#1045) Feel free to make a PR otherwise I'll get to it eventually.

Submitted #95.

It looks like this may not be an issue after all and the PR I submitted may not be necessary. See commit cc51918 which already should handle this problem, so I think this issue and the linked PR can be closed as unnecessary.

I'm not sure yet why we were seeing this buffering in our code. I suspect that we were doing calls against axios directly in some cases and that's where we saw the buffering.

@cdhowie Cool, I'll go ahead and close them.