-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug]: Cors headers not set when cache was not enabled (#925)
* Fix: Cors header where set only when cache enabled * Apply php-cs-fixer changes --------- Co-authored-by: mcop1 <[email protected]>
- Loading branch information
Showing
4 changed files
with
85 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\DataHubBundle\Service; | ||
|
||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
/** @internal */ | ||
final class ResponseService implements ResponseServiceInterface | ||
{ | ||
/** | ||
* Removes CORS headers including Access-Control-Allow-Origin that should not be cached. | ||
*/ | ||
public function removeCorsHeaders(JsonResponse $response): void | ||
{ | ||
$response->headers->remove('Access-Control-Allow-Origin'); | ||
$response->headers->remove('Access-Control-Allow-Credentials'); | ||
$response->headers->remove('Access-Control-Allow-Methods'); | ||
$response->headers->remove('Access-Control-Allow-Headers'); | ||
} | ||
|
||
public function addCorsHeaders(JsonResponse $response): void | ||
{ | ||
$origin = '*'; | ||
if (!empty($_SERVER['HTTP_ORIGIN'])) { | ||
$origin = $_SERVER['HTTP_ORIGIN']; | ||
} | ||
|
||
$response->headers->set('Access-Control-Allow-Origin', $origin); | ||
$response->headers->set('Access-Control-Allow-Credentials', 'true'); | ||
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); | ||
$response->headers->set('Access-Control-Allow-Headers', 'Origin, Content-Type, X-Auth-Token'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\DataHubBundle\Service; | ||
|
||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
/** @internal */ | ||
interface ResponseServiceInterface | ||
{ | ||
public function removeCorsHeaders(JsonResponse $response): void; | ||
|
||
public function addCorsHeaders(JsonResponse $response): void; | ||
} |