index.js
function parse(obj, headers, whitelist) {
  var proxied = forwarded(headers || {}, whitelist)
    , connection = obj.connection
    , socket = connection
      ? connection.socket
      : obj.socket;

  //
  // We should always be testing for HTTP headers as remoteAddress would point
  // to proxies.
  //
  if (proxied) return proxied;

  // Check for the property on our given object.
  if ('object' === typeof obj) {
    if ('remoteAddress' in obj) {
      return new Forwarded(
        obj.remoteAddress,
        obj.remotePort,
        'secure' in obj ? obj.secure : obj.encrypted
      );
    }

    // Edge case for Socket.IO 0.9
    if ('object' === typeof obj.address && obj.address.address) {
      return new Forwarded(
        obj.address.address,
        obj.address.port,
        'secure' in obj ? obj.secure : obj.encrypted
      );
    }
  }

  if ('object' === typeof connection && 'remoteAddress' in connection) {
    return new Forwarded(
      connection.remoteAddress,
      connection.remotePort,
      'secure' in connection ? connection.secure : connection.encrypted
    );
  }

  if ('object' === typeof socket && 'remoteAddress' in socket) {
    return new Forwarded(
      socket.remoteAddress,
      socket.remoteAddress,
      'secure' in socket ? socket.secure : socket.encrypted
    );
  }

  return new Forwarded();
}
function parse(obj, headers, whitelist) {
  var proxied = forwarded(headers || {}, whitelist)
    , connection = obj.connection
    , socket = connection
      ? connection.socket
      : obj.socket;

  //
  // We should always be testing for HTTP headers as remoteAddress would point
  // to proxies.
  //
  if (proxied) return proxied;

  // Check for the property on our given object.
  if ('object' === typeof obj) {
    if ('remoteAddress' in obj) {
      return new Forwarded(
        obj.remoteAddress,
        obj.remotePort,
        'secure' in obj ? obj.secure : obj.encrypted
      );
    }

    // Edge case for Socket.IO 0.9
    if ('object' === typeof obj.address && obj.address.address) {
      return new Forwarded(
        obj.address.address,
        obj.address.port,
        'secure' in obj ? obj.secure : obj.encrypted
      );
    }
  }

  if ('object' === typeof connection && 'remoteAddress' in connection) {
    return new Forwarded(
      connection.remoteAddress,
      connection.remotePort,
      'secure' in connection ? connection.secure : connection.encrypted
    );
  }

  if ('object' === typeof socket && 'remoteAddress' in socket) {
    return new Forwarded(
      socket.remoteAddress,
      socket.remoteAddress,
      'secure' in socket ? socket.secure : socket.encrypted
    );
  }

  return new Forwarded();
}
function parse ( obj , headers , whitelist ) { var proxied = forwarded ( headers || { } , whitelist ) , connection = obj . connection , socket = connection ? connection . socket : obj . socket ; // // We should always be testing for HTTP headers as remoteAddress would point // to proxies. // if ( proxied ) return proxied ; // Check for the property on our given object. if ( 'object' === typeof obj ) { if ( 'remoteAddress' in obj ) { return new Forwarded ( obj . remoteAddress , obj . remotePort , 'secure' in obj ? obj . secure : obj . encrypted ) ; } // Edge case for Socket.IO 0.9 if ( 'object' === typeof obj . address && obj . address . address ) { return new Forwarded ( obj . address . address , obj . address . port , 'secure' in obj ? obj . secure : obj . encrypted ) ; } } if ( 'object' === typeof connection && 'remoteAddress' in connection ) { return new Forwarded ( connection . remoteAddress , connection . remotePort , 'secure' in connection ? connection . secure : connection . encrypted ) ; } if ( 'object' === typeof socket && 'remoteAddress' in socket ) { return new Forwarded ( socket . remoteAddress , socket . remoteAddress , 'secure' in socket ? socket . secure : socket . encrypted ) ; } return new Forwarded ( ) ; }
Parse out the address information..

@param {Object} obj A socket like object that could contain a `remoteAddress`.
@param {Object} headers The received HTTP headers.
@param {Array} whitelist White list
@returns {Forwarded} A Forwarded address object.
@api private
Parse out the address information ..