Skip to content

Commit

Permalink
Make sure to include 'as' in header
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Mar 4, 2024
1 parent fcde1e4 commit e009f37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Link/LinkParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function processHeaders(HttpResponse $response)

$links = [];
foreach ($this->links as $link) {
$links[] = '<'.$link->getUrl().'>; rel="preload"';
$links[] = '<'.$link->getUrl().'>; rel="preload"; as="'.$link->getType().'"';
}

$response->setHeader('Link', implode(', ', $links));
Expand Down
13 changes: 11 additions & 2 deletions Test/Integration/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,17 @@ private function assertValidLink(string $link): void
foreach ($linkParams as $linkParam) {
$linkParam = explode('=', $linkParam);
$this->assertEquals(2, count($linkParam));
$this->assertEquals('rel', trim($linkParam[0]));
$this->assertEquals('preload', str_replace('"', '', trim($linkParam[1])));
$linkParamName = trim($linkParam[0]);
$linkParamValue = str_replace('"', '', trim($linkParam[1]));
$this->assertContains($linkParamName, ['rel', 'as']);

if ($linkParamName === 'rel') {
$this->assertEquals('preload', $linkParamValue);
}

if ($linkParamName === 'as') {
$this->assertContains($linkParamValue, ['style', 'script', 'font']);
}
}
}
}

0 comments on commit e009f37

Please sign in to comment.