Skip to content

Commit

Permalink
Add ExceptionHandler parameters to static constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Nov 9, 2024
1 parent addae97 commit 82d25ce
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/SocketHttpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 82d25ce

Please sign in to comment.