From d899e12606ce01971eb96a3af4403c37d55a7311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Andr=C3=A9=20Bocanegra=20Palacios?= Date: Tue, 22 Dec 2020 02:42:53 -0500 Subject: [PATCH 1/5] Update CorsMiddleware.php Workaround for OPTIONS method --- src/Routing/Middleware/CorsMiddleware.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Routing/Middleware/CorsMiddleware.php b/src/Routing/Middleware/CorsMiddleware.php index 0e6ba12..7cd7863 100644 --- a/src/Routing/Middleware/CorsMiddleware.php +++ b/src/Routing/Middleware/CorsMiddleware.php @@ -6,6 +6,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use Cake\Http\Response; class CorsMiddleware implements MiddlewareInterface { @@ -16,7 +17,20 @@ class CorsMiddleware implements MiddlewareInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $response = $handler->handle($request); + if (strtoupper($request->getMethod()) === 'OPTIONS') { + if (!array_intersect($request->getHeader("Access-Control-Request-Method"), Configure::read('Cors.AllowMethods'))) { + $response = new Response([ + 'status' => 403, + 'body' => 'Method Forbidden' + ]); + } else { + $response = new Response([ + 'status' => 200 + ]); + } + } else { + $response = $handler->handle($request); + } $response = $this->addHeaders($request, $response); From 4087a6083b046e8dc664ee66dbe0c4da850281f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Andr=C3=A9=20Bocanegra=20Palacios?= Date: Sat, 9 Jan 2021 11:07:36 -0500 Subject: [PATCH 2/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b3ae5a6..9fb97a8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Build Status](https://travis-ci.org/ozee31/cakephp-cors.svg?branch=master)](https://travis-ci.org/ozee31/cakephp-cors) +It's a pull request from [ozee31/cakephp-cors](https://github.com/ozee31/cakephp-cors). + A CakePHP (4+) plugin for activate cors domain in your application with [Middleware](http://book.cakephp.org/3.0/en/controllers/middleware.html). [Learn more about CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) From e8dcbb547b4e4b2552438fb7c76f63f94c69d9fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Andr=C3=A9=20Bocanegra=20Palacios?= Date: Sat, 9 Jan 2021 11:08:56 -0500 Subject: [PATCH 3/5] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 96754c3..68c3395 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "ozee31/cakephp-cors", - "description": "A CakePHP (3.3.x) plugin for activate cors domain in your application", + "name": "rabp99/cakephp-cors", + "description": "It's a pull request from ozee31/cakephp-cors that solve the issue about OPTIONS method. A CakePHP 4 plugin for activate cors domain in your application", "type": "cakephp-plugin", "require": { "php": ">=7.2.0", From 3a44f539c0d45292f24b589b11b6e97291767a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Andr=C3=A9=20Bocanegra=20Palacios?= Date: Sun, 27 Feb 2022 13:10:49 -0500 Subject: [PATCH 4/5] Update composer.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lucas CorrĂȘa --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 68c3395..042973f 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "rabp99/cakephp-cors", + "name": "ozee31/cakephp-cors", "description": "It's a pull request from ozee31/cakephp-cors that solve the issue about OPTIONS method. A CakePHP 4 plugin for activate cors domain in your application", "type": "cakephp-plugin", "require": { From e61c905e6cb6dc85bf74b4c0cdfedf76c4462ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Andr=C3=A9=20Bocanegra=20Palacios?= Date: Sun, 27 Feb 2022 13:11:37 -0500 Subject: [PATCH 5/5] Update composer.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lucas CorrĂȘa --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 042973f..fdf556a 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ozee31/cakephp-cors", - "description": "It's a pull request from ozee31/cakephp-cors that solve the issue about OPTIONS method. A CakePHP 4 plugin for activate cors domain in your application", + "description": "A CakePHP 4 plugin for activate cors domain in your application", "type": "cakephp-plugin", "require": { "php": ">=7.2.0",