public function addMiddleware(callable $middleware) {
        $next = $this->middleware;

        $this->middleware = function (HttpRequest $request) use ($middleware, $next): HttpResponse {
            return $middleware($request, $next);
        };

        return $this;
    }
public function addMiddleware(callable $middleware) {
        $next = $this->middleware;

        $this->middleware = function (HttpRequest $request) use ($middleware, $next): HttpResponse {
            return $middleware($request, $next);
        };

        return $this;
    }
public function addMiddleware ( callable $ middleware ) { $ next = $ this -> middleware ; $ this -> middleware = function ( HttpRequest $ request ) use ( $ middleware , $ next ) : HttpResponse { return $ middleware ( $ request , $ next ) ; } ; return $ this ; }
Add a middleware function to the client.

A Middleware is a callable that has the following signature:

```php
function middleware(HttpRequest $request, callable $next): HttpResponse {
// Optionally modify the request.
$request->setHeader('X-Foo', 'bar');

// Process the request by calling $next. You must always call next.
$response = $next($request);

// Optionally modify the response.
$response->setHeader('Access-Control-Allow-Origin', '*');

return $response;
}
```

@param callable $middleware The middleware callback to add.
@return $this
Add a middleware function to the client .