New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept streams as body #2075
Comments
@request/promises can you help with this issue? |
Note I am using request through promisifying the callback api, so changes to any promise api doesn't address this. This is also something that could be useful even without using promises, so I don't think the promise label is entirely accurate. |
Hi @petkaantonov if I understand it correctly you currently use: gzipStream.pipe(request.post(endpoint)); ...whereas this wouldn't work: gzipStream.pipe(request.post(endpoint, function (err, response, body) {
// Callback is provided through promisification.
// Thus cannot have custom code that interacts with the stream here.
})); ...and you propose this: request.post({
uri: endpoint,
body: gzipStream // Passing a stream instead of just JSON
}, function (err, response, body) {
// err is either an error of the request or an error message of the gzipStream stream
}); Correct? |
Yes I want |
@petkaantonov can you provide a full pseudo code on what you are trying to achieve. |
request({
...
body: gzipStream
...
}); Should work the same as if I did |
That seems doable. What happens if you want to stream the response as well? In this case your only choice would be to buffer it inside the callback, though that's probably the case when using Promises anyway? |
Well in practice when request payload is big, the response payload is small. And vice versa. So it's not a problem to buffer the short acknowledgment response. |
What I'm trying to say is that the user should be able to pass not only the input stream, but the output one as well. Buffering by default might not be what you want. So When the |
Yes I am not against that of course. btw I have no affiliation with |
@petkaantonov take a look at #2079 |
@simov I covered your suggestion in request/request-promise#90 |
If I want to send the request body e.g. gzipped, I currently need the return value and pipe the gzipstream there. However I only have access to the return value when using callback API but we are normally using promise API where the return value "slot" is taken by the promise and we cannot interact with the stream.
I propose extending the
body
option to accept stream which would do this for me so that I don't need to waste the return value "slot". Any errors should be redirected to the callback error argument.The text was updated successfully, but these errors were encountered: