]> git.mxchange.org Git - friendica.git/commitdiff
Fix App routing
authorPhilipp <admin@philipp.info>
Mon, 3 Jan 2022 18:55:47 +0000 (19:55 +0100)
committerPhilipp <admin@philipp.info>
Tue, 4 Jan 2022 19:59:28 +0000 (20:59 +0100)
src/App.php
src/Capabilities/ICanCreateResponses.php
src/Module/Special/Options.php
tests/src/Module/Special/OptionsTest.php

index c56222b63f5d7b52bfa9daf98b929b13842c68b7..f7c929820d308640f7b3156d684b58d997417d70 100644 (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);
index 96149bab108fa44010bb52abf602d823d2227d05..dbdc61d843a64b0bca16a2384618fb76a9c0ea24 100644 (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,
        ];
 
        /**
index ecc9e2e0c7762ed126059cb814a5a154e7441246..389e7a239de89a1432e104f23d90fe1ad168184f 100644 (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);
        }
 }
index 98010cd18f9029d06915a14882d0cf24ac26ebfa..ab85e7f8ca9dd29befb471d11087a79263c3db8c 100644 (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'));
        }