From 1d7ac4a340bf9c2951b099ec585716eb74e72f7e Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 28 Aug 2018 20:10:52 +0200 Subject: [PATCH] Always use HTTPS protocol when require_https_domain is True --- readthedocs/core/resolver.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/readthedocs/core/resolver.py b/readthedocs/core/resolver.py index abe1d5d9671..44f1796a760 100644 --- a/readthedocs/core/resolver.py +++ b/readthedocs/core/resolver.py @@ -160,17 +160,18 @@ def resolve(self, project, require_https_domain=False, filename='', private=None else: domain = getattr(settings, 'PRODUCTION_DOMAIN') - protocol = 'http' - if custom_domain: - # Rely on the ``Domain.https`` field or force it if specified - if custom_domain.https or require_https_domain: - protocol = 'https' - else: - # Use HTTPS if settings specify - public_domain = getattr(settings, 'PUBLIC_DOMAIN', None) - use_https = getattr(settings, 'PUBLIC_DOMAIN_USES_HTTPS', False) - if use_https and public_domain and public_domain in domain: - protocol = 'https' + public_domain = getattr(settings, 'PUBLIC_DOMAIN', None) + use_https = getattr(settings, 'PUBLIC_DOMAIN_USES_HTTPS', False) + + use_https_protocol = any([ + # Rely on the ``Domain.https`` field + custom_domain and custom_domain.https, + # or force it if specified + require_https_domain, + # or fallback to settings + use_https and public_domain and public_domain in domain, + ]) + protocol = 'https' if use_https_protocol else 'http' return '{protocol}://{domain}{path}'.format( protocol=protocol,