Hi,
When Drupal8 site is SSL enabled we normally enable HTTPS redirects in .htaccess. So all the HTTP requests are redirected to HTTPS.
In our case we have a load balancer in which this wont have a HTTP listener. Thus .htaccess doesn't help. When a new content gets created at "https://baseurl/node/add/page" on submit it gets redirected to "http://baseurl/node/1". To resolve this $_SERVER['HTTPS'] = 'on'; is added to setting.php. i.e this fix all the form redirects.
Still the internal drupal redirects are getting changed from HTTPS to HTTP.
For example:
The redirection when we hit "https://baseurl/search" in a new drupal 8 instance will get redirected to "http://baseurl/search/node" because the web server returns this. And in our case this "http://baseurl/search/node" will get blocked at the Load Balancer itself, As i said earlier this wont have a HTTP listener only HTTPS is allowed.
When I checked, the constructor of Class RequestContext
at vendor/symfony/routing
has the following code,
public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443, $path = '/', $queryString = '')
{
$this->setBaseUrl($baseUrl);
$this->setMethod($method);
$this->setHost($host);
$this->setScheme($scheme);
$this->setHttpPort($httpPort);
$this->setHttpsPort($httpsPort);
$this->setPathInfo($path);
$this->setQueryString($queryString);
}
You can see the $scheme at the arguments which will have the value HTTP only, if the arguments is not passed. The same class has a function to set the scheme as follows.
public function setScheme($scheme)
{
$this->scheme = strtolower($scheme);
return $this;
}
I found couple of places in Drupal core where an object created for RequestContext Class without any arguments passed thus it sets the $scheme as http.
\Drupal\Core\Path\PathValidator.php [Line number 156 & 160]
$initial_request_context = $router->getContext() ? $router->getContext() : new RequestContext();
$request_context = new RequestContext();
\Drupal\Core\Routing\NullGenerator.php [Line number 24]
$this->context = new RequestContext();
\Drupal\Core\Routing\UrlGenerator.php [Line number 88]
$this->context = new RequestContext();
\Drupal\Core\Routing\UrlMatcher.php [Line number 37]
$this->context = new RequestContext();
Is there any workaround done to resolve this.