public function minifyHtml(BaseEvent $event) { $search = array('/ {2,}/', '/<!--.*?-->|\\t|(?:\\r?\\n[ \\t]*)+/s', '/\\>[^\\S ]+/s', '/[^\\S ]+\\</s', '/(\\s)+/s'); // shorten multiple whitespace sequences $replace = array(' ', ' ', '>', '<', '\\1'); $event->getPoc()->setOutput(preg_replace($search, $replace, $event->getPoc()->getOutput())); }
public function compress(BaseEvent $event) { $this->outputHandler->header('Content-Encoding: gzip'); if ($this->compressionType == self::COMPRESSION_GZIP) { $event->getPoc()->setOutput(\gzencode($event->getPoc()->getOutput(), 9, FORCE_GZIP)); } elseif ($this->compressionType == self::COMPRESSION_DEFLATE) { $event->getPoc()->setOutput(\gzdeflate($event->getPoc()->getOutput())); } }
public function isOutputBlacklisted(BaseEvent $event) { if ($this->outputBlacklist) { foreach ($this->outputBlacklist as $condititon) { $result = preg_match($condititon, $event->getPoc()->getOutput()); if ($result) { $event->getPoc()->setCanICacheThisGeneratedContent(false); return; } } } }
public function checkEtag(BaseEvent $event) { $requestHeaders = $event->getPoc()->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME)->getOutputHandler()->getallheaders(); if (isset($requestHeaders['If-None-Match'])) { $etag = $requestHeaders['If-None-Match']; if ($etag) { $storedEtag = $event->getPoc()->getCache()->fetch($event->getPoc()->getHasher()->getKey() . self::ETAG_POSTFIX); if ($storedEtag == $etag) { $event->getPoc()->getPocDispatcher()->dispatch(EtagEvents::ETAG_FOUND, new BaseEvent($event->getPoc())); $outputHandler = $event->getPoc()->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME)->getOutputHandler(); $outputHandler->header('HTTP/1.0 304 Not Modified'); $outputHandler->header('Etag: ' . $etag); //$event->getPoc()->getOutputHandler()->StopBuffer(); } else { $event->getPoc()->getPocDispatcher()->dispatch(EtagEvents::ETAG_NOT_FOUND, new BaseEvent($event->getPoc())); } } } }
public function printSize(BaseEvent $event) { $LengthHeader = $event->getPoc()->getCache()->fetch($event->getPoc()->getHasher()->getKey() . self::LENGTH_POSTFIX); $event->getPoc()->getEventDispatcher()->getPlugin(HttpCapture::PLUGIN_NAME)->getOutputHandler()->header('Content-Length: ' . $LengthHeader); }
private function logTime(BaseEvent $event, $eventName, $type) { $this->logOutputMatrix($eventName, \microtime(true) - $event->getPoc()->getStartTime() . '|' . $eventName, $type); }