Andy Melnikov (nponeccop) wrote,
Andy Melnikov
nponeccop

Ну не пиздец ли?

Нашёл тут кусок кода http://stackoverflow.com/q/19185055/805266

var dns = require('dns'),
    http = require('http');

function httpRequest(options, body, done) {
  hostname = options.hostname || options.host;

  if (typeof(body) === 'function') {
    done = body;
    body = null;
  }

  // async resolve with C-ares
  dns.resolve(hostname, function (err, addresses) {
    if (err)
      return done(err);

    // Pass the host in the headers so the remote webserver
    // can use the correct vhost.
    var headers = options.headers || {};
    headers.host = hostname;
    options.headers = headers;

    // pass the resolved address so http doesn't feel the need to
    // call dns.lookup in a thread pool
    options.hostname = addresses[0];
    options.host = undefined;

    var req = http.request(options, done);

    req.on('error', done);

    if (body)
      req.write(body);

    req.end();
  });
}
Subscribe

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 3 comments