Closed sergey-yabloncev closed 3 years ago
I cannot reproduce bug.
I get clean laravel installation
$ composer create-project laravel/laravel example-app
change supports_credentials
to true
in config/cors.php
file.
Get docker file and roadrunner config from this issue, (but i have to change http.address
to 0.0.0.0:8080
to avoid permission error)
Build image
$ docker build -t lara-test .
And run
$ docker run --rm -v"${PWD}:/var/www" -u"1000:1000" -p"8081:8080" lara-test
Header Access-Control-Allow-Credentials
is set to true
Sorry, I send not all parameters for cros.php. In cors.php file your need to change param paths on ['*'] below file with all configurations
<?php
return [
'paths' => ['*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
];
Yes, i reproduce an error.
The bug is in the asm89/stack-cors. Response header value must be string
or string[]
, but request header value is nulable. In this case header Origin
is null.
@tarampampam, maybe add AfterRequestHandlingEvent
handler that fix headers?
@jetexe sounds like good idea! Can you make a PR?
I've created an issue (https://github.com/asm89/stack-cors/issues/85) and PR (https://github.com/asm89/stack-cors/pull/86) into asm89/stack-cors
. I hope that bug fix will be applied soon.
@sergey-yabloncev, for now you can try this solution:
Put this listener into app/Listeners/FilterNullHeadersListener.php
<?php
declare(strict_types = 1);
namespace App\Listeners;
use Spiral\RoadRunnerLaravel\Events\Contracts\WithHttpResponse;
use Spiral\RoadRunnerLaravel\Listeners\ListenerInterface;
/**
* FilterNullHeadersListener handle event with http response to clear null valued headers.
*/
class FilterNullHeadersListener implements ListenerInterface
{
/**
* {@inheritDoc}
*/
public function handle($event): void
{
if ($event instanceof WithHttpResponse) {
foreach ($event->httpResponse()->headers->all() as $header => $values) {
$filteredArray = \array_filter($values);
if ($filteredArray === []) {
$event->httpResponse()->headers->remove($header);
} else {
$event->httpResponse()->headers->set($header, $filteredArray);
}
}
}
}
}
Add add it into config/roadrunner.php
<?php
return [
...
'listeners' => [
...
Events\AfterRequestHandlingEvent::class => [
\App\Listeners\FilterNullHeadersListener::class,
],
...
]
...
]
@jetexe Thank's!
Yes now, all work correctly! Thanks!
Describe the bug
If you want to install laravel 8 in the configuration file cors.php change the value of supports_credentials to true we get the following error
it seems to me that the fruitcake/laravel-cors package supplied by default with laravel 8 should be removed since roadrunner solves this case, and it may be worth documenting this moment
System information
PHP version 8,0,1 Current package version 3.7 RoadRunner version 1.9.2 Environment docker
RoadRunner configuration file content
config/roadrunner.php - standart
Additional context