Skip to content

[HttpClient] Support invalid Location header #31776

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
mleczakm opened this issue May 31, 2019 · 4 comments
Closed

[HttpClient] Support invalid Location header #31776

mleczakm opened this issue May 31, 2019 · 4 comments

Comments

@mleczakm
Copy link
Contributor

mleczakm commented May 31, 2019

Symfony version(s) affected: 4.3.0

Description
Curl http client try to parse Location header even if no redirects allowed, which makes unable to get response/headers value from endpoint which returns invalid url in Location header.

How to reproduce

use Symfony\Component\HttpClient\CurlHttpClient;

// uses the cURL PHP extension
$httpClient = new CurlHttpClient();
$response = $httpClient->request('HEAD', 'http://test.mleczko.waw.pl', ['max_redirects' => 0]);

Results in InvalidArgumentException Malformed URL ..., no way to use value of this header.

Possible Solution
Simply check if we are gonna use Location value as redirect target - https://github.com/mleczakm/symfony/commit/5c27013e6b1c8f710821019f1ec64fc29f034d3b

@mleczakm mleczakm changed the title [HttpClient] [HttpClient] Support invalid Location header May 31, 2019
@nicolas-grekas
Copy link
Member

Would you mind sending a PR with the change and a test case please? Please check the result of calling getInfo(redirect_url)
Also, what's the point of replying with invalid location headers?

@mleczakm
Copy link
Contributor Author

mleczakm commented May 31, 2019

It's not me who are replying, it is api which works like that, probably to make it works with HEAD request - but I still don't know why someone choose Location header instead of something custom. Anyway, throwing error on invalid location when you don't gonna use it still seems buggy to me.

After some research I think it is not fixable without try-catch and rethrow when valid location required, so it is probably not worth implementing for this one edge use case :/

@mleczakm
Copy link
Contributor Author

mleczakm commented Jun 3, 2019

I've decided to close this issue, since implementing it is definitely not worth it - I've used plain curl requests for this edge-case and got confirmed what I've been thinking before - http standards should never be broken :)

@nicolas-grekas
Copy link
Member

I decided to fix it :)
See #31834

fabpot added a commit that referenced this issue Jun 5, 2019
…ocation header (nicolas-grekas)

This PR was merged into the 4.3 branch.

Discussion
----------

[HttpClient] Don't throw InvalidArgumentException on bad Location header

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31776
| License       | MIT
| Doc PR        | -

Instead, just stop following redirections and throw a `RedirectionExceptionInterface` as usual when throwing is not disabled.

Commits
-------

4acca42 [HttpClient] Don't throw InvalidArgumentException on bad Location header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants