From 94f4f739545c322594051fd7691825079e7f1399 Mon Sep 17 00:00:00 2001 From: azjezz Date: Thu, 13 Feb 2020 17:59:56 +0100 Subject: [PATCH] make HEAD/GET method rewrite configurable --- src/router/BaseRouter.php | 6 +++++- src/router/BaseRouterOptions.php | 16 ++++++++++++++++ tests/lib/TestRouter.php | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/router/BaseRouterOptions.php diff --git a/src/router/BaseRouter.php b/src/router/BaseRouter.php index ea8e955..02ac008 100644 --- a/src/router/BaseRouter.php +++ b/src/router/BaseRouter.php @@ -14,6 +14,10 @@ use function Facebook\AutoloadMap\Generated\is_dev; abstract class BaseRouter<+TResponder> { + public function __construct( + private BaseRouterOptions $options = shape('use_get_responder_for_head' => true) + ) {} + abstract protected function getRoutes( ): KeyedContainer>; @@ -33,7 +37,7 @@ final public function routeMethodAndPath( } if ( - $method === HttpMethod::HEAD && $allowed === keyset[HttpMethod::GET] + $this->options['use_get_responder_for_head'] && $method === HttpMethod::HEAD && $allowed === keyset[HttpMethod::GET] ) { list($responder, $data) = $resolver->resolve(HttpMethod::GET, $path); $data = Dict\map($data, $value ==> \urldecode($value)); diff --git a/src/router/BaseRouterOptions.php b/src/router/BaseRouterOptions.php new file mode 100644 index 0000000..de0281f --- /dev/null +++ b/src/router/BaseRouterOptions.php @@ -0,0 +1,16 @@ + bool, +); diff --git a/tests/lib/TestRouter.php b/tests/lib/TestRouter.php index 53cdbd0..1ac6e26 100644 --- a/tests/lib/TestRouter.php +++ b/tests/lib/TestRouter.php @@ -21,6 +21,7 @@ public function __construct( private dict $routes, private ?IResolver $resolver = null, ) { + parent::__construct(); } <<__Override>>