Skip to content

Commit 5451dde

Browse files
Merge branch '10.3' into 10.4
2 parents ec00be9 + 398b1aa commit 5451dde

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [10.4.0] - UPCOMING
99

10-
[10.4.0]: https://github.com/GitLabPHP/Client/compare/10.3.0...10.4.0
10+
[10.4.0]: https://github.com/GitLabPHP/Client/compare/10.3.1...10.4.0
11+
12+
## [10.3.1] - 2020-12-04
13+
14+
* Work around GitLab's API returning bad JSON for some endpoints
15+
16+
[10.3.0]: https://github.com/GitLabPHP/Client/compare/10.3.0...10.3.1
1117

1218
## [10.3.0] - 2020-11-27
1319

src/Api/AbstractApi.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private function createMultipartStreamBuilder(array $params = [], array $files =
271271
foreach ($files as $name => $file) {
272272
$builder->addResource($name, self::tryFopen($file, 'r'), [
273273
'headers' => [
274-
'Content-Type' => self::guessFileContentType($file),
274+
ResponseMediator::CONTENT_TYPE_HEADER => self::guessFileContentType($file),
275275
],
276276
'filename' => \basename($file),
277277
]);
@@ -304,7 +304,7 @@ private static function addMultipartContentType(array $headers, MultipartStreamB
304304
{
305305
$contentType = \sprintf('%s; boundary=%s', ResponseMediator::MULTIPART_CONTENT_TYPE, $builder->getBoundary());
306306

307-
return \array_merge(['Content-Type' => $contentType], $headers);
307+
return \array_merge([ResponseMediator::CONTENT_TYPE_HEADER => $contentType], $headers);
308308
}
309309

310310
/**
@@ -336,7 +336,7 @@ private static function prepareJsonBody(array $params)
336336
*/
337337
private static function addJsonContentType(array $headers)
338338
{
339-
return \array_merge(['Content-Type' => ResponseMediator::JSON_CONTENT_TYPE], $headers);
339+
return \array_merge([ResponseMediator::CONTENT_TYPE_HEADER => ResponseMediator::JSON_CONTENT_TYPE], $headers);
340340
}
341341

342342
/**

src/HttpClient/Message/ResponseMediator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
*/
1414
final class ResponseMediator
1515
{
16+
/**
17+
* The content type header.
18+
*
19+
* @var string
20+
*/
21+
public const CONTENT_TYPE_HEADER = 'Content-Type';
22+
1623
/**
1724
* The JSON content type identifier.
1825
*
@@ -45,7 +52,7 @@ public static function getContent(ResponseInterface $response)
4552
{
4653
$body = (string) $response->getBody();
4754

48-
if ('' !== $body && 0 === \strpos($response->getHeaderLine('Content-Type'), self::JSON_CONTENT_TYPE)) {
55+
if (!\in_array($body, ['', 'null', 'true', 'false'], true) && 0 === \strpos($response->getHeaderLine(self::CONTENT_TYPE_HEADER), self::JSON_CONTENT_TYPE)) {
4956
return JsonArray::decode($body);
5057
}
5158

0 commit comments

Comments
 (0)