Symfony2: getScheme does not return 'https'

Inside the controller, I used the getSchemeAndHttpHost method to create the URL of another controller.

Everything works smoothly until I need to switch to https. All the URLs that I get with the getSchemeAndHttpHost function are still http. When troubleshooting, it turned out that the getScheme function always returns http, both when requesting a page using https or with http.

Did I miss something?

How can I find out if I went through http or https from my controller?

Edit - Additional Information

  • I checked the tests with a valid certificate.
  • If I run the isSecure method in the Request object, I always get false.
+4
source share
1 answer

Short answer

Add the following line to the controller:

Request::setTrustedProxies(array($request->server->get('REMOTE_ADDR')));

additional information

After some research, I found this to be related to proxies ... If we check what the isSecure function does, we find this : the Request isFromTrustedProxy strong> method is called to decide whether to return true or false.

Once we know that the problem is with proxies, the symfony documentation details what we need to do to trust proxies or how to manage a load balancer or reverse proxy . In my case, when I work with the hero, trusting the incoming ip , this was the way to go.

+3

Source: https://habr.com/ru/post/1613835/


All Articles