code: private function applyResponseEncoding(
          Request $request,
          Response $response
      )
      {
          $allowedCompressionAsString = $request
              ->headers
              ->get('Accept-Encoding');
  
          if (!$allowedCompressionAsString) {
              return;
          }
  
          $allowedCompression = explode(',', $allowedCompressionAsString);
          $allowedCompression = array_map('trim', $allowedCompression);
  
          if (in_array('gzip', $allowedCompression)) {
              $response->setContent(gzencode($response->getContent()));
              $response
                  ->headers
                  ->set('Content-Encoding', 'gzip');
  
              return;
          }
  
          if (in_array('deflate', $allowedCompression)) {
              $response->setContent(gzdeflate($response->getContent()));
              $response
                  ->headers
                  ->set('Content-Encoding', 'deflate');
  
              return;
          }
      }
docs: Apply response encoding
  
  @param Request $request
  @param Response $response