node-proxy/lib/proxy/ProxyServer.js
/**
 *  Handler to process websockets traffic we receive and route to the
 *  appropriate websocket endpoint and proxy traffic to-and-fro from the
 *  the websocket endpoint.
 *
 *  Examples:
 *    var ProxyServer  = require('./proxy/ProxyServer.js');
 *    var cfgfile      = '/etc/openshift/web-proxy.json';
 *    var proxy_server = new ProxyServer.ProxyServer(cfgfile);
 *    proxy_server.initServer();
 *
 *    var zserver = httputils.createProtocolServer('http');
 *    var wssrvr  = new WebSocket.Server({server: zserver});
 *    wssrvr.on('connection', function(ws) {
 *      _websocketHandler(self, ws);
 *    });
 *
 *  @param  {ProxyServer}  Proxy server instance.
 *  @param  {WebSocket}    The incoming websocket (what we received).
 *  @api    private
 */
Handler to process websockets traffic we receive and route to the
appropriate websocket endpoint and proxy traffic to-and-fro from the
the websocket endpoint.





@param  {ProxyServer}  Proxy server instance.
@param  {WebSocket}    The incoming websocket (what we received).
@api    private
Handler to process websockets traffic we receive and route to the appropriate websocket endpoint and proxy traffic to - and - fro from the the websocket endpoint . @param { ProxyServer } Proxy server instance . @param { WebSocket } The incoming websocket ( what we received ) . @api private
function _websocketHandler(proxy_server, ws) {
  var websockets_timeout = DEFAULT_WEBSOCKETS_TIMEOUT;  
  if (proxy_server.config.timeouts  &&
      proxy_server.config.timeouts.websockets) {
    websockets_timeout = proxy_server.config.timeouts.websockets;
  }
  ws._socket.setTimeout(websockets_timeout * 1000);
  var upgrade_req = ws.upgradeReq  ||  { };
  var upg_reqhost = '';
  if (upgrade_req.headers  &&  upgrade_req.headers.host) {
    upg_reqhost = upgrade_req.headers.host.split(':')[0];
  }
  var idled_container = proxy_server.getIdle(upg_reqhost)
  if (idled_container && 0 !== idled_container.length) {
    var command = 'curl -s -k -L -w %{http_code} -o /dev/null http://' + upg_reqhost
    Logger.debug('Unidle command for ws: ' + command);
    child_process.exec(command, function (error, stdout, stderr) {
      if (null != stderr) {
        Logger.error('curl stderr: ' + stderr);
      }
      if (null != error) {
        Logger.error('curl error: ' + error);
      }
      if ('200' == stdout) {
        proxy_server.unIdle(upg_reqhost);
        finish_websocket (upg_reqhost, proxy_server, ws);
      }
    });
  }
  else {
    finish_websocket (upg_reqhost, proxy_server, ws);
  }
}
function _websocketHandler ( proxy_server , ws ) { var websockets_timeout = DEFAULT_WEBSOCKETS_TIMEOUT ; if ( proxy_server . config . timeouts && proxy_server . config . timeouts . websockets ) { websockets_timeout = proxy_server . config . timeouts . websockets ; } ws . _socket . setTimeout ( websockets_timeout * 1000 ) ; var upgrade_req = ws . upgradeReq || { } ; var upg_reqhost = '' ; if ( upgrade_req . headers && upgrade_req . headers . host ) { upg_reqhost = upgrade_req . headers . host . split ( ':' ) [ 0 ] ; } var idled_container = proxy_server . getIdle ( upg_reqhost ) if ( idled_container && 0 !== idled_container . length ) { var command = 'curl -s -k -L -w %{http_code} -o /dev/null http://' + upg_reqhost Logger . debug ( 'Unidle command for ws: ' + command ) ; child_process . exec ( command , function ( error , stdout , stderr ) { if ( null != stderr ) { Logger . error ( 'curl stderr: ' + stderr ) ; } if ( null != error ) { Logger . error ( 'curl error: ' + error ) ; } if ( '200' == stdout ) { proxy_server . unIdle ( upg_reqhost ) ; finish_websocket ( upg_reqhost , proxy_server , ws ) ; } } ) ; } else { finish_websocket ( upg_reqhost , proxy_server , ws ) ; } }
Handler to process websockets traffic we receive and route to the
  appropriate websocket endpoint and proxy traffic to-and-fro from the
  the websocket endpoint.
Handler to process websockets traffic we receive and route to the appropriate websocket endpoint and proxy traffic to - and - fro from the the websocket endpoint .
/*  Get websockets timeout.  */ /*  3600 secs.  */ /*  Timeout is set in milliseconds, so convert from seconds.  */ /*  Get the original/upgraded HTTP request.  */ /*  Get the host, the original/upgraded HTTP request was sent to.  */