+ if (0) { // TODO: what is ?
+ if (isset($headers['get'])) {
+ $this->requestedResource = $headers['get'];
+ } else {
+ // todo: fail the connection
+ $headers_out['HTTP-Response'] = "405 Method Not Allowed";
+ }
+ }
+
+ if (!isset($headers['Host']) || !$this->checkHost($headers['Host'])) {
+ // error_log('bad 1');
+ $headers_out['HTTP-Response'] = "400 Bad Request";
+ }
+ if (!isset($headers['Upgrade']) || strtolower($headers['Upgrade']) != 'websocket') {
+ // error_log('bad 2 ' . $headers['Upgrade']);
+ $headers_out['HTTP-Response'] = "400 Bad Request";
+ }
+ if (!isset($headers['Connection']) || strpos(strtolower($headers['Connection']), 'upgrade') === FALSE) {
+ // error_log('bad 3');
+ $headers_out['HTTP-Response'] = "400 Bad Request";
+ }
+ if (!isset($headers['Sec-Websocket-Key'])) {
+ // error_log('bad 4');
+ $headers_out['HTTP-Response'] = "400 Bad Request";
+ } else {
+ }
+
+ if (!isset($headers['Sec-Websocket-Version']) || strtolower($headers['Sec-Websocket-Version']) != 13) {
+ $headers_out['HTTP-Response'] = "426 Upgrade Required";
+ $headers_out['Sec-WebSocketVersion'] = "13";
+ }
+ if ( ($this->headerOriginRequired && !isset($headers['Origin']) )
+ || ($this->headerOriginRequired && !$this->checkOrigin($headers['Origin'])) ) {
+ $headers_out['HTTP-Response'] = "403 Forbidden";
+ }
+ if ( ($this->headerSecWebSocketProtocolRequired && !isset($headers['Sec-Websocket-Protocol']))
+ || ($this->headerSecWebSocketProtocolRequired &&
+ !$this->checkWebsocProtocol($headers['Sec-Websocket-Protocol']))) {
+ // error_log('bad 5');
+ $headers_out['HTTP-Response'] = "400 Bad Request";
+ }
+ if ( ($this->headerSecWebSocketExtensionsRequired && !isset($headers['Sec-Websocket-Extensions']))
+ || ($this->headerSecWebSocketExtensionsRequired &&
+ !$this->checkWebsocExtensions($headers['Sec-Websocket-Extensions'])) ) {
+ // error_log('bad 6');
+ $headers_out['HTTP-Response'] = "400 Bad Request";
+ }