-
-
Notifications
You must be signed in to change notification settings - Fork 34
[Swoole PSR7] Fix ServerRequest header Nyholm PSR7 #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @Nyholm, can you check this PR ? thx |
@@ -39,7 +39,7 @@ public function handle(Request $request, Response $response): void | |||
$psrRequest = (new \Nyholm\Psr7\ServerRequest( | |||
$request->getMethod(), | |||
$request->server['request_uri'] ?? '/', | |||
array_change_key_case($request->server ?? [], CASE_UPPER), | |||
$request->header ?? [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CASE_UPPER
looks strange here. If I look at the the ServerRequest, it always converts uppercase to lowercase so CASE_LOWER
would maybe make more sense: https://github.com/Nyholm/psr7/blob/f734364e38a876a23be4d906a2a089e1315be18a/src/MessageTrait.php#L147
It is also converted in other class to uppercase here:
array_change_key_case($request->server ?? [], CASE_UPPER), |
@Nyholm what do you think?
If we change it we would need todo this in all classes to be consistent.
@pistej What type of error you are trying to solve. Can you try to create a test case? Without a test case things get lost over the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error is, that headers from any request send to swoole server are not available in Nyholm ServerRequest -> here is wrong assignmen, dont know why $request->server
is set to $header parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, why remove the array_change_key_case
? can we not keep that then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still the same here:
array_change_key_case($request->server ?? [], CASE_UPPER), |
Is there any difference between swoole and openswoole here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think headers keys are case-insensitive besed on RFC 7230 and more validation is done in ServerRequest __construct
, setHeader
is called and then validateAndTrimHeader
from MessageTrait, so just assign without modifying is ok
https://github.com/Nyholm/psr7/blob/master/src/MessageTrait.php#L138
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in SymfonyHttpBridge there is new SymfonyRequest
and on this line 30 is set $server
in construct, this assingnemt is ok, server to server, and ServeBag is created https://github.com/symfony/http-foundation/blob/6.1/Request.php#L274 where all upsercasse keys are used, which is good https://github.com/symfony/http-foundation/blob/6.1/ServerBag.php#L26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and no, there's no diff. between swoole and openswoole in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
When using swoole app with PSR7, heades are not correctly set from Swoole\Http\Request to \Nyholm\Psr7\ServerRequest