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

This commit is contained in:
Philipp 2022-01-04 20:47:17 +01:00
parent 35a2fd45af
commit 6dbbd08179
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
4 changed files with 3 additions and 23 deletions

View file

@ -262,7 +262,7 @@ class Router
$this->parameters = []; $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) { if ($this->args->getMethod() === static::OPTIONS) {
$routeOptions = $dispatcher->getOptions($cmd); $routeOptions = $dispatcher->getOptions($cmd);

View file

@ -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} * {@inheritDoc}
*/ */
@ -237,9 +225,6 @@ abstract class BaseModule implements ICanHandleRequests
case Router::PUT: case Router::PUT:
$this->put($request); $this->put($request);
break; break;
case Router::OPTIONS:
$this->options($request);
break;
} }
$timestamp = microtime(true); $timestamp = microtime(true);

View file

@ -34,13 +34,9 @@ use Friendica\Module\Response;
*/ */
class Options extends BaseModule class Options extends BaseModule
{ {
protected function options(array $request = []) protected function rawContent(array $request = [])
{ {
$allowedMethods = $this->parameters['AllowedMethods'] ?? []; $allowedMethods = $this->parameters['AllowedMethods'] ?? Router::ALLOWED_METHODS;
if (empty($allowedMethods)) {
$allowedMethods = Router::ALLOWED_METHODS;
}
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
$this->response->setHeader(implode(',', $allowedMethods), 'Allow'); $this->response->setHeader(implode(',', $allowedMethods), 'Allow');

View file

@ -40,7 +40,6 @@ class OptionsTest extends FixtureTest
self::assertEquals([ self::assertEquals([
'Allow' => [implode(',', [Router::GET, Router::POST])], 'Allow' => [implode(',', [Router::GET, Router::POST])],
ICanCreateResponses::X_HEADER => ['blank'], ICanCreateResponses::X_HEADER => ['blank'],
'Content-Type'
], $response->getHeaders()); ], $response->getHeaders());
self::assertEquals(implode(',', [Router::GET, Router::POST]), $response->getHeaderLine('Allow')); self::assertEquals(implode(',', [Router::GET, Router::POST]), $response->getHeaderLine('Allow'));
} }