Skip to content

Latest commit

 

History

History
executable file
·
32 lines (25 loc) · 1.59 KB

README.md

File metadata and controls

executable file
·
32 lines (25 loc) · 1.59 KB

Web compression

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

HTTP compression for the XP Framework, implemented as filter.

Example

The following shows how to enable on-the-fly compression for HTTP responses. Depending on the Accept-Encoding header the client sends, the server-supported compression algorithms and the length of the content, the response is compressed, saving bandwidth.

use web\{Application, Filters};
use web\filters\CompressResponses;

class Service extends Application {

  public function routes() {
    return new Filters([new CompressResponses()], function($req, $res) {
      $content= /* ... */;

      $res->answer(200);
      $res->send($content, 'text/html; charset=utf-8');
    });
  }
}