node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »

lib-stream-http

lib-stream-http

create a duplex stream representing the http connection

install

npm install --save lib-stream-http

usage

var Requestor = require('lib-stream-http')();
var requestor = Requestor.New();
 
var opts = {
  host: 'myhost.example.com',
  path: '/somet/path',
}
 
var duplex = requestor.newDuplex(opts);
 
// generate error on http status >= 400 
// you should still consume the res 
duplex.on('error', function (err, res) {
  // cleanup on error 
});
 
// the outStream only gets data if the request succeeds 
inStream.pipe(duplex).pipe(outStream);

limitations

  • does not handle 3xx status codes

see also