Fix OPTIONS
This commit is contained in:
parent
eaad220738
commit
c7f2ba213b
4 changed files with 9 additions and 6 deletions
|
@ -32,6 +32,7 @@ use Friendica\Core\Hook;
|
|||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Theme;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -378,7 +379,7 @@ class Page implements ArrayAccess
|
|||
*/
|
||||
public function exit(ResponseInterface $response)
|
||||
{
|
||||
header(sprintf("HTTP/%s %i %s",
|
||||
header(sprintf("HTTP/%s %s %s",
|
||||
$response->getProtocolVersion(),
|
||||
$response->getStatusCode(),
|
||||
$response->getReasonPhrase())
|
||||
|
|
|
@ -191,23 +191,23 @@ abstract class BaseModule implements ICanHandleRequests
|
|||
public function run(array $request = []): ResponseInterface
|
||||
{
|
||||
// @see https://github.com/tootsuite/mastodon/blob/c3aef491d66aec743a3a53e934a494f653745b61/config/initializers/cors.rb
|
||||
if (substr($request['pagename'] ?? '', 0, 12) == '.well-known/') {
|
||||
if (substr($this->args->getQueryString(), 0, 12) == '.well-known/') {
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
|
||||
$this->response->setHeader(Router::GET, 'Access-Control-Allow-Methods');
|
||||
$this->response->setHeader('false', 'Access-Control-Allow-Credentials');
|
||||
} elseif (substr($request['pagename'] ?? '', 0, 8) == 'profile/') {
|
||||
} elseif (substr($this->args->getQueryString(), 0, 8) == 'profile/') {
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
|
||||
$this->response->setHeader(Router::GET, 'Access-Control-Allow-Methods');
|
||||
$this->response->setHeader('false', 'Access-Control-Allow-Credentials');
|
||||
} elseif (substr($request['pagename'] ?? '', 0, 4) == 'api/') {
|
||||
} elseif (substr($this->args->getQueryString(), 0, 4) == 'api/') {
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
|
||||
$this->response->setHeader(implode(',', Router::ALLOWED_METHODS), 'Access-Control-Allow-Methods');
|
||||
$this->response->setHeader('false', 'Access-Control-Allow-Credentials');
|
||||
$this->response->setHeader('Link', 'Access-Control-Expose-Headers');
|
||||
} elseif (substr($request['pagename'] ?? '', 0, 11) == 'oauth/token') {
|
||||
} elseif (substr($this->args->getQueryString(), 0, 11) == 'oauth/token') {
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
|
||||
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
|
||||
$this->response->setHeader(Router::POST, 'Access-Control-Allow-Methods');
|
||||
|
|
|
@ -140,6 +140,6 @@ class Response implements ICanCreateResponses
|
|||
// Setting the response type as an X-header for direct usage
|
||||
$this->headers[static::X_HEADER] = $this->type;
|
||||
|
||||
return new \GuzzleHttp\Psr7\Response($this->status, $this->headers, $this->content, $this->reason);
|
||||
return new \GuzzleHttp\Psr7\Response($this->status, $this->headers, $this->content, '1.1', $this->reason);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Friendica\Test\src\Module\Special;
|
||||
|
||||
use Friendica\App\Arguments;
|
||||
use Friendica\App\Page;
|
||||
use Friendica\App\Router;
|
||||
use Friendica\Capabilities\ICanCreateResponses;
|
||||
use Friendica\DI;
|
||||
|
|
Loading…
Reference in a new issue