Beispiel #1
0
 public function testNothingBadHappensWhenHttpAndXmlEtagsMatch()
 {
     $this->entry->setEtag(Etag::fromString('Etag: ' . $this->expectedEtag));
     $this->entry->transferFromXML($this->entryText);
     $this->assertEquals($this->expectedEtag, $this->entry->getEtag()->getFieldValue());
 }
Beispiel #2
0
 public function testReloadInheritsClassname()
 {
     $className = '\\ZendGData\\Entry';
     $etag = Etag::fromString('Etag: ABCD1234');
     $this->service->setMajorProtocolVersion(2);
     $this->adapter->setResponse($this->httpEntrySample);
     $entry = new $className();
     $entry->setService($this->service);
     $entry->link = array(new Extension\Link('http://www.example.com', 'edit', 'application/atom+xml'));
     $entry->setEtag($etag);
     $newEntry = $entry->reload();
     $this->assertEquals('ZendGData\\Entry', get_class($newEntry));
 }
Beispiel #3
0
 public function testGenerateIfMatchHeaderDataReturnsEtagIfNotWeakAndFlagSet()
 {
     $etag = Etag::fromString('Etag: ABCD1234');
     $this->service->setMajorProtocolVersion(2);
     $entry = new App\Entry();
     $entry->setEtag($etag);
     $result = $this->service->generateIfMatchHeaderData($entry, true);
     $this->assertEquals($etag->getFieldValue(), $result);
 }
Beispiel #4
0
 public function testEtagFromStringCreatesValidEtagHeader()
 {
     $etagHeader = Etag::fromString('Etag: xxx');
     $this->assertInstanceOf('Zend\\Http\\Header\\HeaderInterface', $etagHeader);
     $this->assertInstanceOf('Zend\\Http\\Header\\Etag', $etagHeader);
 }
Beispiel #5
0
 public function testCanSetAndGetEtag()
 {
     $data = Etag::fromString("Etag: W/&FooBarBaz&");
     $this->feed->setEtag($data);
     $this->assertEquals($this->feed->getEtag(), $data);
 }
 /**
  * Cache Response for future requests
  *
  * @param MvcEvent $e
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function onFinish(MvcEvent $e)
 {
     $request = $e->getRequest();
     if (!$request instanceof HttpRequest) {
         return;
     }
     if (!$request->isGet()) {
         return;
     }
     $response = $e->getResponse();
     if ($response instanceof HttpResponse && !$response->isOk()) {
         return;
     }
     // Do not continue if weren't able to compose a key
     if (empty($this->cache_key)) {
         return;
     }
     if (!$this->cacheAdapter->hasItem($this->cache_key)) {
         $resourceIdentifier = $e->getRouteMatch()->getParam('resource');
         $resource = call_user_func($this->getResourceLocatorService(), $resourceIdentifier);
         if (!$resource instanceof Resource || !$resource->isCacheable()) {
             return;
         }
         // Generate Response cache headers based on Resource CacheOptions
         $cacheOptions = $resource->getCacheOptions();
         $cacheControl = new CacheControl();
         $cacheControl->addDirective($cacheOptions->getAccess());
         $cacheControl->addDirective('max-age', $cacheOptions->getMaxAge());
         $cacheControl->addDirective('expires', $cacheOptions->getExpires());
         $cacheControl->addDirective('must-revalidate');
         $dateTime = new \DateTime();
         $dateTime->modify('+ ' . $cacheOptions->getExpires() . 'seconds');
         $expires = new Expires();
         $expires->setDate($dateTime);
         $lastModified = new LastModified();
         $lastModified->setDate(new \DateTime());
         // Add Headers to Response Header
         $response->getHeaders()->addHeader($cacheControl);
         $response->getHeaders()->addHeader($expires);
         $response->getHeaders()->addHeaderLine('Pragma: ' . $cacheOptions->getAccess());
         $response->getHeaders()->addHeader(Etag::fromString('Etag: ' . md5($response->getBody())));
         $response->getHeaders()->addHeader($lastModified);
         // Set cache adapter's TTL using Resource cache expires value
         $this->cacheAdapter->getOptions()->setTtl($cacheOptions->getExpires());
         $this->cacheAdapter->setItem($this->cache_key, $response);
         //return $response;
     }
 }