diff --git a/src/Middleware/AddHttp2ServerPush.php b/src/Middleware/AddHttp2ServerPush.php index 2a4cef2..70c5979 100644 --- a/src/Middleware/AddHttp2ServerPush.php +++ b/src/Middleware/AddHttp2ServerPush.php @@ -87,7 +87,7 @@ protected function fetchLinkableNodes($response) { $crawler = $this->getCrawler($response); - return collect($crawler->filter('link, script[src], img[src]')->extract(['src', 'href'])); + return collect($crawler->filter('link:not([rel*="icon"]), script[src], img[src], object[data]')->extract(['src', 'href', 'data'])); } /** @@ -107,6 +107,7 @@ private function buildLinkHeaderString($url) '.JPG' => 'image', '.JPEG' => 'image', '.PNG' => 'image', + '.SVG' => 'image', '.TIFF' => 'image', ]; diff --git a/tests/AddHttp2ServerPushTest.php b/tests/AddHttp2ServerPushTest.php index d0ec4b3..de33856 100644 --- a/tests/AddHttp2ServerPushTest.php +++ b/tests/AddHttp2ServerPushTest.php @@ -2,8 +2,6 @@ namespace JacobBennett\Http2ServerPush\Test; -// TODO: test for invalid file types like .svg - use Illuminate\Http\Request; use JacobBennett\Http2ServerPush\Middleware\AddHttp2ServerPush; use Symfony\Component\HttpFoundation\Response; @@ -57,7 +55,19 @@ public function it_will_return_an_image_link_header_for_images() $this->assertTrue($this->isServerPushResponse($response)); $this->assertStringEndsWith("as=image", $response->headers->get('link')); - $this->assertCount(6, explode(",", $response->headers->get('link'))); + $this->assertCount(7, explode(",", $response->headers->get('link'))); + } + + /** @test */ + public function it_will_return_an_image_link_header_for_svg_objects() + { + $request = new Request(); + + $response = $this->middleware->handle($request, $this->getNext('pageWithSVGObject')); + + $this->assertTrue($this->isServerPushResponse($response)); + $this->assertStringEndsWith("as=image", $response->headers->get('link')); + $this->assertCount(1, explode(",", $response->headers->get('link'))); } /** @test */ @@ -93,6 +103,16 @@ public function it_will_not_return_a_push_header_for_inline_js() $this->assertFalse($this->isServerPushResponse($response)); } + /** @test */ + public function it_will_not_return_a_push_header_for_icons() + { + $request = new Request(); + + $response = $this->middleware->handle($request, $this->getNext('pageWithFavicon')); + + $this->assertFalse($this->isServerPushResponse($response)); + } + /** @test */ public function it_will_return_limit_count_of_links() { diff --git a/tests/fixtures/pageWithFavicon.html b/tests/fixtures/pageWithFavicon.html new file mode 100644 index 0000000..7e75f3f --- /dev/null +++ b/tests/fixtures/pageWithFavicon.html @@ -0,0 +1,12 @@ + + + + Page title + + + + + + + + \ No newline at end of file diff --git a/tests/fixtures/pageWithImages.html b/tests/fixtures/pageWithImages.html index 99d0984..afcb5c4 100644 --- a/tests/fixtures/pageWithImages.html +++ b/tests/fixtures/pageWithImages.html @@ -11,6 +11,7 @@ + diff --git a/tests/fixtures/pageWithSVGObject.html b/tests/fixtures/pageWithSVGObject.html new file mode 100644 index 0000000..c4bab5a --- /dev/null +++ b/tests/fixtures/pageWithSVGObject.html @@ -0,0 +1,11 @@ + + + + Page title + + + + + + +