From within a controller, I have been using the method getSchemeAndHttpHost in order to build the url of another controller.
Everything has been running smoothly, until I needed to go over https. All urls that I get with the getSchemeAndHttpHost function are still http. Doing some troubleshooting, it came out that the getScheme function always returns http, both when I request the page with https and with http.
Did I miss something ?
How can I know if I am over http or https from my controller ?
Edit - some more information
Short answer
Add the following line in the controller:
Request::setTrustedProxies(array($request->server->get('REMOTE_ADDR')));
Some more details
After some investigations, I discovered that this has to do with Proxies... If we check what the isSecure function is doing, we find this: the Request method isFromTrustedProxy is called to decide if true or false should be returned.
Once we know the issue has to do with proxies, the symfony documentation explains in details what we should do to trust proxies or how to manage a load balancer or a reverse proxy. In my case, as I am working with heroku, trusting the incoming ip was the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With