Fix App routing

This commit is contained in:
Philipp Holzer 2022-01-03 19:55:47 +01:00
parent 543e4be0a6
commit 37f850377e
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
4 changed files with 14 additions and 10 deletions

View file

@ -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);

View file

@ -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,
];
/**

View file

@ -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);
}
}

View file

@ -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'));
}