diff --git a/readthedocs/api/client.py b/readthedocs/api/client.py index 0259928543e..dd742198b15 100644 --- a/readthedocs/api/client.py +++ b/readthedocs/api/client.py @@ -7,7 +7,7 @@ import logging from django.conf import settings -from requests import Session +import requests from requests_toolbelt.adapters import host_header_ssl from slumber import API @@ -20,8 +20,17 @@ def setup_api(): - session = Session() - session.mount(API_HOST, host_header_ssl.HostHeaderSSLAdapter()) + session = requests.Session() + if API_HOST.startswith('https'): + # Only use the HostHeaderSSLAdapter for HTTPS connections + adapter_class = host_header_ssl.HostHeaderSSLAdapter + else: + adapter_class = requests.adapters.HTTPAdapter + + session.mount( + API_HOST, + adapter_class(max_retries=3), + ) session.headers.update({'Host': PRODUCTION_DOMAIN}) api_config = { 'base_url': '%s/api/v1/' % API_HOST, diff --git a/readthedocs/restapi/client.py b/readthedocs/restapi/client.py index 8a4bfbfdf62..aefbcd3f8c4 100644 --- a/readthedocs/restapi/client.py +++ b/readthedocs/restapi/client.py @@ -37,11 +37,15 @@ def dumps(self, data): def setup_api(): session = requests.Session() + if API_HOST.startswith('https'): + # Only use the HostHeaderSSLAdapter for HTTPS connections + adapter_class = host_header_ssl.HostHeaderSSLAdapter + else: + adapter_class = requests.adapters.HTTPAdapter + session.mount( API_HOST, - host_header_ssl.HostHeaderSSLAdapter( - max_retries=3, - ), + adapter_class(max_retries=3), ) session.headers.update({'Host': PRODUCTION_DOMAIN}) api_config = {