Implement pause option for resolving with stream#16
Implement pause option for resolving with stream#16mildsunrise wants to merge 3 commits intorequest:masterfrom
pause option for resolving with stream#16Conversation
- Initialize options at the beginning of init - Extract the code that resolves / rejects the promise into separate functions
5 similar comments
|
Does this look good to you? If it does, I'll add tests |
|
Thanks for finally submitting a PR - I never got around to it since i had my custom resolve-stream-from-promise wrapper around request and never needed it anywhere else, and I'm not using The changes I can see being needed are documentation, and as this option means that the stream is being resolved, personally, i'd call the option Also, on errors, in my old proof of concept, (and what I did in the previously-mentioned wrapper) is to read the body on error, rather than completely discarding it. IMO, in |
See request/request-promise#90. The particular implementation details are:
transformandresolveWithFullResponseare always ignored.simple = trueand the response is a 404), so the response cannot be streamed in that case. This is a limitation, but 99% of the time users aren't interested in the error body, so that'd be a memory leak unless they make surestream.resume()is called on rejections. And if you really need to stream error responses, you can usesimple = false.Proposed documentation and examples for the option:
pause = falsewhich is a boolean that when set, the promise will be resolved with the raw response stream (http.IncomingMessage) before the body arrives (e.g. when theresponseevent fires). ImpliesresolveWithFullResponse = trueandtransform = null..pipe()and others resume it automatically, otherwise you may need to call.resume()manually, even if you do nothing else with the stream.The implementation is in the second commit, the first is just a refactor to prepare for the changes.