Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
make HEAD/GET method rewrite configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
azjezz committed Feb 10, 2020
1 parent c71cb58 commit 031136c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/router/BaseRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
use function Facebook\AutoloadMap\Generated\is_dev;

abstract class BaseRouter<+TResponder> {
public function __construct(
private RouterOptions $options = shape('head_rewrite' => true)
) {}

abstract protected function getRoutes(
): ImmMap<HttpMethod, ImmMap<string, TResponder>>;

Expand All @@ -33,7 +37,7 @@ final public function routeMethodAndPath(
}

if (
$method === HttpMethod::HEAD && $allowed === keyset[HttpMethod::GET]
$this->options['head_rewrite'] && $method === HttpMethod::HEAD && $allowed === keyset[HttpMethod::GET]
) {
list($responder, $data) = $resolver->resolve(HttpMethod::GET, $path);
$data = Dict\map($data, $value ==> \urldecode($value));
Expand Down
16 changes: 16 additions & 0 deletions src/router/RouterOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?hh // strict

/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

namespace Facebook\HackRouter;

type RouterOptions = shape(
'head_rewrite' => bool,
);
1 change: 1 addition & 0 deletions tests/lib/TestRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function __construct(
private dict<string, T> $routes,
private ?IResolver<T> $resolver = null,
) {
parent::__construct();
}

<<__Override>>
Expand Down

0 comments on commit 031136c

Please sign in to comment.