Nexus API Reference

BodySizeLimitMiddleware
in package
implements MiddlewareInterface

Read onlyYes
FinalYes
Tags
psalm-api

Rejects requests whose body exceeds the configured byte limit with 413 Payload Too Large. Trusts the Content-Length header for upfront rejection; for streaming/chunked bodies, the body stream's getSize() is consulted (PSR-7 returns null for unknown sizes, in which case the limit is enforced after the body is read).

Layer this as global middleware OUTSIDE any body parser so oversized bodies never reach JSON decoding or the FromBody attribute mapper.

$app->middleware(new BodySizeLimitMiddleware(maxBytes: 10 * 1024 * 1024));

Per-route limits override the global by registering this middleware on the route:

$app->post('/upload', UploadHandler::class) ->middleware(new BodySizeLimitMiddleware(maxBytes: 100 * 1024 * 1024));

Table of Contents

Interfaces

MiddlewareInterface

Methods

__construct()  : mixed
process()  : ResponseInterface

Methods

__construct()

public __construct(int $maxBytes[, ResponseFactoryInterface|null $responseFactory = null ][, StreamFactoryInterface|null $streamFactory = null ]) : mixed
Parameters
$maxBytes : int
$responseFactory : ResponseFactoryInterface|null = null
$streamFactory : StreamFactoryInterface|null = null

process()

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

        
On this page

Search results