lib/pingback.js
function(url, body, func) {
  if (typeof url !== 'object') {
    url = parse(url);
  }

  if (!func) {
    func = body;
    body = undefined;
  }

  var opt = {
    host: url.hostname,
    port: url.port || 80,
    path: url.pathname
    //agent: false
  };

  if (body) {
    opt.headers = {
      'Content-Type': 'application/xml; charset=utf-8',
      'Content-Length': Buffer.byteLength(body),
      'Range': 'bytes=0-5120'
    };
    opt.method = 'POST';
  } else {
    opt.method = 'GET';
  }

  var req = http.request(opt);
  req.on('response', function(res) {
    var decoder = new StringDecoder('utf8')
      , total = 0
      , body = ''
      , done = false;

    var end = function() {
      if (done) return;
      done = true;
      res.body = body;
      func(null, res);
    };

    res.on('data', function(data) {
      total += data.length;
      body += decoder.write(data);
      if (total > 5120) {
        res.destroy();
        end();
      }
    }).on('error', function(err) {
      res.destroy();
      func(err);
    });

    res.on('end', end);

    // an agent socket's `end` sometimes
    // wont be emitted on the response
    res.socket.on('end', end);
  });
  req.end(body);
}
function(url, body, func) {
  if (typeof url !== 'object') {
    url = parse(url);
  }

  if (!func) {
    func = body;
    body = undefined;
  }

  var opt = {
    host: url.hostname,
    port: url.port || 80,
    path: url.pathname
    //agent: false
  };

  if (body) {
    opt.headers = {
      'Content-Type': 'application/xml; charset=utf-8',
      'Content-Length': Buffer.byteLength(body),
      'Range': 'bytes=0-5120'
    };
    opt.method = 'POST';
  } else {
    opt.method = 'GET';
  }

  var req = http.request(opt);
  req.on('response', function(res) {
    var decoder = new StringDecoder('utf8')
      , total = 0
      , body = ''
      , done = false;

    var end = function() {
      if (done) return;
      done = true;
      res.body = body;
      func(null, res);
    };

    res.on('data', function(data) {
      total += data.length;
      body += decoder.write(data);
      if (total > 5120) {
        res.destroy();
        end();
      }
    }).on('error', function(err) {
      res.destroy();
      func(err);
    });

    res.on('end', end);

    // an agent socket's `end` sometimes
    // wont be emitted on the response
    res.socket.on('end', end);
  });
  req.end(body);
}
function ( url , body , func ) { if ( typeof url !== 'object' ) { url = parse ( url ) ; } if ( ! func ) { func = body ; body = undefined ; } var opt = { host : url . hostname , port : url . port || 80 , path : url . pathname //agent: false } ; if ( body ) { opt . headers = { 'Content-Type' : 'application/xml; charset=utf-8' , 'Content-Length' : Buffer . byteLength ( body ) , 'Range' : 'bytes=0-5120' } ; opt . method = 'POST' ; } else { opt . method = 'GET' ; } var req = http . request ( opt ) ; req . on ( 'response' , function ( res ) { var decoder = new StringDecoder ( 'utf8' ) , total = 0 , body = '' , done = false ; var end = function ( ) { if ( done ) return ; done = true ; res . body = body ; func ( null , res ) ; } ; res . on ( 'data' , function ( data ) { total += data . length ; body += decoder . write ( data ) ; if ( total > 5120 ) { res . destroy ( ) ; end ( ) ; } } ) . on ( 'error' , function ( err ) { res . destroy ( ) ; func ( err ) ; } ) ; res . on ( 'end' , end ) ; // an agent socket's `end` sometimes // wont be emitted on the response res . socket . on ( 'end' , end ) ; } ) ; req . end ( body ) ; }
HTTP Request
 make an http request
HTTP Request make an http request