Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 35a6d85

Browse filesBrowse files
author
Gauvain Pocentek
committed
fix(api): Don't try to parse raw downloads
http_get always tries to interpret the retrieved data if the content-type is json. In some cases (artifact download for instance) this is not the expected behavior. This patch changes http_get and download methods to always get the raw data without parsing. Closes python-gitlab#683
1 parent 89679ce commit 35a6d85
Copy full SHA for 35a6d85

File tree

Expand file treeCollapse file tree

2 files changed

+18
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-13
lines changed
Open diff view settings
Collapse file

‎gitlab/__init__.py‎

Copy file name to clipboardExpand all lines: gitlab/__init__.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,16 @@ def http_request(self, verb, path, query_data={}, post_data=None,
517517
error_message=error_message,
518518
response_body=result.content)
519519

520-
def http_get(self, path, query_data={}, streamed=False, **kwargs):
520+
def http_get(self, path, query_data={}, streamed=False, raw=False,
521+
**kwargs):
521522
"""Make a GET request to the Gitlab server.
522523
523524
Args:
524525
path (str): Path or full URL to query ('/projects' or
525526
'http://whatever/v4/api/projecs')
526527
query_data (dict): Data to send as query parameters
527528
streamed (bool): Whether the data should be streamed
529+
raw (bool): If True do not try to parse the output as json
528530
**kwargs: Extra options to send to the server (e.g. sudo)
529531
530532
Returns:
@@ -538,8 +540,10 @@ def http_get(self, path, query_data={}, streamed=False, **kwargs):
538540
"""
539541
result = self.http_request('get', path, query_data=query_data,
540542
streamed=streamed, **kwargs)
541-
if (result.headers['Content-Type'] == 'application/json' and
542-
not streamed):
543+
544+
if (result.headers['Content-Type'] == 'application/json'
545+
and not streamed
546+
and not raw):
543547
try:
544548
return result.json()
545549
except Exception:
Collapse file

‎gitlab/v4/objects.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects.py
+11-10Lines changed: 11 additions & 10 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.