-
Notifications
You must be signed in to change notification settings - Fork 500
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
Only include the port number in the Host
header when it differs from default
#238
Conversation
Host
header when it differs from defaultHost
header when it differs from default
Current coverage is 92.22% (diff: 100%)@@ master #238 diff @@
==========================================
Files 21 21
Lines 1762 1762
Methods 156 156
Messages 0 0
Branches 0 0
==========================================
Hits 1625 1625
Misses 137 137
Partials 0 0
|
Thanks for applying my suggestion. One detail that was missed is that you also need to check if the scheme is present. It is possible that the scheme was not specified and it will not be set. either !empty($url_parts['scheme']) or isset($url_parts['scheme']) is necessary here. The current logic if the scheme was foo://example.com:81 it will not set the port in the "Hosts: example.com". logic currently in place that fails this foo://example.com:81/ ::
Logic that passes foo://example.com:81/ ::
Note this is a slight change to my original patch. |
Sorry my last reply did not address the situation where the scheme was not specified. Please see this patch for a better example how to write this logic, it catches all cases, if the protocol is specified, not specified and if a custom port is set or not. Update added strtolower() in switch line to handle when scheme may have capital letters. |
Here are some test cases:
|
@amandato Thanks for expanding on your concerns. Thanks for the example test cases too, I'm yet to actually write any Requests unit tests, but I'll see if I can work out how to test these. |
Based on RFC 7230, it seems like we shouldn't do this at all?
That said, seems like a no-brainer to do it if we're already doing 80. |
Awesome! Yes that same RFC states "If the connection's incoming TCP port number On the server side, when the port is included the $_SERVER['HTTP_HOST'] then includes the port, which can confuse some PHP code for certain applications that do not expect the port for HTTP or HTTPS when 80/443 is used. There are special cases, such as https on port 80 and http on port 443, then the ports should be specified. I understand that it is a good idea NOT to support other scheme's. The drawback though your library does not support those URLs where the scheme still uses port 80 as default, such as feed:// or podcast://. podcast:// does not have a RFC though, another reason not to directly support it. But there are other scheme's such as feed:// that have been proposed they are just almost never used. For your reference: http://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml I would keep things the way they are, just providing additional info. Thanks for a great library! |
Based on @amandato in https://core.trac.wordpress.org/ticket/37991