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


PHP Response::hasHeader方法代码示例

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


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

示例1: getContextFromResponse

 private function getContextFromResponse(Response $response)
 {
     $extraFields = array();
     $headersToLookFor = array('x-served-by', 'x-backend', 'x-location', 'x-varnish');
     foreach ($headersToLookFor as $headerName) {
         if ($response->hasHeader($headerName)) {
             $extraFields[$headerName] = (string) $response->getHeader($headerName);
         }
     }
     return $extraFields;
 }
开发者ID:robertpisano,项目名称:LeeLee,代码行数:11,代码来源:MonologGuzzleLogAdapter.php

示例2: createExceptionFromStatusCode

 /**
  * @param string $errorName
  * @param \Guzzle\Http\Message\Response $response
  * @param int $statusCode
  * @return \Phobetor\Billomat\Exception\ExceptionInterface
  */
 public function createExceptionFromStatusCode($errorName, $response, $statusCode)
 {
     $exception = null;
     switch ($statusCode) {
         case self::STATUS_NOT_FOUND:
             return new NotFoundException($errorName, $statusCode);
         case self::STATUS_BAD_REQUEST:
             return new BadRequestException($errorName, $statusCode);
         case self::STATUS_UNAUTHORIZED:
             return new UnauthorizedException($errorName, $statusCode);
         case self::STATUS_TOO_MANY_REQUESTS:
             $exception = new TooManyRequestsException($errorName, $statusCode);
             if ($response->hasHeader('X-Rate-Limit-Remaining')) {
                 $exception->setRateLimitRemaining((int) (string) $response->getHeader('X-Rate-Limit-Remaining'));
             }
             if ($response->hasHeader('X-Rate-Limit-Reset')) {
                 $exception->setRateLimitReset((int) (string) $response->getHeader('X-Rate-Limit-Reset'));
             }
             return $exception;
         default:
             return new UnknownErrorException($errorName, $statusCode);
     }
 }
开发者ID:phobetor,项目名称:billomat,代码行数:29,代码来源:ErrorHandlerListener.php

示例3: 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

示例4: onRequestBeforeSend

 /**
  * Check if a response in cache will satisfy the request before sending
  *
  * @param Event $event
  */
 public function onRequestBeforeSend(Event $event)
 {
     $request = $event['request'];
     if (!$this->canCache->canCacheRequest($request)) {
         return;
     }
     $hashKey = $this->keyProvider->getCacheKey($request);
     $this->cached[$request] = $hashKey;
     // If the cached data was found, then make the request into a
     // manually set request
     if ($cachedData = $this->storage->fetch($hashKey)) {
         unset($this->cached[$request]);
         $response = new Response($cachedData[0], $cachedData[1], $cachedData[2]);
         $response->setHeader('Age', time() - strtotime($response->getDate() ?: 'now'));
         if (!$response->hasHeader('X-Guzzle-Cache')) {
             $response->setHeader('X-Guzzle-Cache', "key={$hashKey}");
         }
         // Validate that the response satisfies the request
         if ($this->canResponseSatisfyRequest($request, $response)) {
             $request->setResponse($response);
         }
     }
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:28,代码来源:CachePlugin.php

示例5: onRequestBeforeSend

 /**
  * Check if a response in cache will satisfy the request before sending
  *
  * @param Event $event
  */
 public function onRequestBeforeSend(Event $event)
 {
     $request = $event['request'];
     // This request is being prepared
     $key = spl_object_hash($request);
     $hashKey = $this->getCacheKey($request);
     $this->cached[$key] = $hashKey;
     $cachedData = $this->getCacheAdapter()->fetch($hashKey);
     // If the cached data was found, then make the request into a
     // manually set request
     if ($cachedData) {
         if ($this->serialize) {
             $cachedData = unserialize($cachedData);
         }
         unset($this->cached[$key]);
         $response = new Response($cachedData['c'], $cachedData['h'], $cachedData['b']);
         $response->setHeader('Age', time() - strtotime($response->getDate() ?: 'now'));
         if (!$response->hasHeader('X-Guzzle-Cache')) {
             $response->setHeader('X-Guzzle-Cache', "key={$key}");
         }
         // Validate that the response satisfies the request
         if ($this->canResponseSatisfyRequest($request, $response)) {
             $request->setResponse($response);
         }
     }
 }
开发者ID:norv,项目名称:guzzle,代码行数:31,代码来源:CachePlugin.php

示例6: 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

示例7: addResponseHeaders

 /**
  * Add the plugin's headers to a response
  *
  * @param string           $cacheKey Cache key
  * @param RequestInterface $request  Request
  * @param Response         $response Response to add headers to
  */
 protected function addResponseHeaders($cacheKey, RequestInterface $request, Response $response)
 {
     if (!$response->hasHeader('X-Guzzle-Cache')) {
         $response->setHeader('X-Guzzle-Cache', "key={$cacheKey}");
     }
     $response->addHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));
     if ($this->debugHeaders) {
         if ($request->getParams()->get('cache.lookup') === true) {
             $response->addHeader('X-Cache-Lookup', 'HIT from GuzzleCache');
         } else {
             $response->addHeader('X-Cache-Lookup', 'MISS from GuzzleCache');
         }
         if ($request->getParams()->get('cache.hit') === true) {
             $response->addHeader('X-Cache', 'HIT from GuzzleCache');
         } elseif ($request->getParams()->get('cache.hit') === 'error') {
             $response->addHeader('X-Cache', 'HIT_ERROR from GuzzleCache');
         } else {
             $response->addHeader('X-Cache', 'MISS from GuzzleCache');
         }
     }
     if ($response->isFresh() === false) {
         $response->addHeader('Warning', sprintf('110 GuzzleCache/%s "Response is stale"', Version::VERSION));
         if ($request->getParams()->get('cache.hit') === 'error') {
             $response->addHeader('Warning', sprintf('111 GuzzleCache/%s "Revalidation failed"', Version::VERSION));
         }
     }
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:34,代码来源:CachePlugin.php

