# DebugRouteMiddleware

> Serves the debugger endpoints under the configured route prefix and passes every other request through.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Middleware](/docs/extensions/yii3-debug/reference/middleware/index.md) › DebugRouteMiddleware

| final readonly class | `Yii3\Debug\Middleware\DebugRouteMiddleware` |
| --- | --- |
| Implements | `Psr\Http\Server\MiddlewareInterface` |
| Source | [`src/Middleware/DebugRouteMiddleware.php`](https://github.com/yii3/debug/blob/main/src/Middleware/DebugRouteMiddleware.php#L22) |

Serves the debugger endpoints under the configured route prefix and passes every other request through.

Register it before [`RequestCaptureMiddleware`](/docs/extensions/yii3-debug/reference/middleware/requestcapturemiddleware/index.md), so a debugger page is answered before the application pipeline
runs.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates debugger-route middleware with IP restrictions and optional deferred-capture finalization. | `DebugRouteMiddleware` |
| [`process()`](#method-process) | Serves a request targeting the debugger itself, and hands every other request to the next handler untouched. | `DebugRouteMiddleware` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Yiisoft\NetworkUtilities\IpRanges $allowedIpRanges, Yii3\Debug\Web\DebugRequestHandler $debugRequestHandler, Yii3\Debug\Capture\DeferredCapture|null $deferredCapture, Yii3\Debug\Middleware\ToolbarOptions $options)
```

Creates debugger-route middleware with IP restrictions and optional deferred-capture finalization.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$allowedIpRanges` | `Yiisoft\NetworkUtilities\IpRanges` | Ranges allowed to reach the debugger. |
| `$debugRequestHandler` | [`Yii3\Debug\Web\DebugRequestHandler`](/docs/extensions/yii3-debug/reference/web/debugrequesthandler/index.md) | Handler serving the debugger endpoints. |
| `$deferredCapture` | [`Yii3\Debug\Capture\DeferredCapture`](/docs/extensions/yii3-debug/reference/capture/deferredcapture/index.md)`\|null` | Holder of a capture still pending from an earlier request, or `null` when captures are finalized inside the pipeline. |
| `$options` | [`ToolbarOptions`](/docs/extensions/yii3-debug/reference/middleware/toolbaroptions/index.md) | Settings carrying the route prefix. |

### process() <span id="method-process"></span>

```php
public function process(Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Server\RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface
```

Serves a request targeting the debugger itself, and hands every other request to the next handler untouched.

A capture still pending from an earlier request is written before anything else, debugger pages and requests
from a disallowed address included: a worker that never dispatched the shutdown event stops the collectors
before serving them, so their activity stays out of that capture, and the capture reaches history at once. A
failing finalization propagates from the request that triggered it. [`RequestCaptureMiddleware`](/docs/extensions/yii3-debug/reference/middleware/requestcapturemiddleware/index.md) applies the
same rule, so the guarantee holds whichever of the two runs first.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | `Psr\Http\Message\ServerRequestInterface` | Request reaching the middleware. |
| `$handler` | `Psr\Http\Server\RequestHandlerInterface` | Next handler in the middleware stack. |

**Returns**

`Psr\Http\Message\ResponseInterface`: Debugger response, an empty `403 Forbidden` for a disallowed client, or the application response for any other path.

**Throws**

- [`Throwable`](https://www.php.net/manual/en/class.throwable.php): when the pending capture, the debugger endpoint, or the request handler fails.