]> git.mxchange.org Git - friendica.git/commitdiff
Support HTTP OPTIONS requests
authorMichael <heluecht@pirati.ca>
Wed, 9 Jun 2021 07:27:42 +0000 (07:27 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 9 Jun 2021 07:27:42 +0000 (07:27 +0000)
src/App/Module.php
src/App/Router.php

index 7ad4261aa60945320a45a74a4d57db51d1c39fce..8cc4dd7109cafb5aa3e37ba6372f3a8305479a05 100644 (file)
@@ -265,6 +265,16 @@ class Module
                        $logger->debug('index.php: page not found.', ['request_uri' => $server['REQUEST_URI'], 'address' => $server['REMOTE_ADDR'], 'query' => $server['QUERY_STRING']]);
                }
 
+               if ($server['REQUEST_METHOD'] === Router::OPTIONS) {
+                       header('HTTP/1.1 204 No Content');
+                       header('access-control-allow-credentials: true');
+                       header('access-control-allow-headers: Authorization,Content-Type');
+                       header('access-control-allow-methods: ' . implode(',', Router::ALLOWED_METHODS));
+                       header('access-control-allow-origin: *');
+                       header('access-control-max-age: 86400');
+                       exit();
+               }
+
                $placeholder = '';
 
                $profiler->set(microtime(true), 'ready');
index c18c048eaa8db0ac3a32a94f7d2a56c8534d2587..82c493baa6b66db97f4fc40dd47bcda98a79596e 100644 (file)
@@ -44,11 +44,12 @@ use Friendica\Network\HTTPException;
  */
 class Router
 {
-       const DELETE = 'DELETE';
-       const GET    = 'GET';
-       const PATCH  = 'PATCH';
-       const POST   = 'POST';
-       const PUT    = 'PUT';
+       const DELETE  = 'DELETE';
+       const GET     = 'GET';
+       const PATCH   = 'PATCH';
+       const POST    = 'POST';
+       const PUT     = 'PUT';
+       const OPTIONS = 'OPTIONS';
 
        const ALLOWED_METHODS = [
                self::DELETE,
@@ -56,6 +57,7 @@ class Router
                self::PATCH,
                self::POST,
                self::PUT,
+               self::OPTIONS
        ];
 
        /** @var RouteCollector */