I want to generate an absolute URL with a specific scheme (https) in a Symfony2 controller. All the solutions I found point me to configure the targeted route so that it requires that scheme. But I need the route to remain accessible in http, so I can't set it to require https (in which case http requests are redirected to the corresponding https URL).
Is there a way to generate an URL with, in the scope of that URL generation only, a specific scheme?
I saw that using the 'network' keyword generates a "network path"-style URL, which looks like "//example.com/dir/file"; so maybe I can simply do
'https:' . $this->generateUrl($routeName, $parameters, 'network')
But I don't know if this will be robust enough to any route or request context.
UPDATE: after investigation in the URL generation code, this "network path" workaround seems fully robust. A network path is generated exactly as an absolute URL, without a scheme before the "//".
//, or if there could be specific scenarios where the results would differ...