Skip to content

Node-utils/neat-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

neat-request

Light-weight Promise wrap for raw http.request

Install

npm install neat-request

Hello Request

// Now is mostly used for proxy
const request = require('neat-request');

const server = http.createServer(async function(sreq, sres) {
  const url_parts = url.parse(sreq.url);
  const opts = {
    host: 'google.com',
    port: 80,
    path: url_parts.pathname,
    method: sreq.method,
    headers: sreq.headers
  };
  const ext = {
    body: sreq, // pipe server to client request
    // timeout(Num): If None, Default is 15sec
    // toJSON(bool): Default is False.
  };
  const cres = await request(opts, ext);
  sres.writeHead(cres.statusCode, cres.headers);
  cres.pipe(sres); // pipe client to server response
});
server.listen(80, '0.0.0.0');

About

Light-weight Promise wrap for raw http.request

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published