Skip to content

Proxy server question #760

Closed
Closed
@ORESoftware

Description

@ORESoftware

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions