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


PHP Response::addHeader方法代码示例

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


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

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

示例2: addResponseHeaders

 /**
  * Add the plugin's headers to a response
  *
  * @param RequestInterface $request  Request
  * @param Response         $response Response to add headers to
  */
 protected function addResponseHeaders(RequestInterface $request, Response $response)
 {
     $params = $request->getParams();
     $response->setHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));
     $lookup = ($params['cache.lookup'] === true ? 'HIT' : 'MISS') . ' from GuzzleCache';
     if ($header = $response->getHeader('X-Cache-Lookup')) {
         // Don't add duplicates
         $values = $header->toArray();
         $values[] = $lookup;
         $response->setHeader('X-Cache-Lookup', array_unique($values));
     } else {
         $response->setHeader('X-Cache-Lookup', $lookup);
     }
     if ($params['cache.hit'] === true) {
         $xcache = 'HIT from GuzzleCache';
     } elseif ($params['cache.hit'] == 'error') {
         $xcache = 'HIT_ERROR from GuzzleCache';
     } else {
         $xcache = 'MISS from GuzzleCache';
     }
     if ($header = $response->getHeader('X-Cache')) {
         // Don't add duplicates
         $values = $header->toArray();
         $values[] = $xcache;
         $response->setHeader('X-Cache', array_unique($values));
     } else {
         $response->setHeader('X-Cache', $xcache);
     }
     if ($response->isFresh() === false) {
         $response->addHeader('Warning', sprintf('110 GuzzleCache/%s "Response is stale"', Version::VERSION));
         if ($params['cache.hit'] === 'error') {
             $response->addHeader('Warning', sprintf('111 GuzzleCache/%s "Revalidation failed"', Version::VERSION));
         }
     }
 }
开发者ID:Trideon,项目名称:gigolo,代码行数:41,代码来源:CachePlugin.php

示例3: shouldThrowExceptionWhenApiIsExceeded

 /**
  * @test
  * @expectedException \Github\Exception\ApiLimitExceedException
  */
 public function shouldThrowExceptionWhenApiIsExceeded()
 {
     $path = '/some/path';
     $parameters = array('a = b');
     $headers = array('c' => 'd');
     $response = new Response(403);
     $response->addHeader('X-RateLimit-Remaining', 0);
     $mockPlugin = new MockPlugin();
     $mockPlugin->addResponse($response);
     $client = new GuzzleClient('http://123.com/');
     $client->addSubscriber($mockPlugin);
     $httpClient = new TestHttpClient(array(), $client);
     $httpClient->get($path, $parameters, $headers);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:18,代码来源:HttpClientTest.php


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