I think I uncovered a potential bug in
Zend_Controller_Action_Helper_Redirector, but I want to be sure. The
method Zend_Controller_Action_Helper_Redirector::_redirect() is
currently implemented this way:

    protected function _redirect($url)
    {
        if ($this->getUseAbsoluteUri() &&
!preg_match('#^(https?|ftp)://#', $url)) {
            $host  = (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'');
            $proto =
(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=="off") ? 'https' :
'http';
            $port  =
(isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80);
            $uri   = $proto . '://' . $host;
            if ((('http' == $proto) && (80 != $port)) || (('https' ==
$proto) && (443 != $port))) {
                $uri .= ':' . $port;
            }
            $url = $uri . '/' . ltrim($url, '/');
        }
        $this->_redirectUrl = $url;
        $this->getResponse()->setRedirect($url, $this->getCode());
    }

However, are the lines that assign a value to $port and the
corresponding if...then test that conditionally appends $port to $uri
necessary? In my experience, the port number for non-default ports is
already part of $_SERVER['HTTP_HOST'], so this seems redundant. Are
there instances where this is not the case?

I copied the logic from this method to a function I use to build
absolute URLs that get passed via JSON to a web browser. It worked
fine until we moved one of our applications to a new system behind a
load balancer. The public address is a typical host name such as
www.hostname.com that uses the default ports 80/443, but the request
is forwarded from the load balancer to a web server via an address
like 192.168.1.125:50001. When we moved the application to this
system, I noticed that the URLs being built in my function (using the
same logic as above) were for the hostname www.hostname.com:50001,
which is not a valid address/port assignment.



Andrew

Reply via email to