Created
August 15, 2018 18:12
-
-
Save davidfischer/06244f91791088a5847f43888eb683a9 to your computer and use it in GitHub Desktop.
Test Read the Docs HTTPS redirects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function, unicode_literals | |
import requests | |
from requests.exceptions import RequestException | |
def request_url(url): | |
try: | |
return requests.get(url) | |
except RequestException as e: | |
print('- {exc} exception accessing {url}'.format(exc=e.message, url=url)) | |
if e.response: | |
return e.response | |
return None | |
def check_redirects(slug, urls, expected): | |
print('Checking {slug} redirects...'.format(slug=slug)) | |
success = True | |
for url in urls: | |
resp = request_url(url) | |
if not resp: | |
success = False | |
continue | |
if not resp.ok or resp.url != expected: | |
success = False | |
print('- [ERROR] URL {url} redirected to {dest_url} (status={status})'.format( | |
url=url, | |
dest_url=resp.url, | |
status=resp.status_code, | |
)) | |
if success: | |
print('- [SUCCESS] {slug} redirects look good'.format(slug=slug)) | |
#################################### | |
# Check readthedocs.io redirects | |
#################################### | |
expected = 'https://docs.readthedocs.io/en/latest/' | |
urls = [ | |
'http://docs.readthedocs.io/en/latest/', | |
'http://docs.readthedocs.io/en/latest', | |
'http://docs.readthedocs.io', | |
] | |
check_redirects('readthedocs.io', urls, expected) | |
#################################### | |
# Check rtfd.io redirects | |
#################################### | |
expected = 'https://docs.readthedocs.io/en/latest/' | |
urls = [ | |
'http://docs.rtfd.io', | |
'https://docs.rtfd.io', | |
'http://docs.rtfd.io/', | |
'https://docs.rtfd.io/', | |
'http://docs.rtfd.io/en/latest', | |
'http://docs.rtfd.io/en/latest/', | |
] | |
check_redirects('rtfd.io', urls, expected) | |
#################################### | |
# Check rtfd.org redirects | |
#################################### | |
expected = 'https://docs.readthedocs.io/en/latest/' | |
urls = [ | |
'http://docs.rtfd.org', | |
'https://docs.rtfd.org', | |
'http://docs.rtfd.org/', | |
'https://docs.rtfd.org/', | |
'http://docs.rtfd.org/en/latest', | |
'http://docs.rtfd.org/en/latest/', | |
] | |
check_redirects('rtfd.org', urls, expected) | |
#################################### | |
# Check custom domain redirects | |
#################################### | |
domain = 'docs.phpmyadmin.net' | |
expected = 'https://{domain}/en/latest/'.format(domain=domain) | |
urls = [ | |
'http://{domain}'.format(domain=domain), | |
'https://{domain}'.format(domain=domain), | |
'http://{domain}/'.format(domain=domain), | |
'https://{domain}/'.format(domain=domain), | |
'http://{domain}/en/latest'.format(domain=domain), | |
'http://{domain}/en/latest/'.format(domain=domain), | |
] | |
check_redirects('custom domain', urls, expected) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of today, we are not yet redirecting custom domains and we don't have a valid cert on rtfd.org