Skip to content

Commit f683263

Browse files
Json decode only responses with json content type
When I wanted to get code of JSON file (that exists in repository) using blob API method, I got parsed JSON, but I wanted plain text... Url: projects/<project id>/repository/commits/<sha>/blob?filepath=<some json file>
1 parent 76ab3d5 commit f683263

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/Gitlab/HttpClient/Message/Response.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ class Response extends BaseResponse
1212
public function getContent()
1313
{
1414
$response = parent::getContent();
15-
$content = json_decode($response, true);
16-
17-
if (JSON_ERROR_NONE !== json_last_error()) {
15+
if (parent::getHeader("Content-Type") === "application/json") {
16+
$content = json_decode($response, true);
17+
18+
if (JSON_ERROR_NONE !== json_last_error()) {
19+
return $response;
20+
}
21+
22+
return $content;
23+
} else {
1824
return $response;
1925
}
20-
21-
return $content;
2226
}
2327
}

0 commit comments

Comments
 (0)