示例8: parseResponse

 private function parseResponse(Response $response, $path)
 {
     $statusCode = $response->getStatusCode();
     if ($statusCode !== 200) {
         throw new UnexpectedValueException(sprintf('Expected status code 200 from "%s", got %d', $path, $statusCode));
     }
     $contentType = $response->hasHeader('content-type') ? $response->getContentType() : '';
     if (substr($contentType, 0, 10) !== 'text/plain') {
         throw new UnexpectedValueException(sprintf('Expected content type "text/plain" from "%s", got "%s"', $path, $contentType));
     }
     return $this->parseRequestFromResponse($response, $path);
 }
开发者ID:cosmorogers,项目名称:http-mock,代码行数:12,代码来源:RequestCollectionFacade.php

示例9: hasHeader

 /**
  * {@inheritdoc}
  */
 public function hasHeader($header)
 {
     return $this->response->hasHeader($header);
 }
开发者ID:ramunasd,项目名称:platform,代码行数:7,代码来源:GuzzleRestResponse.php

示例10: onRequestBeforeSend

 /**
  * Check if a response in cache will satisfy the request before sending
  *
  * @param Event $event
  */
 public function onRequestBeforeSend(Event $event)
 {
     $request = $event['request'];
     // Only cache cacheable requests
     if ($cacheFilter = $request->getParams()->get('cache.filter_strategy')) {
         if (!call_user_func($cacheFilter, $request)) {
             return;
         }
     } elseif (!$request->canCache()) {
         return;
     }
     $hashKey = $this->getCacheKey($request);
     $this->cached[$request] = $hashKey;
     $cachedData = $this->adapter->fetch($hashKey);
     // If the cached data was found, then make the request into a
     // manually set request
     if ($cachedData) {
         unset($this->cached[$request]);
         $response = new Response($cachedData[0], $cachedData[1], $cachedData[2]);
         $response->setHeader('Age', time() - strtotime($response->getDate() ?: 'now'));
         if (!$response->hasHeader('X-Guzzle-Cache')) {
             $response->setHeader('X-Guzzle-Cache', "key={$hashKey}");
         }
         // Validate that the response satisfies the request
         if ($this->canResponseSatisfyRequest($request, $response)) {
             $request->setResponse($response);
         }
     }
 }
开发者ID:vieiragabriel,项目名称:moodle-block_gchat,代码行数:34,代码来源:CachePlugin.php


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