Fix HTTP to HTTPS redirection not working for default domains
If a default domain is in use, the group domain will be passed into the
IsHTTPSOnly()
call, but this will always return false because the HTTPS-only
flag can only be determined by looking at the HTTP request host rather than
the URL.
For example, for the project https://gitlab.com/tanukitalks/tanukitalks.gitlab.io, this is what happened previously:
- For a project in the default domain (e.g.
gitlab.io
), GitLab Pages loadsconfig.json
and sees the group istanukitalks
with the project nametanuitalks.gitlab.io
. It stores the HTTPS-only flag inside the project config. - Note that for projects in the default domain, the
domainConfig
is empty. This makes sense because there is no domain configuration specified since the default domain is being used, and we need to redirect on a project-by-project basis. - User requests https://tanukitalks.gitlab.io.
- GitLab Pages looks up
tanukitalks.gitlab.io
, and it returns the domaintanukitalks
with an emptydomainConfig
and projecttanukitalks.gitlab.io
. - Since there is no
domainConfig
,IsHTTPSOnly
attempts to resolve the project from the URL. - However, since the URL is using the default domain, the path is
/
, which doesn't resolve to any project.
In the new behavior, we check the hostname of the request to see if it matches any project before trying to parse the URL.
Closes #162 (closed)
Edited by Stan Hu