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

Proxy server question #760

Closed
ORESoftware opened this issue Jul 29, 2017 · 3 comments
Closed

Proxy server question #760

ORESoftware opened this issue Jul 29, 2017 · 3 comments

Comments

@ORESoftware
Copy link

This pertains to Node.js versions greater than 4.0.0

re: https://stackoverflow.com/questions/45384853/proxy-request-with-node-js-neterr-empty-response/45385003#45385003

Why does this work:

router.post('/image', function (req, res, next) {

  const filename = uuid.v4();

  const proxy = http.request({
    method: 'PUT',
    hostname: 'engci-maven.nabisco.com',
    path: `/artifactory/cdt-repo/folder/${filename}`,
    headers: {
      'Authorization': 'Basic ' + Buffer.from('foo:bar').toString('base64'),
    }
  }, function(resp){

    resp.pipe(res).once('error', next);

  });

  req.pipe(proxy).once('error', next);

});

but this does not work:

router.post('/image', function (req, res, next) {

  const filename = uuid.v4();

  const proxy = http.request({
    method: 'PUT',
    hostname: 'engci-maven.nabisco.com',
    path: `/artifactory/cdt-repo/folder/${filename}`,
    headers: {
      'Authorization': 'Basic ' + Buffer.from('foo:bar').toString('base64'),
    }
  });

  req.pipe(proxy).pipe(res).once('error', next);

});

any info much appreciated.

@ORESoftware ORESoftware changed the title Proxy server Proxy server question Jul 29, 2017
@refack
Copy link

refack commented Jul 30, 2017

/cc @mcollina

@mcollina
Copy link
Member

The object http.request returns is not a Duplex, so you can only write to it, not read from it. You are hitting nodejs/node#14358, which will be fixed in Node 9.

I think the code you are writing would work using https://www.npmjs.com/package/request.

@ORESoftware
Copy link
Author

ORESoftware commented Jul 30, 2017

@mcollina yeah I see, thanks, glad I wasn't totally off-base.

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

No branches or pull requests

4 participants