Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Use the Host port when port forwarding is detected #4

Merged

Conversation

weierophinney
Copy link
Member

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.

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.
@gianarb
Copy link
Contributor

gianarb commented Jun 15, 2015

👍

// 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.
Copy link
Contributor

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).

Copy link
Member Author

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.

Copy link
Contributor

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.
@weierophinney weierophinney added this to the 2.5.2 milestone Jun 15, 2015
@weierophinney
Copy link
Member Author

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.

@akrabat akrabat merged commit 27fecdb into zendframework:master Jun 15, 2015
weierophinney added a commit that referenced this pull request Jun 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants