Пример #1
0
 /**
  * Negotiate permessage-deflate settings with the server using the given handshake HTTP response.
  * 
  * @param HttpResponse $response
  * @return PerMessageDeflate Or null when the server did not enable the extension.
  */
 protected function negotiatePerMessageDeflate(HttpResponse $response)
 {
     static $zlib;
     $extension = null;
     if ($zlib ?? ($zlib = \function_exists('inflate_init'))) {
         foreach ($response->getHeaderTokens('Sec-WebSocket-Extensions') as $ext) {
             if (\strtolower($ext->getValue()) === 'permessage-deflate') {
                 $extension = $ext;
                 break;
             }
         }
     }
     if ($extension === null) {
         return;
     }
     try {
         return PerMessageDeflate::fromHeaderToken($extension);
     } catch (\OutOfRangeException $e) {
         return;
     }
 }