当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::getEtag方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Response::getEtag方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getEtag方法的具体用法?PHP Response::getEtag怎么用?PHP Response::getEtag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::getEtag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle304Response

 protected function handle304Response(RequestInterface $request, Response $validateResponse, Response $response)
 {
     static $replaceHeaders = array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified');
     if ($validateResponse->getEtag() != $response->getEtag()) {
         return false;
     }
     $modified = false;
     foreach ($replaceHeaders as $name) {
         if ($validateResponse->hasHeader($name)) {
             $modified = true;
             $response->setHeader($name, $validateResponse->getHeader($name));
         }
     }
     if ($modified && $this->canCache->canCacheResponse($response)) {
         $this->storage->cache($request, $response);
     }
     return true;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:18,代码来源:DefaultRevalidation.php

示例2: revalidate

 /**
  * Revalidate a cached response
  *
  * @param RequestInterface $request  Request to revalidate
  * @param Response         $response Response to revalidate
  *
  * @return bool
  */
 public function revalidate(RequestInterface $request, Response $response)
 {
     $revalidate = clone $request;
     $revalidate->getEventDispatcher()->removeSubscriber($this);
     $revalidate->removeHeader('Pragma')->removeHeader('Cache-Control')->setHeader('If-Modified-Since', $response->getDate());
     if ($response->getEtag()) {
         $revalidate->setHeader('If-None-Match', '"' . $response->getEtag() . '"');
     }
     try {
         $validateResponse = $revalidate->send();
         if ($validateResponse->getStatusCode() == 200) {
             // The server does not support validation, so use this response
             $request->setResponse($validateResponse);
             // Store this response in cache if possible
             if ($validateResponse->canCache()) {
                 $this->saveCache($this->getCacheKey($request), $validateResponse, $validateResponse->getMaxAge());
             }
             return false;
         }
         if ($validateResponse->getStatusCode() == 304) {
             // Make sure that this response has the same ETage
             if ($validateResponse->getEtag() != $response->getEtag()) {
                 return false;
             }
             // Replace cached headers with any of these headers from the
             // origin server that might be more up to date
             $modified = false;
             foreach (array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified') as $name) {
                 if ($validateResponse->hasHeader($name)) {
                     $modified = true;
                     $response->setHeader($name, $validateResponse->getHeader($name));
                 }
             }
             // Store the updated response in cache
             if ($modified && $response->canCache()) {
                 $this->saveCache($this->getCacheKey($request), $response, $response->getMaxAge());
             }
             return true;
         }
     } catch (BadResponseException $e) {
         // 404 errors mean the resource no longer exists, so remove from
         // cache, and prevent an additional request by throwing the exception
         if ($e->getResponse()->getStatusCode() == 404) {
             $this->getCacheAdapter()->delete($this->getCacheKey($request));
             throw $e;
         }
     }
     // Other exceptions encountered in the revalidation request are ignored
     // in hopes that sending a request to the origin server will fix it
     return false;
 }
开发者ID:norv,项目名称:guzzle,代码行数:59,代码来源:CachePlugin.php

示例3: handle304Response

 /**
  * Handle a 304 response and ensure that it is still valid
  *
  * @param RequestInterface $request          Request that was sent
  * @param Response         $validateResponse Response received
  * @param Response         $response         Original cached response
  *
  * @return bool Returns true if valid, false if invalid
  */
 protected function handle304Response(RequestInterface $request, Response $validateResponse, Response $response)
 {
     static $replaceHeaders = array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified');
     // Make sure that this response has the same ETag
     if ($validateResponse->getEtag() != $response->getEtag()) {
         return false;
     }
     // Replace cached headers with any of these headers from the
     // origin server that might be more up to date
     $modified = false;
     foreach ($replaceHeaders as $name) {
         if ($validateResponse->hasHeader($name)) {
             $modified = true;
             $response->setHeader($name, $validateResponse->getHeader($name));
         }
     }
     // Store the updated response in cache
     if ($modified && $this->canCache->canCacheResponse($response)) {
         $this->storage->cache($request, $response);
     }
     return true;
 }
开发者ID:carlesgutierrez,项目名称:libreobjet.org,代码行数:31,代码来源:DefaultRevalidation.php


注:本文中的Guzzle\Http\Message\Response::getEtag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。