lib/util/eventedhttp.js
function EventedHTTPServerConnection(clientSocket) {
  this.sessionID = uuid.generate(clientSocket.remoteAddress + ':' + clientSocket.remotePort);

  this._remoteAddress = clientSocket.remoteAddress; // cache because it becomes undefined in 'onClientSocketClose'
  this._pendingClientSocketData = bufferShim.alloc(0); // data received from client before HTTP proxy is fully setup
  this._fullySetup = false; // true when we are finished establishing connections
  this._writingResponse = false; // true while we are composing an HTTP response (so events can wait)
  this._pendingEventData = bufferShim.alloc(0); // event data waiting to be sent until after an in-progress HTTP response is being written

  // clientSocket is the socket connected to the actual iOS device
  this._clientSocket = clientSocket;
  this._clientSocket.on('data', this._onClientSocketData.bind(this));
  this._clientSocket.on('close', this._onClientSocketClose.bind(this));
  this._clientSocket.on('error', this._onClientSocketError.bind(this)); // we MUST register for this event, otherwise the error will bubble up to the top and crash the node process entirely.

  // serverSocket is our connection to our own internal httpServer
  this._serverSocket = null; // created after httpServer 'listening' event

  // create our internal HTTP server for this connection that we will proxy data to and from
  this._httpServer = http.createServer();

  this._httpServer.timeout = 0; // clients expect to hold connections open as long as they want
  this._httpServer.keepAliveTimeout = 0; // workaround for https://github.com/nodejs/node/issues/13391
  this._httpServer.on('listening', this._onHttpServerListening.bind(this));
  this._httpServer.on('request', this._onHttpServerRequest.bind(this));
  this._httpServer.on('error', this._onHttpServerError.bind(this));
  this._httpServer.listen(0);

  // an arbitrary dict that users of this class can store values in to associate with this particular connection
  this._session = {
    sessionID: this.sessionID
  };

  // a collection of event names subscribed to by this connection
  this._events = {}; // this._events[eventName] = true (value is arbitrary, but must be truthy)

  debug("[%s] New connection from client", this._remoteAddress);
}
function EventedHTTPServerConnection(clientSocket) {
  this.sessionID = uuid.generate(clientSocket.remoteAddress + ':' + clientSocket.remotePort);

  this._remoteAddress = clientSocket.remoteAddress; // cache because it becomes undefined in 'onClientSocketClose'
  this._pendingClientSocketData = bufferShim.alloc(0); // data received from client before HTTP proxy is fully setup
  this._fullySetup = false; // true when we are finished establishing connections
  this._writingResponse = false; // true while we are composing an HTTP response (so events can wait)
  this._pendingEventData = bufferShim.alloc(0); // event data waiting to be sent until after an in-progress HTTP response is being written

  // clientSocket is the socket connected to the actual iOS device
  this._clientSocket = clientSocket;
  this._clientSocket.on('data', this._onClientSocketData.bind(this));
  this._clientSocket.on('close', this._onClientSocketClose.bind(this));
  this._clientSocket.on('error', this._onClientSocketError.bind(this)); // we MUST register for this event, otherwise the error will bubble up to the top and crash the node process entirely.

  // serverSocket is our connection to our own internal httpServer
  this._serverSocket = null; // created after httpServer 'listening' event

  // create our internal HTTP server for this connection that we will proxy data to and from
  this._httpServer = http.createServer();

  this._httpServer.timeout = 0; // clients expect to hold connections open as long as they want
  this._httpServer.keepAliveTimeout = 0; // workaround for https://github.com/nodejs/node/issues/13391
  this._httpServer.on('listening', this._onHttpServerListening.bind(this));
  this._httpServer.on('request', this._onHttpServerRequest.bind(this));
  this._httpServer.on('error', this._onHttpServerError.bind(this));
  this._httpServer.listen(0);

  // an arbitrary dict that users of this class can store values in to associate with this particular connection
  this._session = {
    sessionID: this.sessionID
  };

  // a collection of event names subscribed to by this connection
  this._events = {}; // this._events[eventName] = true (value is arbitrary, but must be truthy)

  debug("[%s] New connection from client", this._remoteAddress);
}
function EventedHTTPServerConnection ( clientSocket ) { this . sessionID = uuid . generate ( clientSocket . remoteAddress + ':' + clientSocket . remotePort ) ; this . _remoteAddress = clientSocket . remoteAddress ; // cache because it becomes undefined in 'onClientSocketClose' this . _pendingClientSocketData = bufferShim . alloc ( 0 ) ; // data received from client before HTTP proxy is fully setup this . _fullySetup = false ; // true when we are finished establishing connections this . _writingResponse = false ; // true while we are composing an HTTP response (so events can wait) this . _pendingEventData = bufferShim . alloc ( 0 ) ; // event data waiting to be sent until after an in-progress HTTP response is being written // clientSocket is the socket connected to the actual iOS device this . _clientSocket = clientSocket ; this . _clientSocket . on ( 'data' , this . _onClientSocketData . bind ( this ) ) ; this . _clientSocket . on ( 'close' , this . _onClientSocketClose . bind ( this ) ) ; this . _clientSocket . on ( 'error' , this . _onClientSocketError . bind ( this ) ) ; // we MUST register for this event, otherwise the error will bubble up to the top and crash the node process entirely. // serverSocket is our connection to our own internal httpServer this . _serverSocket = null ; // created after httpServer 'listening' event // create our internal HTTP server for this connection that we will proxy data to and from this . _httpServer = http . createServer ( ) ; this . _httpServer . timeout = 0 ; // clients expect to hold connections open as long as they want this . _httpServer . keepAliveTimeout = 0 ; // workaround for https://github.com/nodejs/node/issues/13391 this . _httpServer . on ( 'listening' , this . _onHttpServerListening . bind ( this ) ) ; this . _httpServer . on ( 'request' , this . _onHttpServerRequest . bind ( this ) ) ; this . _httpServer . on ( 'error' , this . _onHttpServerError . bind ( this ) ) ; this . _httpServer . listen ( 0 ) ; // an arbitrary dict that users of this class can store values in to associate with this particular connection this . _session = { sessionID : this . sessionID } ; // a collection of event names subscribed to by this connection this . _events = { } ; // this._events[eventName] = true (value is arbitrary, but must be truthy) debug ( "[%s] New connection from client" , this . _remoteAddress ) ; }
Manages a single iOS-initiated HTTP connection during its lifetime.

@event 'request' => function(request, response) { }
@event 'decrypt' => function(data, {decrypted.data}, session) { }
@event 'encrypt' => function(data, {encrypted.data}, session) { }
@event 'close' => function() { }
Manages a single iOS - initiated HTTP connection during its lifetime .