Skip to content
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

Accept custom HTTP headers when reading over HTTP(S) #272

Merged
merged 15 commits into from
Jul 18, 2019
Merged
9 changes: 7 additions & 2 deletions smart_open/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BufferedInputBase(io.BufferedIOBase):
"""

def __init__(self, url, mode='r', buffer_size=DEFAULT_BUFFER_SIZE,
kerberos=False, user=None, password=None):
kerberos=False, user=None, password=None, headers=None):
"""
If Kerberos is True, will attempt to use the local Kerberos credentials.
Otherwise, will try to use "basic" HTTP authentication via username/password.
Expand All @@ -48,7 +48,12 @@ def __init__(self, url, mode='r', buffer_size=DEFAULT_BUFFER_SIZE,
self.buffer_size = buffer_size
self.mode = mode

self.response = requests.get(url, auth=auth, stream=True, headers=_HEADERS)
if headers:
self.headers = headers
else:
self.headers = _HEADERS

self.response = requests.get(url, auth=auth, stream=True, headers=self.headers)

if not self.response.ok:
self.response.raise_for_status()
Expand Down