Documentation

Middleware

Table of Contents

Interfaces

MiddlewareInterface
Client middleware interface - a PSR-15-style interceptor for Client's outbound dispatch. Not a literal PSR-15 implementation: PSR-15's real interfaces are typed to ServerRequestInterface (server-side only) and cannot apply to a Client's outbound RequestInterface flow, so this mirrors PSR-15's shape with the request type swapped.
RequestHandlerInterface
Client middleware request handler interface - what a MiddlewareInterface's $handler argument is; calling $handler->handle($request) continues the chain

Classes

CallableMiddleware
Adapts a plain callable into a MiddlewareInterface, so Client::addMiddleware() can accept a closure directly instead of requiring a full class
CallableRequestHandler
Adapts a plain callable into a RequestHandlerInterface. Internal - used by Pipeline to build each link of the chain; not part of the API a middleware author interacts with directly.
LoggingMiddleware
PSR-3 logging middleware - logs one line per handler invocation (per dispatch attempt), with a level derived from the outcome (info for success, warning for 4xx, error for 5xx or a thrown exception), known- sensitive headers redacted by default, and request/response bodies excluded unless explicitly opted in. Exceptions are logged then re-thrown completely unmodified. No special coupling with RetryMiddleware - see logRetriesTo() for an optional adapter onto its existing onRetry hook.
Pipeline
Builds and runs a middleware chain. Registration order is wrap order: the first-registered middleware ends up outermost (runs first going in, last coming out) - the standard onion convention.
RetryMiddleware
Retry/backoff middleware - retries a request on transient network exceptions and/or specific response status codes, with exponential backoff and full jitter between attempts. Honors a Retry-After response header over the computed delay when present. Skips retrying entirely when the request has a non-seekable body, since a partially-consumed stream can't be safely resent.

        
On this page

Search results