Skip to content

Only use HostHeaderSSLAdapter for SSL/HTTPS connections #4498

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

Merged
merged 2 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions readthedocs/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions readthedocs/restapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down