-
Notifications
You must be signed in to change notification settings - Fork 61
Use the Host port when port forwarding is detected #4
Use the Host port when port forwarding is detected #4
Conversation
In vagrant and other systems, you often have a port on the host forwarding to a port on the client box. In terms of ServerUrl, the port on the host server is the public one that should be used. Prior to this patch ServerUrl was detecting both the port from the Host header, as well as SERVER_PORT, and using *both* in generated URLs. As an example, given: HTTP_HOST: localhost:10088 SERVER_PORT: 10081 ServerUrl would generate the host "localhost:10088:10081", when it should be generating "localhost:10088". This patch corrects the situation.
👍 |
// If the Host header contains a port, and it differs from the | ||
// SERVER_PORT, use the port from the Host header. Typically | ||
// this is a situation where port-forwarding is in use, and you | ||
// want to present a URI using the public port. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment should be:
// If the Host header contains a port, then use this port. Typically
// this is a situation where port-forwarding is in use, and you
// want to present a URI using the public port.
or similar as we don't actually check that it differs from SERVER_PORT
(or need to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or similar as we don't actually check that it differs from SERVER_PORT (or need to).
There's a block immediately before it that does, actually. :) This is the condition that we hit if the SERVER_PORT and the HTTP_HOST's port are not equal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... we should probably extract the port from HTTP_HOST once then :)
- Per @akrabat, the logic for detecting the port based on the combination of the Host header and SERVER_PORT values needed to be cleaned up to make it more clear what was being done. The new approach tests for the combination of SERVER_PORT and a host header in the `<domain>:<port>` format, and uses PCRE matched groups to set the host and/or port.
As this was communicated from the Zend Server team, I'm also going to backport it to 2.4.3 as a critical fix for the LTS series. |
In vagrant and other systems, you often have a port on the host forwarding to a port on the client box. In terms of ServerUrl, the port on the host server is the public one that should be used.
Prior to this patch ServerUrl was detecting both the port from the Host header, as well as SERVER_PORT, and using both in generated URLs.
As an example, given:
ServerUrl would generate the host "localhost:10088:10081", when it should be generating "localhost:10088". This patch corrects the situation.