From 37f850377e6c28bb58eb7c619c78040d4a816702 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 3 Jan 2022 19:55:47 +0100 Subject: [PATCH] Fix App routing --- src/App.php | 3 +-- src/Capabilities/ICanCreateResponses.php | 14 ++++++++------ src/Module/Special/Options.php | 2 ++ tests/src/Module/Special/OptionsTest.php | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/App.php b/src/App.php index c56222b63..f7c929820 100644 --- a/src/App.php +++ b/src/App.php @@ -710,8 +710,7 @@ class App $timestamp = microtime(true); $response = $module->run($input); $this->profiler->set(microtime(true) - $timestamp, 'content'); - if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML && - $response->getStatusCode() == 200) { + if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) { $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig); } else { $page->exit($response); diff --git a/src/Capabilities/ICanCreateResponses.php b/src/Capabilities/ICanCreateResponses.php index 96149bab1..dbdc61d84 100644 --- a/src/Capabilities/ICanCreateResponses.php +++ b/src/Capabilities/ICanCreateResponses.php @@ -31,18 +31,20 @@ interface ICanCreateResponses */ const X_HEADER = 'X-RESPONSE-TYPE'; - const TYPE_HTML = 'html'; - const TYPE_XML = 'xml'; - const TYPE_JSON = 'json'; - const TYPE_ATOM = 'atom'; - const TYPE_RSS = 'rss'; + const TYPE_HTML = 'html'; + const TYPE_XML = 'xml'; + const TYPE_JSON = 'json'; + const TYPE_ATOM = 'atom'; + const TYPE_RSS = 'rss'; + const TYPE_BLANK = 'blank'; const ALLOWED_TYPES = [ self::TYPE_HTML, self::TYPE_XML, self::TYPE_JSON, self::TYPE_ATOM, - self::TYPE_RSS + self::TYPE_RSS, + self::TYPE_BLANK, ]; /** diff --git a/src/Module/Special/Options.php b/src/Module/Special/Options.php index ecc9e2e0c..389e7a239 100644 --- a/src/Module/Special/Options.php +++ b/src/Module/Special/Options.php @@ -23,6 +23,7 @@ namespace Friendica\Module\Special; use Friendica\App\Router; use Friendica\BaseModule; +use Friendica\Module\Response; /** * Returns the allowed HTTP methods based on the route information @@ -44,5 +45,6 @@ class Options extends BaseModule // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS $this->response->setHeader(implode(',', $allowedMethods), 'Allow'); $this->response->setStatus(204); + $this->response->setType(Response::TYPE_BLANK); } } diff --git a/tests/src/Module/Special/OptionsTest.php b/tests/src/Module/Special/OptionsTest.php index 98010cd18..ab85e7f8c 100644 --- a/tests/src/Module/Special/OptionsTest.php +++ b/tests/src/Module/Special/OptionsTest.php @@ -21,7 +21,7 @@ class OptionsTest extends FixtureTest self::assertEquals('No Content', $response->getReasonPhrase()); self::assertEquals([ 'Allow' => [implode(',', Router::ALLOWED_METHODS)], - ICanCreateResponses::X_HEADER => ['html'], + ICanCreateResponses::X_HEADER => ['blank'], ], $response->getHeaders()); self::assertEquals(implode(',', Router::ALLOWED_METHODS), $response->getHeaderLine('Allow')); } @@ -39,7 +39,8 @@ class OptionsTest extends FixtureTest self::assertEquals('No Content', $response->getReasonPhrase()); self::assertEquals([ 'Allow' => [implode(',', [Router::GET, Router::POST])], - ICanCreateResponses::X_HEADER => ['html'], + ICanCreateResponses::X_HEADER => ['blank'], + 'Content-Type' ], $response->getHeaders()); self::assertEquals(implode(',', [Router::GET, Router::POST]), $response->getHeaderLine('Allow')); }