Skip to content

Commit 69db575

Browse files
authored
Merge pull request #193 from nicolasmure/fix/metadata-parsing
fix metadata header parsing
2 parents 328705b + 30d4a31 commit 69db575

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/ObjectStore/v1/Models/MetadataTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public function parseMetadata(ResponseInterface $response): array
1111
$metadata = [];
1212

1313
foreach ($response->getHeaders() as $header => $value) {
14-
$position = strpos($header, static::METADATA_PREFIX);
15-
if ($position === 0) {
16-
$metadata[ltrim($header, static::METADATA_PREFIX)] = $response->getHeader($header)[0];
14+
if (0 === strpos($header, static::METADATA_PREFIX)) {
15+
$name = substr($header, strlen(static::METADATA_PREFIX));
16+
$metadata[$name] = $response->getHeader($header)[0];
1717
}
1818
}
1919

tests/unit/ObjectStore/v1/Fixtures/HEAD_Object.resp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Last-Modified: Thu, 16 Jan 2014 21:12:31 GMT
55
Etag: 451e372e48e0f6b1114fa0724aa79fa1
66
X-Timestamp: 1389906751.73463
77
X-Object-Meta-Book: GoodbyeColumbus
8+
X-Object-Meta-Manufacturer: Acme
89
Content-Type: application/octet-stream
910
X-Trans-Id: tx37ea34dcd1ed48ca9bc7d-0052d84b6f
10-
Date: Thu, 16 Jan 2014 21:13:19 GMT
11+
Date: Thu, 16 Jan 2014 21:13:19 GMT

tests/unit/ObjectStore/v1/Models/ObjectTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,20 @@ public function test_Get_Metadata()
6666
{
6767
$this->setupMock('HEAD', self::CONTAINER . '/' . self::NAME, null, [], 'HEAD_Object');
6868

69-
$this->assertEquals(['Book' => 'GoodbyeColumbus'], $this->object->getMetadata());
69+
$this->assertEquals([
70+
'Book' => 'GoodbyeColumbus',
71+
'Manufacturer' => 'Acme',
72+
], $this->object->getMetadata());
7073
}
7174

7275
public function test_Merge_Metadata()
7376
{
7477
$this->setupMock('HEAD', self::CONTAINER . '/' . self::NAME, null, [], 'HEAD_Object');
7578

7679
$headers = [
77-
'X-Object-Meta-Author' => 'foo',
78-
'X-Object-Meta-Book' => 'GoodbyeColumbus',
80+
'X-Object-Meta-Author' => 'foo',
81+
'X-Object-Meta-Book' => 'GoodbyeColumbus',
82+
'X-Object-Meta-Manufacturer' => 'Acme',
7983
];
8084

8185
$this->setupMock('POST', self::CONTAINER . '/' . self::NAME, null, $headers, 'NoContent');

0 commit comments

Comments
 (0)