Skip to content
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

Question: pipe stream to POST request #3

Closed
mulyoved opened this issue Jul 9, 2015 · 9 comments
Closed

Question: pipe stream to POST request #3

mulyoved opened this issue Jul 9, 2015 · 9 comments
Labels
api: N/A Tells auto-label to not auto-detect the API for this issue type: question Request for information or clarification. Not an issue.

Comments

@mulyoved
Copy link

mulyoved commented Jul 9, 2015

Have this code which work fine with request, what will be the correct way to call it in retry-request?

var pipe = fs
  .createReadStream(fileName)
  .pipe(
  request({ url: url, method: 'POST'}));

pipe
  .on('error', function(err) {
    console.error(err);
  })
  .on('response', function (answer) {
  })
  .on('complete', function (answer) {
  })
  .on('end', function(answer) {
  });
@stephenplusplus
Copy link
Contributor

It should look like:

var pipe = fs
  .createReadStream(fileName)
  .pipe(
-  request({ url: url, method: 'POST'}));
+  retryRequest({ url: url, method: 'POST'}));

pipe
  .on('error', function(err) {
    console.error(err);
  })
  .on('response', function (answer) {
  })
  .on('complete', function (answer) {
  })
  .on('end', function(answer) {
  });

Can you let me know if that works?

@mulyoved
Copy link
Author

No this does not work, all look OK but result seem to be empty stream.

@stephenplusplus
Copy link
Contributor

Sorry, I don't know how I missed the POST part of this, since it was all over your question.

Using retryRequest with post requests is not currently supported, as it's quite a difficult task to implement. Conditionally rewinding & re-piping a stream already in the hands of a user is not something I've yet figured out how to do, if it is even possible at all. PRs welcome if you know the trick!

@stephenplusplus
Copy link
Contributor

Left a note in the readme that points here.

@mulyoved
Copy link
Author

I can see why stream POST is an issue, I ended up add the retry logic in an upper level.

@ruffle1986
Copy link

Sorry, it's a bit irrelevant. @stephenplusplus, how did you achieve the red and green lines to show the changes in your comment?

@stephenplusplus
Copy link
Contributor

No problem @ruffle1986. I thought it was pretty cool the first time I saw it, too.

```diff
var pipe = fs
  .createReadStream(fileName)
  .pipe(
-  request({ url: url, method: 'POST'}));
+  retryRequest({ url: url, method: 'POST'}));

var pipe = fs
  .createReadStream(fileName)
  .pipe(
-  request({ url: url, method: 'POST'}));
+  retryRequest({ url: url, method: 'POST'}));

@surya1024
Copy link

surya1024 commented May 22, 2019

I have similar issue even with GET but work as expected with request

Using pump returns a empty response

  pump(req, retryRequest({...options, url: url}), res, (err) => console.log(err));

Using pipe gives a "write after end" error

req.pipe(retryRequest({url: url, ...options}))
      .on('error', (req, res, next) => console.log("error"))
      .pipe(res)

@stephenplusplus
Copy link
Contributor

@surya1024 thank you for reporting. Would you mind opening a new issue for that?

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 16, 2022
@tmatsuo tmatsuo added type: question Request for information or clarification. Not an issue. api: N/A Tells auto-label to not auto-detect the API for this issue and removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: N/A Tells auto-label to not auto-detect the API for this issue type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

7 participants