Skip to content

Fix populating default port and headers in HttpFoundationFactory #78

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

Merged
merged 1 commit into from
Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Factory/HttpFoundationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function createRequest(ServerRequestInterface $psrRequest, bool $streamed

if ($uri instanceof UriInterface) {
$server['SERVER_NAME'] = $uri->getHost();
$server['SERVER_PORT'] = $uri->getPort();
$server['SERVER_PORT'] = $uri->getPort() ?: ('https' === $uri->getScheme() ? 443 : 80);
$server['REQUEST_URI'] = $uri->getPath();
$server['QUERY_STRING'] = $uri->getQuery();

Expand All @@ -74,7 +74,7 @@ public function createRequest(ServerRequestInterface $psrRequest, bool $streamed
$server,
$streamed ? $psrRequest->getBody()->detach() : $psrRequest->getBody()->__toString()
);
$request->headers->replace($psrRequest->getHeaders());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can the created request know about the headers of the psr one if we remove this line?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are already parsed few lines above. Without this line removed there is no way to use basic auth with Symfony - header is parsed during request object creation few lines above and then parsed user/password values are being overriden here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the line and replaced "replace()" by "add()". This should provide better compat.

$request->headers->add($psrRequest->getHeaders());

return $request;
}
Expand Down