-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Redirect HTTP -> HTTPS for custom domains #6882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Only redirect if the appropriate flag is set on the Domain (default is not to redirect) - Use a 302 redirect for now. Ideally this is a 301 redirect, but redirecting other people's domains with a 301 is always a bit risky.
readthedocs/proxito/middleware.py
Outdated
if domain.https and not request.is_secure(): | ||
# Redirect HTTP -> HTTPS (302) for this custom domain | ||
log.debug('Proxito CNAME HTTPS Redirect: host=%s', host) | ||
return redirect('https://%s%s' % (host, request.get_full_path())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use f-strings or .format
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Would be good to add a validatehttp check for this as well 👍
readthedocs/proxito/middleware.py
Outdated
if domain.https and not request.is_secure(): | ||
# Redirect HTTP -> HTTPS (302) for this custom domain | ||
log.debug('Proxito CNAME HTTPS Redirect: host=%s', host) | ||
return redirect('https://{}{}'.format(host, request.get_full_path())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, I'd like to see a custom RTD header on here so we know where this request comes from similar to
resp['X-RTD-System-Redirect'] = True |
Perhaps X-RTD-HTTPS-Redirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll do X-RTD-Redirect
and the value will be https
. I might use the same header with the value canonicalize
when doing the domain canonicalization.
Hold off on merging this. I'm considering a refactor here that might make it easier to canonicalize the domain as well. I might move the actual redirection to |
I put an alternative implementation (based on this one) in #6905. That one uses the regular resolver code to actually perform the redirect and I think I like that solution a bit better overall. I'm open to feedback on either/both though. If we want to roll out the HTTP -> HTTPS change separately from canonicalizing the domain, we can merge this, roll this out, and merge that one in the future. |
I'm going to close this in favor of #6905 which seems closer to rolling out. |
Fixes #4641