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

MimeTypeMiddleware
in package
implements MiddlewareInterface

MIME Type Middleware

Sets the response Content-Type based on the URL's extension when the handler didn't already set one. Useful for handlers that stream raw bytes for custom file types (.wasm, .glb, .usdz, …) without each handler remembering the right MIME string.

Multi-suffix aware (Apache mod_mime find_ct parity): the type is resolved by walking every dot-separated suffix left-to-right, so document.html.gz resolves its Content-Type from html (the last type-mapped suffix wins) while gz contributes no type. Leading-dot basenames (.png) are hidden files with no extension and receive no type. See MimeResolver.

Note: OpenSwoole's static file handler has its own internal MIME map for files served directly off disk via static_handler_locations. This middleware covers the case where your PHP handler is generating the body (the static handler isn't in the picture) and you still want extension- based Content-Type negotiation.

Apache equivalent:

AddType application/wasm           .wasm
AddType model/gltf-binary          .glb
AddType model/vnd.usdz+zip         .usdz

Only fires when the upstream response has no Content-Type — explicit $response->header('Content-Type', ...) calls in the handler always win.

Usage in app.php:

$app->addMiddleware(new \ZealPHP\Middleware\MimeTypeMiddleware([
    'wasm' => 'application/wasm',
    'glb'  => 'model/gltf-binary',
    'usdz' => 'model/vnd.usdz+zip',
]));

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 => mime-type

process()

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