Skip to content

Commit f19f959

Browse files
committed
authorization header doesn't have a colon in it's value, requests' auth parameter overrides custom authorization header
1 parent f8080db commit f19f959

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

gitlab/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def set_token(self, token=None, oauth_token=None):
358358

359359
if oauth_token:
360360
self.headers.pop("PRIVATE-TOKEN", None)
361-
self.headers["Authorization"] = "Bearer: %s" % oauth_token
361+
self.headers["Authorization"] = "Bearer %s" % oauth_token
362362
elif token:
363363
self.headers.pop("Authorization", None)
364364
self.headers["PRIVATE-TOKEN"] = token
@@ -397,16 +397,22 @@ def _raw_get(self, path_, content_type=None, streamed=False, **kwargs):
397397
url = '%s%s' % (self._url, path_)
398398

399399
headers = self._create_headers(content_type)
400+
401+
if 'Authorization' in self.headers:
402+
auth = None
403+
else:
404+
auth = requests.auth.HTTPBasicAuth(
405+
self.http_username,
406+
self.http_password)
407+
400408
try:
401409
return self.session.get(url,
402410
params=kwargs,
403411
headers=headers,
404412
verify=self.ssl_verify,
405413
timeout=self.timeout,
406414
stream=streamed,
407-
auth=requests.auth.HTTPBasicAuth(
408-
self.http_username,
409-
self.http_password))
415+
auth=auth)
410416
except Exception as e:
411417
raise GitlabConnectionError(
412418
"Can't connect to GitLab server (%s)" % e)
@@ -438,7 +444,7 @@ def _raw_list(self, path_, cls, extra_attrs={}, **kwargs):
438444
results = [cls(self, item, **params) for item in r.json()
439445
if item is not None]
440446
if ('next' in r.links and 'url' in r.links['next']
441-
and get_all_results is True):
447+
and get_all_results is True):
442448
args = kwargs.copy()
443449
args['next_url'] = r.links['next']['url']
444450
results.extend(self.list(cls, **args))

0 commit comments

Comments
 (0)