Bug Fix: Pick port defaults depending if the host was in HTTP_HOST or SERVER #2487
Conversation
|
In a case that someone should have an application (intranet apps) running on a different port, I don't think this change would work. e.g. |
Actually, I think that this scenario would continue to work as the i.e. when I run |
|
I think it's reasonable to default to port 80 if HTTP_HOST is set. We need to consider SSL though as that needs the port to be set to 443, so may be we need to check |
|
Hmm, this is a really good point. Because the default should be 443 or 80, depending on the protocol, but I'm not sure we always know the protocol of the incoming request, only what the local server is using. If I use https:// for my ngrok tunnel, I still don't get that (default 443) port number in the |
|
For tunneled requests these could be derived from |
|
I've looked it up. According to the spec, if the i.e. if the port is missing from |
|
At the risk of thickening the plot, we don't have scheme either. Reading the git history the |
|
Yes, you’d still need rka-scheme-and-host-middleware (now renamed to proxy-detection-middleware) to pick up the scheme. That middleware should probably handle the port better too. Further thinking about the |
If there is a Host header, then we can expect the port to be part of it. If the port is not there, then we should use the default for the scheme as per RFC 2616, section 14.23.
Also remove test where SERVER_PORT is used when Host header exists as this was an incorrect assumption that is wrong.
|
This works perfectly for me (using the middleware as well) both locally with a custom port number and with the ngrok tunnel in front of it. |
|
Thanks. |
This change relates to #2486 where a local server on port 8080 receiving a request from ngrok that is on port 80 ends up with a URI containing the ngrok host but the local server port number. This change fixes it for me BUT it causes a test to fail (
UriTest::testCreateEnvironmentWithIPv6HostNoPort) because the test expects the response to be port 8080, but I'm not sure I agree that's the right behaviour. I can fix the test if we can agree that NULL is the expected response togetPort()called on a request without a port number?