From: Philipp <admin@philipp.info>
Date: Tue, 4 Jan 2022 19:47:17 +0000 (+0100)
Subject: Use rawContent for Special Options to avoid a protected options() method
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6dbbd081795fa1c8fe57db2248ac162efeeada88;p=friendica.git

Use rawContent for Special Options to avoid a protected options() method
---

diff --git a/src/App/Router.php b/src/App/Router.php
index fd1cec362f..c21dfd44d9 100644
--- a/src/App/Router.php
+++ b/src/App/Router.php
@@ -262,7 +262,7 @@ class Router
 
 		$this->parameters = [];
 
-		// Check if the HTTP method ist OPTIONS and return the special Options Module with the possible HTTP methods
+		// Check if the HTTP method is OPTIONS and return the special Options Module with the possible HTTP methods
 		if ($this->args->getMethod() === static::OPTIONS) {
 			$routeOptions = $dispatcher->getOptions($cmd);
 
diff --git a/src/BaseModule.php b/src/BaseModule.php
index c1a926a3a5..5ac56533ca 100644
--- a/src/BaseModule.php
+++ b/src/BaseModule.php
@@ -173,18 +173,6 @@ abstract class BaseModule implements ICanHandleRequests
 	{
 	}
 
-	/**
-	 * Module OPTIONS method to process submitted data
-	 *
-	 * Extend this method if the module is supposed to process OPTIONS requests.
-	 * Doesn't display any content
-	 *
-	 * @param string[] $request The $_REQUEST content
-	 */
-	protected function options(array $request = [])
-	{
-	}
-
 	/**
 	 * {@inheritDoc}
 	 */
@@ -237,9 +225,6 @@ abstract class BaseModule implements ICanHandleRequests
 			case Router::PUT:
 				$this->put($request);
 				break;
-			case Router::OPTIONS:
-				$this->options($request);
-				break;
 		}
 
 		$timestamp = microtime(true);
diff --git a/src/Module/Special/Options.php b/src/Module/Special/Options.php
index 389e7a239d..79ce5d0c2e 100644
--- a/src/Module/Special/Options.php
+++ b/src/Module/Special/Options.php
@@ -34,13 +34,9 @@ use Friendica\Module\Response;
  */
 class Options extends BaseModule
 {
-	protected function options(array $request = [])
+	protected function rawContent(array $request = [])
 	{
-		$allowedMethods = $this->parameters['AllowedMethods'] ?? [];
-
-		if (empty($allowedMethods)) {
-			$allowedMethods = Router::ALLOWED_METHODS;
-		}
+		$allowedMethods = $this->parameters['AllowedMethods'] ?? Router::ALLOWED_METHODS;
 
 		// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
 		$this->response->setHeader(implode(',', $allowedMethods), 'Allow');
diff --git a/tests/src/Module/Special/OptionsTest.php b/tests/src/Module/Special/OptionsTest.php
index ab85e7f8ca..460435ae24 100644
--- a/tests/src/Module/Special/OptionsTest.php
+++ b/tests/src/Module/Special/OptionsTest.php
@@ -40,7 +40,6 @@ class OptionsTest extends FixtureTest
 		self::assertEquals([
 			'Allow'                       => [implode(',', [Router::GET, Router::POST])],
 			ICanCreateResponses::X_HEADER => ['blank'],
-			'Content-Type'
 		], $response->getHeaders());
 		self::assertEquals(implode(',', [Router::GET, Router::POST]), $response->getHeaderLine('Allow'));
 	}