Thanks to visit codestin.com
Credit goes to github.com

Skip to content

UrlGenerator too eager to include port number in absolute urls #8561

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

Closed
TomiS opened this issue Jul 24, 2013 · 10 comments
Closed

UrlGenerator too eager to include port number in absolute urls #8561

TomiS opened this issue Jul 24, 2013 · 10 comments

Comments

@TomiS
Copy link

TomiS commented Jul 24, 2013

I have Apache listening port 8080 and Varnish listening port 80. It seems when I generate an absolute url with router, it adds port 8080 automatically. I'd like not to have any explicit ports in url even if I generate absolute urls

It seems to happen because of this code in Routing component's UrlGenerator.php

if (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) {
    $port = '';
    if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
        $port = ':'.$this->context->getHttpPort();
    } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
        $port = ':'.$this->context->getHttpsPort();
    }

    $schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : "$scheme://";
    $schemeAuthority .= $host.$port;
}

Is this a bug or a feature or am I doing something wrong?

@Flask
Copy link

Flask commented Jul 24, 2013

Im not able to reproduce this error with a similar setup. Have you got

        if (req.http.X-Forwarded-Proto == "https" ) {
            set req.http.X-Forwarded-Port = "443";
        } else {
            set req.http.X-Forwarded-Port = "80";
        }

in your vcl_recv?

@TomiS
Copy link
Author

TomiS commented Jul 24, 2013

@Flask I tried adding your code to the beginning of vlc_recv and confirmed it gets called. But it didn't help. I wonder if this is an Apache issue after all. My Apache version is 2.2.22.

@TomiS
Copy link
Author

TomiS commented Jul 24, 2013

If I dump $SERVER I get following:

  'REDIRECT_STATUS' => string '200' (length=3)
  'HTTP_HOST' => string '10.211.14.7' (length=11)
  'HTTP_CACHE_CONTROL' => string 'max-age=0' (length=9)
  'HTTP_ACCEPT' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' (length=63)
  'HTTP_USER_AGENT' => string 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36' (length=119)
  'HTTP_ACCEPT_ENCODING' => string 'gzip,deflate,sdch' (length=17)
  'HTTP_ACCEPT_LANGUAGE' => string 'en-US,en;q=0.8' (length=14)
  'HTTP_COOKIE' => string '__utma=115165319.1729105269.1363162429.1370251221.1370256885.28; __utmc=115165319; __utmz=115165319.1363162429.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=or2506qvfv227ie001vuj38r30' (length=198)
  'HTTP_SURROGATE_CAPABILITY' => string 'abc=ESI/1.0' (length=11)
  'HTTP_X_FORWARDED_FOR' => string '80, 10.211.14.2' (length=15)
  'HTTP_X_VARNISH' => string '1085221840' (length=10)
  'PATH' => string '/usr/local/bin:/usr/bin:/bin' (length=28)
  'SERVER_SIGNATURE' => string '<address>Apache/2.2.22 (Ubuntu) Server at 10.211.14.7 Port 8080</address>
' (length=74)
  'SERVER_SOFTWARE' => string 'Apache/2.2.22 (Ubuntu)' (length=22)
  'SERVER_NAME' => string '10.211.14.7' (length=11)
  'SERVER_ADDR' => string '127.0.0.1' (length=9)
  'SERVER_PORT' => string '8080' (length=4)
  'REMOTE_ADDR' => string '127.0.0.1' (length=9)
  'DOCUMENT_ROOT' => string '/home/rohea/wwwroot' (length=19)
  'SERVER_ADMIN' => string 'webmaster@localhost' (length=19)
  'SCRIPT_FILENAME' => string '/home/rohea/wwwroot/app_dev.php' (length=31)
  'REMOTE_PORT' => string '56416' (length=5)
  'REDIRECT_URL' => string '/oma_keittio/' (length=13)
  'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
  'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
  'REQUEST_METHOD' => string 'GET' (length=3)
  'QUERY_STRING' => string '' (length=0)
  'REQUEST_URI' => string '/oma_keittio/' (length=13)
  'SCRIPT_NAME' => string '/app_dev.php' (length=12)
  'PHP_SELF' => string '/app_dev.php' (length=12)
  'REQUEST_TIME' => int 1374578958

Still wondering if this is about Apache or Symfony

@jakzal
Copy link
Contributor

jakzal commented Jul 24, 2013

relates to #3341

@TomiS read: http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html
Have you confirmed the headers are being passed with the request to Symfony? Try dumping the request headers.

@TomiS
Copy link
Author

TomiS commented Jul 25, 2013

@jakzal Thanks. After all it was about trusting proxies... I tried lots of stuff and finally noticed there was a flag trust_proxy_headers: false in configuration. (Who put that in there ;). So I turned it on and added proper X-Forwarded-Port to Varnish config and voilà.

Would it be ok to add a short notice about the config flag in documentation on the 'Trusting Proxies' page?

I think the X-forwarded stuff could also be added to 'How to use Varnish to speed up my Website'. I guess no-one can really live without that config if one does the port configs the same way as in example.

@TomiS
Copy link
Author

TomiS commented Jul 25, 2013

Closing this issue as invalid and swearing one of these days I'll report a real existing bug. :)

@TomiS TomiS closed this as completed Jul 25, 2013
@jakzal
Copy link
Contributor

jakzal commented Jul 25, 2013

@TomiS could you send a PR with a change you suggested to the https://github.com/symfony/symfony-docs? :)

@TomiS
Copy link
Author

TomiS commented Jul 25, 2013

@jakzal Already did. See above .

@jakzal
Copy link
Contributor

jakzal commented Jul 25, 2013

🍻

@Giuscar
Copy link

Giuscar commented Mar 18, 2021

Hello everyone,

Did you do any changes related to this topic? Actually I have the opposite problem: I want the port to appear when I generate my URL.. I am using the port 443 and the port is not shown in the absolute path....

Thanks.
Giuseppe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants