original_string: protected function validate(Request $request, Response $entry, $catch = false)
      {
          $subRequest = clone $request;
  
          // send no head requests because we want content
          if ('HEAD' === $request->getMethod()) {
              $subRequest->setMethod('GET');
          }
  
          // add our cached last-modified validator
          $subRequest->headers->set('if_modified_since', $entry->headers->get('Last-Modified'));
  
          // Add our cached etag validator to the environment.
          // We keep the etags from the client to handle the case when the client
          // has a different private valid entry which is not cached here.
          $cachedEtags = $entry->getEtag() ? [$entry->getEtag()] : [];
          $requestEtags = $request->getETags();
          if ($etags = array_unique(array_merge($cachedEtags, $requestEtags))) {
              $subRequest->headers->set('if_none_match', implode(', ', $etags));
          }
  
          $response = $this->forward($subRequest, $catch, $entry);
  
          if (304 == $response->getStatusCode()) {
              $this->record($request, 'valid');
  
              // return the response and not the cache entry if the response is valid but not cached
              $etag = $response->getEtag();
              if ($etag && \in_array($etag, $requestEtags) && !\in_array($etag, $cachedEtags)) {
                  return $response;
              }
  
              $entry = clone $entry;
              $entry->headers->remove('Date');
  
              foreach (['Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified'] as $name) {
                  if ($response->headers->has($name)) {
                      $entry->headers->set($name, $response->headers->get($name));
                  }
              }
  
              $response = $entry;
          } else {
              $this->record($request, 'invalid');
          }
  
          if ($response->isCacheable()) {
              $this->store($request, $response);
          }
  
          return $response;
      }
code: protected function validate(Request $request, Response $entry, $catch = false)
      {
          $subRequest = clone $request;
  
          // send no head requests because we want content
          if ('HEAD' === $request->getMethod()) {
              $subRequest->setMethod('GET');
          }
  
          // add our cached last-modified validator
          $subRequest->headers->set('if_modified_since', $entry->headers->get('Last-Modified'));
  
          // Add our cached etag validator to the environment.
          // We keep the etags from the client to handle the case when the client
          // has a different private valid entry which is not cached here.
          $cachedEtags = $entry->getEtag() ? [$entry->getEtag()] : [];
          $requestEtags = $request->getETags();
          if ($etags = array_unique(array_merge($cachedEtags, $requestEtags))) {
              $subRequest->headers->set('if_none_match', implode(', ', $etags));
          }
  
          $response = $this->forward($subRequest, $catch, $entry);
  
          if (304 == $response->getStatusCode()) {
              $this->record($request, 'valid');
  
              // return the response and not the cache entry if the response is valid but not cached
              $etag = $response->getEtag();
              if ($etag && \in_array($etag, $requestEtags) && !\in_array($etag, $cachedEtags)) {
                  return $response;
              }
  
              $entry = clone $entry;
              $entry->headers->remove('Date');
  
              foreach (['Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified'] as $name) {
                  if ($response->headers->has($name)) {
                      $entry->headers->set($name, $response->headers->get($name));
                  }
              }
  
              $response = $entry;
          } else {
              $this->record($request, 'invalid');
          }
  
          if ($response->isCacheable()) {
              $this->store($request, $response);
          }
  
          return $response;
      }
code_tokens: protected function validate ( Request $ request , Response $ entry , $ catch = false ) { $ subRequest = clone $ request ; // send no head requests because we want content if ( 'HEAD' === $ request -> getMethod ( ) ) { $ subRequest -> setMethod ( 'GET' ) ; } // add our cached last-modified validator $ subRequest -> headers -> set ( 'if_modified_since' , $ entry -> headers -> get ( 'Last-Modified' ) ) ; // Add our cached etag validator to the environment. // We keep the etags from the client to handle the case when the client // has a different private valid entry which is not cached here. $ cachedEtags = $ entry -> getEtag ( ) ? [ $ entry -> getEtag ( ) ] : [ ] ; $ requestEtags = $ request -> getETags ( ) ; if ( $ etags = array_unique ( array_merge ( $ cachedEtags , $ requestEtags ) ) ) { $ subRequest -> headers -> set ( 'if_none_match' , implode ( ', ' , $ etags ) ) ; } $ response = $ this -> forward ( $ subRequest , $ catch , $ entry ) ; if ( 304 == $ response -> getStatusCode ( ) ) { $ this -> record ( $ request , 'valid' ) ; // return the response and not the cache entry if the response is valid but not cached $ etag = $ response -> getEtag ( ) ; if ( $ etag && \ in_array ( $ etag , $ requestEtags ) && ! \ in_array ( $ etag , $ cachedEtags ) ) { return $ response ; } $ entry = clone $ entry ; $ entry -> headers -> remove ( 'Date' ) ; foreach ( [ 'Date' , 'Expires' , 'Cache-Control' , 'ETag' , 'Last-Modified' ] as $ name ) { if ( $ response -> headers -> has ( $ name ) ) { $ entry -> headers -> set ( $ name , $ response -> headers -> get ( $ name ) ) ; } } $ response = $ entry ; } else { $ this -> record ( $ request , 'invalid' ) ; } if ( $ response -> isCacheable ( ) ) { $ this -> store ( $ request , $ response ) ; } return $ response ; }
docstring: Validates that a cache entry is fresh.
  
  The original request is used as a template for a conditional
  GET request with the backend.
  
  @param Request  $request A Request instance
  @param Response $entry   A Response instance to validate
  @param bool     $catch   Whether to process exceptions
  
  @return Response A Response instance
docstring_tokens: Validates that a cache entry is fresh .