From 82d25cea4825e9225031c5d42e98f0faf9c11288 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 9 Nov 2024 09:55:38 -0600 Subject: [PATCH] Add ExceptionHandler parameters to static constructors --- src/SocketHttpServer.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/SocketHttpServer.php b/src/SocketHttpServer.php index ea6f57ff..03aa7741 100644 --- a/src/SocketHttpServer.php +++ b/src/SocketHttpServer.php @@ -14,6 +14,7 @@ use Amp\Http\Server\Middleware\AllowedMethodsMiddleware; use Amp\Http\Server\Middleware\CompressionMiddleware; use Amp\Http\Server\Middleware\ConcurrencyLimitingMiddleware; +use Amp\Http\Server\Middleware\ExceptionHandlerMiddleware; use Amp\Http\Server\Middleware\ForwardedHeaderType; use Amp\Http\Server\Middleware\ForwardedMiddleware; use Amp\Socket\BindContext; @@ -70,6 +71,7 @@ public static function createForDirectAccess( ?int $concurrencyLimit = self::DEFAULT_CONCURRENCY_LIMIT, ?array $allowedMethods = AllowedMethodsMiddleware::DEFAULT_ALLOWED_METHODS, ?HttpDriverFactory $httpDriverFactory = null, + ?ExceptionHandler $exceptionHandler = null, ): self { $serverSocketFactory = new ConnectionLimitingServerSocketFactory(new LocalSemaphore($connectionLimit)); @@ -88,6 +90,10 @@ public static function createForDirectAccess( $middleware = []; + if ($exceptionHandler) { + $middleware[] = new ExceptionHandlerMiddleware($exceptionHandler); + } + if ($concurrencyLimit !== null) { $logger->notice(\sprintf("Request concurrency limited to %s simultaneous requests", $concurrencyLimit)); $middleware[] = new ConcurrencyLimitingMiddleware($concurrencyLimit); @@ -126,9 +132,14 @@ public static function createForBehindProxy( ?int $concurrencyLimit = self::DEFAULT_CONCURRENCY_LIMIT, ?array $allowedMethods = AllowedMethodsMiddleware::DEFAULT_ALLOWED_METHODS, ?HttpDriverFactory $httpDriverFactory = null, + ?ExceptionHandler $exceptionHandler = null, ): self { $middleware = []; + if ($exceptionHandler) { + $middleware[] = new ExceptionHandlerMiddleware($exceptionHandler); + } + if ($concurrencyLimit !== null) { $middleware[] = new ConcurrencyLimitingMiddleware($concurrencyLimit); }