Skip to content

Commit

Permalink
refactor: remove external url check
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBennett committed Jul 30, 2016
1 parent 563230e commit cabc41c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
22 changes: 1 addition & 21 deletions src/Middleware/AddHttp2ServerPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function handle(Request $request, Closure $next)
return $response;
}

// use the crawler to fetch the nodes we want from the response
$this->fetchLinkableNodes($response);

return $response;
Expand All @@ -48,20 +47,11 @@ protected function fetchLinkableNodes(Response $response)
{
$crawler = $this->getCrawler($response);

// look to see if link can have any type other than css or a font
// distinguish font vs css by looking at extension, css vs eot or svg etc...

// include images??

$nodes = $crawler->filter('link, script[src]')->extract(['src', 'href']);

// this is giving me a listing of LOCAL urls for any links or scripts
// now I just need to determine which type, make sure you account for query strings on end
$headers = collect($nodes)->flatten(1)
->filter()
->reject(function ($url) {
return $this->isExternalUrl($url);
})->map(function ($url) {
->map(function ($url) {
return $this->buildLinkHeaderString($url);
})->filter()
->implode(',');
Expand Down Expand Up @@ -89,16 +79,6 @@ protected function getCrawler(Response $response)
return $this->crawler = new Crawler($response->getContent());
}

/**
* @param $url
* @return bool
*/
private function isExternalUrl($url)
{
// is this a local fully qualified url
return str_contains($url, "//");
}

/**
* @param String $url
* @return string
Expand Down
12 changes: 0 additions & 12 deletions tests/AddHttp2ServerPushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ 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_external_resources()
{
// TODO: check that double slash isn't OUR sites url

$request = new Request();

$response = $this->middleware->handle($request, $this->getNext('pageWithExternalAssets'));

$this->assertFalse($this->isServerPushResponse($response));
}

/**
* @param string $pageName
*
Expand Down

0 comments on commit cabc41c

Please sign in to comment.