-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Support protocol relative URL in HTTP Client. #11163
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
Some servers set //example.com as a Location header. `buildUrl()` needs to support that in order to build absolute urls.
Codecov Report
@@ Coverage Diff @@
## master #11163 +/- ##
============================================
- Coverage 94.86% 93.15% -1.71%
- Complexity 12859 12980 +121
============================================
Files 437 437
Lines 32774 33621 +847
============================================
+ Hits 31090 31319 +229
- Misses 1684 2302 +618
Continue to review full report at Codecov.
|
Can you explain the actual use case this is for please. Do you mean the reason for this change is to follow redirects like so: ? Feels like there is significant scope for "upgrading broke my app" with this as |
Yes. To me it looks like a bug that those URL weren't supported. |
|
In the scope of a location header the change makes sense, but it applies much broader than that I think this is a problem: I could be wrong, but I feel the right place for fixing that problem is https://github.com/cakephp/cakephp/blob/master/src/Http/Client.php#L401-L402 For comparison, curl doesn't understand protocol-relative urls: unless they are in a location header: Note also that there is no need to use preg_match to test if a string matches one permutation. |
|
Maybe the if (isset($options['scheme'] && (substr($url, 0, 2) === '//')) {
$url = $options['scheme'] . ':' . $url;
}
...
$options += $defaults; |
|
@AD7six rfc 7231 states that |
|
@markstory my concern/point is that a request like this https://cakephp.org//css/cake.css is a valid response on most webservers, and is affected by the modified code. It's easy to write code which would make a request like that: The behavior of this request is going to significantly change when this PR is merged. Hoping that's understood (if it already is - well 🤷♂️ :)) - I have no problem with the intended scope of the PR (handling protocol relative redirects) as I previously mentioned. |
|
That's a good point @AD7six I hadn't considered that. @robertpustulka Is there a way your change could be scoped closer to where Location headers are followed? Perhaps the scheme should only be applied if the scheme option was set as you mentioned earlier. |
|
Protocol relative fix is now opt-in. I added a |
|
Nice work! |
Some servers set
//example.comas aLocationheader.buildUrl()needs to support that in order to build absolute urls.