Skip to content

[HttpClient] Psr18Client: parse HTTP Reason Phrase for Response #52329

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

Closed
wants to merge 6 commits into from

Conversation

Hanmac
Copy link
Contributor

@Hanmac Hanmac commented Oct 27, 2023

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #51527
License MIT

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.4" but it seems your PR description refers to branch "6.4 for features / 5.4 or 6.3 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot
Copy link

It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title Psr18Client: parse HTTP Reason Phrase for Response [HttpClient] Psr18Client: parse HTTP Reason Phrase for Response Oct 27, 2023
@stof
Copy link
Member

stof commented Oct 27, 2023

How does this behave when the actual request is done with HTTP/2, which does not transmit a reason phrase ?

@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 27, 2023

How does this behave when the actual request is done with HTTP/2, which does not transmit a reason phrase ?

the Regex shouldn't find any, and then return nothing, and then the factory should fallback to the old one

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, here are some comments.

I think HttplugClient might need the same, can you have a look?

Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 27, 2023

It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you.

Cheers!

Carsonbot

Where can I check this right now?

I didn't saw it when making this MR

@stof
Copy link
Member

stof commented Oct 27, 2023

I'm not sure this checkbox exists for PRs sent from a fork owned by an organization instead of a user.

@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 28, 2023

i probably need to do some trickery with responseFactory->createResponse and the amount of parameters.

while the Response class allows the Reason Phase to be null (and falls back to the hard codes ones, MAYBE)
the factory doesn't allow null as parameter, and passing empty string is not the same as passing 1 parameter.

so i probably need to do something like:

$responseParameters = [$response->getStatusCode()];
if ($phrase = $this->getReasonPhrase($response)) {
  $responseParameters []= $phrase;
}

$psrResponse = $this->responseFactory->createResponse(...$responseParameters);

i need to try this after weekend

@derrabus derrabus removed the Bug label Oct 28, 2023
Co-authored-by: Alexander M. Turek <me@derrabus.de>
Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

This test failure appears to be related.

1) Symfony\Component\HttpClient\Tests\Psr18ClientTest::testInvalidHeaderResponse
TypeError: Http\Discovery\Psr17Factory::createResponse(): Argument #2 ($reasonPhrase) must be of type string, null given, called in /home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Psr18Client.php on line 109

/home/runner/work/symfony/symfony/vendor/php-http/discovery/src/Psr17Factory.php:84
/home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Psr18Client.php:109
/home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php:101

@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 28, 2023

This test failure appears to be related.

1) Symfony\Component\HttpClient\Tests\Psr18ClientTest::testInvalidHeaderResponse
TypeError: Http\Discovery\Psr17Factory::createResponse(): Argument #2 ($reasonPhrase) must be of type string, null given, called in /home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Psr18Client.php on line 109

/home/runner/work/symfony/symfony/vendor/php-http/discovery/src/Psr17Factory.php:84
/home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Psr18Client.php:109
/home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php:101

That's why I said I need to at this maybe after weekend

@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 28, 2023

This test failure appears to be related.

1) Symfony\Component\HttpClient\Tests\Psr18ClientTest::testInvalidHeaderResponse
TypeError: Http\Discovery\Psr17Factory::createResponse(): Argument #2 ($reasonPhrase) must be of type string, null given, called in /home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Psr18Client.php on line 109

/home/runner/work/symfony/symfony/vendor/php-http/discovery/src/Psr17Factory.php:84
/home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Psr18Client.php:109
/home/runner/work/symfony/symfony/src/Symfony/Component/HttpClient/Tests/Psr18ClientTest.php:101

took my laptop to work on this thing ... see my idea above with the variable parameters

@Hanmac Hanmac requested a review from derrabus October 29, 2023 08:40
@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 29, 2023

The last failures seems to be unrelated?

@nicolas-grekas nicolas-grekas changed the base branch from 6.4 to 5.4 October 29, 2023 12:34
@nicolas-grekas nicolas-grekas changed the base branch from 5.4 to 6.4 October 29, 2023 12:36
@nicolas-grekas
Copy link
Member

Thank you @Hanmac.

nicolas-grekas added a commit that referenced this pull request Oct 29, 2023
…ponse (Hanmac)

This PR was submitted for the 6.4 branch but it was squashed and merged into the 5.4 branch instead.

Discussion
----------

[HttpClient] Psr18Client: parse HTTP Reason Phrase for Response

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #51527
| License       | MIT

Commits
-------

115a5a1 [HttpClient] Psr18Client: parse HTTP Reason Phrase for Response
@nicolas-grekas
Copy link
Member

Merged as 115a5a1 in 5.4
For your next PR, please allow edits from maintainers.

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented Oct 29, 2023

For your next PR, please allow edits from maintainers.

Edits were not possible because it was forked to an organization account.

@Hanmac Hanmac deleted the httpclient_reason_phrase branch October 29, 2023 20:38
@fabpot fabpot mentioned this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HttpClient] Psr18Client can't get custom HTTP status messages
6 participants