Skip to content

Commit

Permalink
Always use HTTPS protocol when require_https_domain is True
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos committed Aug 28, 2018
1 parent 6fd22b0 commit 1d7ac4a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions readthedocs/core/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1d7ac4a

Please sign in to comment.