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
Methods
- __construct() : mixed
- process() : ResponseInterface
Properties
$resolver
private
MimeResolver
$resolver
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