Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit e7b1e1f

Browse files
committed
Fixed Link header behavior.
1 parent 0de3315 commit e7b1e1f

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ configuration/local/
33
vendor/
44
example/vue-app/dist
55
.phpunit.result.cache
6+
.DS_Store

src/Header.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function __construct(ConfigurationInterface $conf)
5353
/**
5454
* Prepare headers before handling requests.
5555
*
56+
* https://tools.ietf.org/html/rfc5988#section-5.5
57+
*
5658
* @return void
5759
*/
5860
private function prepareBeforeRequest(): void
@@ -66,18 +68,21 @@ private function prepareBeforeRequest(): void
6668

6769
// Backward compatibility.
6870
if (!isset($values[0]['value'])) {
69-
$this->prepared[$item][] = join('; ', (array) $values);
71+
$this->prepared[$item] = join('; ', (array) $values);
7072
}
7173

7274
// Checks new extended format for sent headers from yaml values.
7375
if (is_array($values) && count($values) > 0 && isset($values[0]['value'])) {
76+
$array = [];
7477
foreach ($values as $value) {
7578
if (!isset($value['value'])) {
7679
throw new InvalidArgumentException('Invalid header format, see docs & examples.');
7780
}
7881

79-
$this->prepared[$item][] = join('; ', (array) $value['value']);
82+
$array[] = join('; ', (array) $value['value']);
8083
}
84+
85+
$this->prepared[$item] = join(', ', $array);
8186
}
8287
}
8388
}
@@ -94,10 +99,8 @@ public function sent(Response $response): void
9499
$response->header('software-server', '');
95100
$response->header('server', '');
96101

97-
foreach ($this->prepared as $header => $values) {
98-
foreach ($values as $value) {
99-
$response->header($header, $value);
100-
}
102+
foreach ($this->prepared as $header => $value) {
103+
$response->header($header, $value);
101104
}
102105
}
103106
}

tests/HeaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testSendingHeaders()
1616

1717
$response = $this->createMock(Response::class);
1818
$response
19-
->expects($this->exactly(count($conf->get('server.headers')) + 3)) // +3 because 2 hardcoded and 1 header have 2 values.
19+
->expects($this->exactly(count($conf->get('server.headers')) + 2)) // +2 because 2 hardcoded.
2020
->method('header')
2121
->willReturn(null);
2222

0 commit comments

Comments
 (0)