Mercurial > SimpleWebPresenter
comparison Page.inc @ 100:0a33803ee026
Setting variant correctly.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Sat, 27 Sep 2014 10:54:58 +0200 |
| parents | d98e315308cd |
| children | adf7b11921f4 |
comparison
equal
deleted
inserted
replaced
| 99:d98e315308cd | 100:0a33803ee026 |
|---|---|
| 55 * Master class for generating a page | 55 * Master class for generating a page |
| 56 */ | 56 */ |
| 57 abstract class Page | 57 abstract class Page |
| 58 { | 58 { |
| 59 private $cache; | 59 private $cache; |
| 60 private $variants = array(); | |
| 61 | |
| 62 function addVariant($value) | |
| 63 { | |
| 64 array_push($this->variants, $value); | |
| 65 } | |
| 66 | |
| 67 function getVariants() | |
| 68 { | |
| 69 return $this->variants; | |
| 70 } | |
| 60 | 71 |
| 61 /** | 72 /** |
| 62 * Constructs a page | 73 * Constructs a page |
| 63 * | 74 * |
| 64 * @param $cache optionally sets a cache | 75 * @param $cache optionally sets a cache |
| 97 * | 108 * |
| 98 * @return bool if this page may be compressed | 109 * @return bool if this page may be compressed |
| 99 */ | 110 */ |
| 100 function mayCompress() | 111 function mayCompress() |
| 101 { | 112 { |
| 113 //We want to add the variant even if we don't serve with compression. | |
| 114 $this->addVariant('Accept-Encoding'); | |
| 102 if (!array_key_exists('HTTP_ACCEPT_ENCODING', $_SERVER)) | 115 if (!array_key_exists('HTTP_ACCEPT_ENCODING', $_SERVER)) |
| 103 return false; | 116 return false; |
| 104 return (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')); | 117 return (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')); |
| 105 } | 118 } |
| 106 | 119 |
| 187 $res = new PageContent($res); | 200 $res = new PageContent($res); |
| 188 } | 201 } |
| 189 elseif (get_class($res) !== "PageContent") { | 202 elseif (get_class($res) !== "PageContent") { |
| 190 throw new InvalidArgumentException("generateContent returned an unexpected type"); | 203 throw new InvalidArgumentException("generateContent returned an unexpected type"); |
| 191 } | 204 } |
| 205 if ($variants = $this->getVariants()) { | |
| 206 $res->setHeader('Vary', join(",", $variants)); | |
| 207 } | |
| 192 return $res; | 208 return $res; |
| 193 } | 209 } |
| 194 | 210 |
| 195 /** | 211 /** |
| 196 * Displays the result from genPage. | 212 * Displays the result from genPage. |
