Development

Changeset 4560

You must first sign up to be able to contribute.

Changeset 4560

Show
Ignore:
Timestamp:
07/08/07 17:36:39 (1 year ago)
Author:
fabien
Message:

fixed Status code 404 may be transformed into 304 when using ETag (closes #1944)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/filter/sfCacheFilter.class.php

    r4534 r4560  
    110110  { 
    111111    // cache only 200 HTTP status 
    112     if ($this->response->getStatusCode() == 200) 
    113     { 
    114       $uri = $this->routing->getCurrentInternalUri(); 
    115  
    116       // save page in cache 
    117       if ($this->cache[$uri]['page']) 
    118       { 
    119         // set some headers that deals with cache 
    120         $lifetime = $this->cacheManager->getClientLifeTime($uri, 'page'); 
    121         $this->response->setHttpHeader('Last-Modified', $this->response->getDate(time()), false); 
    122         $this->response->setHttpHeader('Expires', $this->response->getDate(time() + $lifetime), false); 
    123         $this->response->addCacheControlHttpHeader('max-age', $lifetime); 
    124  
    125         // set Vary headers 
    126         foreach ($this->cacheManager->getVary($uri, 'page') as $vary) 
    127         { 
    128           $this->response->addVaryHttpHeader($vary); 
    129         } 
    130  
    131         $this->setPageCache($uri); 
    132       } 
    133       else if ($this->cache[$uri]['action']) 
    134       { 
    135         // save action in cache 
    136         $this->setActionCache($uri); 
    137       } 
     112    if (200 != $this->response->getStatusCode()) 
     113    { 
     114      return; 
     115    } 
     116 
     117    $uri = $this->routing->getCurrentInternalUri(); 
     118 
     119    // save page in cache 
     120    if ($this->cache[$uri]['page']) 
     121    { 
     122      // set some headers that deals with cache 
     123      $lifetime = $this->cacheManager->getClientLifeTime($uri, 'page'); 
     124      $this->response->setHttpHeader('Last-Modified', $this->response->getDate(time()), false); 
     125      $this->response->setHttpHeader('Expires', $this->response->getDate(time() + $lifetime), false); 
     126      $this->response->addCacheControlHttpHeader('max-age', $lifetime); 
     127 
     128      // set Vary headers 
     129      foreach ($this->cacheManager->getVary($uri, 'page') as $vary) 
     130      { 
     131        $this->response->addVaryHttpHeader($vary); 
     132      } 
     133 
     134      $this->setPageCache($uri); 
     135    } 
     136    else if ($this->cache[$uri]['action']) 
     137    { 
     138      // save action in cache 
     139      $this->setActionCache($uri); 
    138140    } 
    139141 
  • trunk/test/functional/genericTest.php

    r4555 r4560  
    3636  checkResponseElement('link[href="/sf/sf_default/css/screen.css"]') 
    3737; 
     38 
     39// 404 with ETag enabled must returns 404, not 304 
     40sfConfig::set('sf_cache', true); 
     41sfConfig::set('sf_etag', true); 
     42$b-> 
     43  get('/notfound')-> 
     44  isStatusCode(404)-> 
     45  isRequestParameter('module', 'notfound')-> 
     46  isRequestParameter('action', 'index')-> 
     47  checkResponseElement('body', '/404/')-> 
     48 
     49  get('/notfound')-> 
     50  isStatusCode(404)-> 
     51  isRequestParameter('module', 'notfound')-> 
     52  isRequestParameter('action', 'index')-> 
     53  checkResponseElement('body', '/404/') 
     54; 
     55sfConfig::set('sf_cache', false); 
     56sfConfig::set('sf_etag', false); 
    3857 
    3958// unexistant action