DevGroup-ru / yii2-http2-server-push

HTTP/2 server push support for Yii2 web application
MIT License
7 stars 4 forks source link

Incorrect Link header creating #1

Open avtop3 opened 8 years ago

avtop3 commented 8 years ago

As I understood from Internet, only relative URIs could be server pushed Also font type resources don't processed as assume.

bethrezen commented 8 years ago

Thanks, I'll take a look at it when I have time

bethrezen commented 8 years ago

Feel free suggesting your solution to this. Pull request is welcome

Philosoft commented 8 years ago

Since this is actually a css, it has been included as css, etc, there is actually only one way to implement this:

  1. use registerCssFile with additional special opti$ons to indicate that this asset should be treated like a font
  2. implement certain checks and logic here
Philosoft commented 8 years ago

Something like this instead of preg_match_all (much slower, but working)

$dom = new DomDocument();
foreach ($view->cssFiles as $linkTag) {
    $dom->loadHTML($linkTag);
    $link = $dom->getElementsByTagName("link")->item(0);
    $href = $link->attributes->getNamedItem("href");
    $href = $href === null ? "" : $href->value;
    $type = $link->attributes->getNamedItem("push-type");
    if ($type !== null) {
        $type = $type->value;
    } else {
        $type = "style";
    }
    $this->addPreloadHeader($href, $type);
}