Skip to content

[HttpClient] Psr18Client can't get custom HTTP status messages #51527

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
Hanmac opened this issue Aug 31, 2023 · 6 comments
Closed

[HttpClient] Psr18Client can't get custom HTTP status messages #51527

Hanmac opened this issue Aug 31, 2023 · 6 comments

Comments

@Hanmac
Copy link
Contributor

Hanmac commented Aug 31, 2023

Symfony version(s) affected

5,4, 6.4

Description

for example if some API i want to connect uses HTTP Status Codes like this:

HTTP/1.1 404 countryCodeNotFound

then when using Symfony HttpClient as its own Client, then the Exception sets the Message correct

but the Psr18Client doesn't parse the response_headers like the Exceptions do
https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php#L34

the Psr18Client sets the status code without trying to set the message too:
https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/HttpClient/Psr18Client.php#L108

How to reproduce

have an API with custom status messages:

HTTP/1.1 404 countryCodeNotFound

Possible Solution

Similar code that is done in the Exception Trait should also be done in the Psr18Client

Additional Context

No response

@nicolas-grekas
Copy link
Member

The HTTP status text is a thing of the past, HTTP/2 doesn't support it. I'd recommend not relying on this.

@Hanmac
Copy link
Contributor Author

Hanmac commented Sep 22, 2023

The HTTP status text is a thing of the past, HTTP/2 doesn't support it. I'd recommend not relying on this.

and Symfony Client still supports that.

the problem its that this one API doesn't have a meaningful body to be parsed on exceptions.
so i can't parse the body myself.

@nicolas-grekas
Copy link
Member

Up for sending a PR?

@Hanmac
Copy link
Contributor Author

Hanmac commented Sep 22, 2023

i will try to make a fix for Psr18Client next week

@OskarStark OskarStark changed the title [HttpClient] Psr18Client cant get Custom HTTP Status Messages [HttpClient] Psr18Client can't get custom HTTP status messages Oct 10, 2023
@nicolas-grekas
Copy link
Member

Don't forget about this one @Hanmac ;

@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 27, 2023

yeah! thanks for reminding me, i probably can work on this the next days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants