Skip to content

Commit 52d7631

Browse files
authored
Merge pull request python-gitlab#687 from python-gitlab/fix/683/raw_download
fix(api): Don't try to parse raw downloads
2 parents ca8c85c + 35a6d85 commit 52d7631

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

gitlab/__init__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,16 @@ def http_request(self, verb, path, query_data={}, post_data=None,
530530
error_message=error_message,
531531
response_body=result.content)
532532

533-
def http_get(self, path, query_data={}, streamed=False, **kwargs):
533+
def http_get(self, path, query_data={}, streamed=False, raw=False,
534+
**kwargs):
534535
"""Make a GET request to the Gitlab server.
535536
536537
Args:
537538
path (str): Path or full URL to query ('/projects' or
538539
'http://whatever/v4/api/projecs')
539540
query_data (dict): Data to send as query parameters
540541
streamed (bool): Whether the data should be streamed
542+
raw (bool): If True do not try to parse the output as json
541543
**kwargs: Extra options to send to the server (e.g. sudo)
542544
543545
Returns:
@@ -551,8 +553,10 @@ def http_get(self, path, query_data={}, streamed=False, **kwargs):
551553
"""
552554
result = self.http_request('get', path, query_data=query_data,
553555
streamed=streamed, **kwargs)
554-
if (result.headers['Content-Type'] == 'application/json' and
555-
not streamed):
556+
557+
if (result.headers['Content-Type'] == 'application/json'
558+
and not streamed
559+
and not raw):
556560
try:
557561
return result.json()
558562
except Exception:

gitlab/v4/objects.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
11281128
"""
11291129
path = '/snippets/%s/raw' % self.get_id()
11301130
result = self.manager.gitlab.http_get(path, streamed=streamed,
1131-
**kwargs)
1131+
raw=True, **kwargs)
11321132
return utils.response_content(result, streamed, action, chunk_size)
11331133

11341134

@@ -1365,7 +1365,7 @@ def artifacts(self, streamed=False, action=None, chunk_size=1024,
13651365
"""
13661366
path = '%s/%s/artifacts' % (self.manager.path, self.get_id())
13671367
result = self.manager.gitlab.http_get(path, streamed=streamed,
1368-
**kwargs)
1368+
raw=True, **kwargs)
13691369
return utils.response_content(result, streamed, action, chunk_size)
13701370

13711371
@cli.register_custom_action('ProjectJob')
@@ -1393,7 +1393,7 @@ def artifact(self, path, streamed=False, action=None, chunk_size=1024,
13931393
"""
13941394
path = '%s/%s/artifacts/%s' % (self.manager.path, self.get_id(), path)
13951395
result = self.manager.gitlab.http_get(path, streamed=streamed,
1396-
**kwargs)
1396+
raw=True, **kwargs)
13971397
return utils.response_content(result, streamed, action, chunk_size)
13981398

13991399
@cli.register_custom_action('ProjectJob')
@@ -1419,7 +1419,7 @@ def trace(self, streamed=False, action=None, chunk_size=1024, **kwargs):
14191419
"""
14201420
path = '%s/%s/trace' % (self.manager.path, self.get_id())
14211421
result = self.manager.gitlab.http_get(path, streamed=streamed,
1422-
**kwargs)
1422+
raw=True, **kwargs)
14231423
return utils.response_content(result, streamed, action, chunk_size)
14241424

14251425

@@ -2654,7 +2654,7 @@ def raw(self, file_path, ref, streamed=False, action=None, chunk_size=1024,
26542654
path = '%s/%s/raw' % (self.path, file_path)
26552655
query_data = {'ref': ref}
26562656
result = self.gitlab.http_get(path, query_data=query_data,
2657-
streamed=streamed, **kwargs)
2657+
streamed=streamed, raw=True, **kwargs)
26582658
return utils.response_content(result, streamed, action, chunk_size)
26592659

26602660

@@ -2897,7 +2897,7 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
28972897
"""
28982898
path = "%s/%s/raw" % (self.manager.path, self.get_id())
28992899
result = self.manager.gitlab.http_get(path, streamed=streamed,
2900-
**kwargs)
2900+
raw=True, **kwargs)
29012901
return utils.response_content(result, streamed, action, chunk_size)
29022902

29032903

@@ -3174,7 +3174,7 @@ def download(self, streamed=False, action=None, chunk_size=1024, **kwargs):
31743174
"""
31753175
path = '/projects/%d/export/download' % self.project_id
31763176
result = self.manager.gitlab.http_get(path, streamed=streamed,
3177-
**kwargs)
3177+
raw=True, **kwargs)
31783178
return utils.response_content(result, streamed, action, chunk_size)
31793179

31803180

@@ -3315,7 +3315,7 @@ def repository_raw_blob(self, sha, streamed=False, action=None,
33153315
"""
33163316
path = '/projects/%s/repository/blobs/%s/raw' % (self.get_id(), sha)
33173317
result = self.manager.gitlab.http_get(path, streamed=streamed,
3318-
**kwargs)
3318+
raw=True, **kwargs)
33193319
return utils.response_content(result, streamed, action, chunk_size)
33203320

33213321
@cli.register_custom_action('Project', ('from_', 'to'))
@@ -3391,7 +3391,8 @@ def repository_archive(self, sha=None, streamed=False, action=None,
33913391
if sha:
33923392
query_data['sha'] = sha
33933393
result = self.manager.gitlab.http_get(path, query_data=query_data,
3394-
streamed=streamed, **kwargs)
3394+
raw=True, streamed=streamed,
3395+
**kwargs)
33953396
return utils.response_content(result, streamed, action, chunk_size)
33963397

33973398
@cli.register_custom_action('Project', ('forked_from_id', ))
@@ -3674,7 +3675,7 @@ def snapshot(self, wiki=False, streamed=False, action=None,
36743675
"""
36753676
path = '/projects/%d/snapshot' % self.get_id()
36763677
result = self.manager.gitlab.http_get(path, streamed=streamed,
3677-
**kwargs)
3678+
raw=True, **kwargs)
36783679
return utils.response_content(result, streamed, action, chunk_size)
36793680

36803681
@cli.register_custom_action('Project', ('scope', 'search'))

0 commit comments

Comments
 (0)