Skip to content

Commit 0aa3da7

Browse files
committed
Add support for link headers with multiple lnks
Also add work around for odd formatting of link headers by Moodle
1 parent bc6cc82 commit 0aa3da7

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/Http/HttpMessage.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,22 @@ public function getRelativeLinks()
264264
*/
265265
private function parseRelativeLinks()
266266
{
267-
$matched = preg_match_all('/[Link|link]: *\<([^\>]+)\>; *rel=(\"[a-z]+\"|[a-z]+)/', $this->responseHeaders, $matches);
267+
$matched = preg_match_all('/^(Link|link): *(.*)$/m', $this->responseHeaders, $matches);
268268
if ($matched) {
269269
for ($i = 0; $i < $matched; $i++) {
270-
$rel = strtolower($matches[2][$i]);
271-
if (strpos($rel, '"') === 0) {
272-
$rel = substr($rel, 1, strlen($rel) - 2);
273-
}
274-
if ($rel === 'previous') {
275-
$rel = 'prev';
270+
$links = explode(',', $matches[2][$i]);
271+
foreach ($links as $link) {
272+
if (preg_match('/^\<([^\>]+)\>; *rel=([^ ]+)$/', trim($link), $match)) {
273+
$rel = strtolower(utf8_decode($match[2]));
274+
if ((strpos($rel, '"') === 0) || (strpos($rel, '?') === 0)) {
275+
$rel = substr($rel, 1, strlen($rel) - 2);
276+
}
277+
if ($rel === 'previous') {
278+
$rel = 'prev';
279+
}
280+
$this->relativeLinks[$rel] = $match[1];
281+
}
276282
}
277-
$this->relativeLinks[$rel] = $matches[1][$i];
278283
}
279284
}
280285
}

0 commit comments

Comments
 (0)