# DebugRequestHandler

> Serves the debugger endpoints from the toolbar middleware, without a route declaration.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Web](/docs/extensions/yii3-debug/reference/web/index.md) › DebugRequestHandler

| final class | `Yii3\Debug\Web\DebugRequestHandler` |
| --- | --- |
| Source | [`src/Web/DebugRequestHandler.php`](https://github.com/yii3/debug/blob/main/src/Web/DebugRequestHandler.php#L35) |

Serves the debugger endpoints from the toolbar middleware, without a route declaration.

Endpoints are resolved lazily from the container, so a request the debugger does not own costs no action
instantiation.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates the debugger endpoint handler resolved through the container. | `DebugRequestHandler` |
| [`forbidden()`](#method-forbidden) | Rejects a client that may not reach the debugger. | `DebugRequestHandler` |
| [`handle()`](#method-handle) | Serves the endpoint the path selects. | `DebugRequestHandler` |

## Method details

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

```php
public function __construct(Psr\Container\ContainerInterface $container, Psr\Http\Message\ResponseFactoryInterface $responseFactory, Yii3\Debug\Middleware\ToolbarOptions $options = new \Yii3\Debug\Middleware\ToolbarOptions())
```

Creates the debugger endpoint handler resolved through the container.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$container` | `Psr\Container\ContainerInterface` | Container the endpoint is resolved from when the path matches. |
| `$responseFactory` | `Psr\Http\Message\ResponseFactoryInterface` | Factory building the rejection responses. |
| `$options` | [`Yii3\Debug\Middleware\ToolbarOptions`](/docs/extensions/yii3-debug/reference/middleware/toolbaroptions/index.md) | Settings carrying the route prefix the debugger endpoints are served under. |

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

```php
public function forbidden(): Psr\Http\Message\ResponseInterface
```

Rejects a client that may not reach the debugger.

**Returns**

`Psr\Http\Message\ResponseInterface`: Empty `403 Forbidden` response, marked `Cache-Control: no-store`.

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

```php
public function handle(Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface
```

Serves the endpoint the path selects.

Every response carries `Cache-Control: no-store`, so captured request data never reaches a shared cache or the
browser history.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | `Psr\Http\Message\ServerRequestInterface` | Request targeting the debugger. |

**Returns**

`Psr\Http\Message\ResponseInterface`: Endpoint response, an empty `404 Not Found` for an unknown path, or an empty `405 Method Not Allowed` for a write method.

**Throws**

- [`RuntimeException`](https://www.php.net/manual/en/class.runtimeexception.php): when the container resolves the endpoint to something else.