/**
  * Check if the current Request has the given ETag
  *
  * @param null $etag
  * @return bool
  */
 protected function checkRequestHasETag($etag = null)
 {
     if ($etag === null) {
         return false;
     }
     $requestEtags = $this->request->getETags();
     foreach ($requestEtags as $retag) {
         $retag = str_replace('"', '', $retag);
         if ($etag === $retag) {
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
 /**
  * Controller function to output the JavaScript.
  *
  * @param Route $route
  * @param Request $request
  * @param Response $response
  *
  * @return Response
  */
 public function viewJS(Route $route, Request $request, Response $response)
 {
     if (!$this->isResponseObject($response)) {
         return $response;
     }
     $count = $route->parameter('count', 0);
     $files = explode(',', $route->parameter('files', ''));
     if ($count != count($files)) {
         $this->app->abort(422, 'Length option incorrect');
     }
     $data = '';
     $files = $this->sanitize_files($files);
     $filesstr = implode('_', $files);
     $etag = preg_replace('#^"(.*)"$#i', '\\1', implode('-', $request->getETags()));
     if (\Cache::has(sprintf('%s_%s_%d', $etag, $filesstr, $count))) {
         $response->setEtag($etag);
         if ($response->isNotModified($request)) {
             return $response->send();
         }
         $data = \Cache::get(sprintf('%s_%s_%d', $etag, $filesstr, $count));
         $response->setPublic();
         $response->setContent($data);
         $response->setVary('etag', true);
         $response->header('Content-Type', 'text/javascript', true);
         $response->setExpires(Carbon::now()->addSeconds($this->app->config->get('combiner.javascript.expires')));
         return $response->send();
     }
     $basedir = $this->app->basePath() . DIRECTORY_SEPARATOR . $this->app->config->get('combiner.javascript.path');
     foreach ($files as $file) {
         $fullfile = $basedir . DIRECTORY_SEPARATOR . $file;
         if (!(preg_match('#\\.js$#i', $file) && file_exists($fullfile))) {
             continue;
         }
         $data .= @file_get_contents($fullfile) . PHP_EOL;
     }
     $etag = md5($data);
     $response->setPublic();
     $response->setEtag($etag);
     $response->setContent($data);
     $response->setVary('etag', true);
     $response->header('Content-Type', 'text/javascript', true);
     $response->setExpires(Carbon::now()->addSeconds($this->app->config->get('combiner.javascript.expires')));
     \Cache::put(sprintf('%s_%s_%d', $etag, $filesstr, $count), $data, Carbon::now()->addMinutes(60));
     return $response->send();
 }
Beispiel #3
0
 /**
  * Gets the Etags.
  *
  * @return array The entity tags
  * @static 
  */
 public static function getETags()
 {
     //Method inherited from \Symfony\Component\HttpFoundation\Request
     return \Illuminate\Http\Request::getETags();
 }
 /**
  * @param Request $request
  * @param string $responseTag
  * @return bool
  */
 private static function eTagsMatch(Request $request, $responseTag)
 {
     $requestTags = str_replace('"', '', $request->getETags());
     return is_array($requestTags) && in_array($responseTag, $requestTags);
 }