Responding Before Handling Request in Middleware (version 4)

In version 3, middleware accepts 3 arguments:

  1. \Psr\Http\Message\ServerRequestInterface - The PSR7 request object
  2. \Psr\Http\Message\ResponseInterface - The PSR7 response object
  3. callable - The next middleware callable

In version 4 middleware has

  1. Psr\Http\Message\ServerRequestInterface - The PSR-7 request object
  2. Psr\Http\Server\RequestHandlerInterface - The PSR-15 request handler object

This is confusing to me because, while authenticating for example, if the user isn’t authorized I want to return a response without calling the handler. Do I need to create a new Response, if so how do I do that?

Edit: I figured it out, you create a new response with

$response = $app->getResponseFactory()->createResponse();

It was a bit hard to find, it isn’t mentioned anywhere, I just saw it being used in Custom Error Handlers part of the guide.