Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

ContentEncodingMiddleware
in package
implements MiddlewareInterface

Content-Encoding Middleware — Apache mod_mime AddEncoding parity.

Sets the response Content-Encoding header from the request URL's file suffixes. Apache find_ct (mod_mime.c:947–962) walks every dot-separated suffix and accumulates an encoding chain — archive.tar.gz with AddEncoding x-gzip .gz yields Content-Encoding: x-gzip, and a doubly-encoded data.gz.gz yields gzip, gzip (order preserved, duplicates intentionally kept). The multi-suffix walk is delegated to MimeResolver.

This middleware is ADDITIVE and OPT-IN: with the default empty map it never touches the response. It only sets Content-Encoding when (a) the map has a matching suffix AND (b) the response doesn't already declare one — an explicit Content-Encoding set by the handler (or by a compression middleware that actually encoded the body) always wins.

Apache equivalent: AddEncoding x-gzip .gz AddEncoding x-bzip2 .bz2 AddEncoding br .br

Usage in app.php:

$app->addMiddleware(new \ZealPHP\Middleware\ContentEncodingMiddleware([
    'gz'  => 'gzip',
    'br'  => 'br',
    'bz2' => 'bzip2',
]));

Table of Contents

Interfaces

MiddlewareInterface

Properties

$resolver  : MimeResolver

Methods

__construct()  : mixed
process()  : ResponseInterface

Properties

Methods

__construct()

public __construct([array<string, string|int> $map = [] ]) : mixed
Parameters
$map : array<string, string|int> = []

ext => content-encoding (e.g. gz => gzip)

process()

public process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
$request : ServerRequestInterface
$handler : RequestHandlerInterface
Return values
ResponseInterface
On this page