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


PHP Response::setHeader方法代码示例

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


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

示例1: testRateReset

 /**
  * Tests getRateReset method
  */
 public function testRateReset()
 {
     $response = new Response(200);
     $response->setHeader('X-Rate-Reset', '100');
     $client = new GenderizeClient();
     $client->setLastResponse($response);
     $this->assertEquals('100', $client->getRateReset());
 }
开发者ID:javihgil,项目名称:genderize-io-client,代码行数:11,代码来源:GenderizeClientTest.php

示例2: writeHead

 public function writeHead($status = 200, array $headers = array())
 {
     if ($this->headWritten) {
         throw new \Exception('Response head has already been written.');
     }
     if (isset($headers['Content-Length'])) {
         $this->chunkedEncoding = false;
     }
     $response = new GuzzleResponse($status);
     $response->setHeader('X-Powered-By', 'React/alpha');
     $response->addHeaders($headers);
     if ($this->chunkedEncoding) {
         $response->setHeader('Transfer-Encoding', 'chunked');
     }
     $data = (string) $response;
     $this->conn->write($data);
     $this->headWritten = true;
 }
开发者ID:jibinam,项目名称:budabot2,代码行数:18,代码来源:Response.php

示例3: cache

 /**
  * {@inheritdoc}
  */
 public function cache($key, Response $response, $ttl = null)
 {
     if ($ttl === null) {
         $ttl = $this->defaultTtl;
     }
     if ($ttl) {
         $response->setHeader('X-Guzzle-Cache', "key={$key}, ttl={$ttl}");
         // Remove excluded headers from the response  (see RFC 2616:13.5.1)
         foreach ($this->excludeResponseHeaders as $header) {
             $response->removeHeader($header);
         }
         // Add a Date header to the response if none is set (for validation)
         if (!$response->getDate()) {
             $response->setHeader('Date', Utils::getHttpDate('now'));
         }
         $this->cache->save($key, array($response->getStatusCode(), $response->getHeaders()->getAll(), $response->getBody(true)), $ttl);
     }
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:21,代码来源:DefaultCacheStorage.php

示例4: cache

 public function cache($key, Response $response, $ttl = null)
 {
     if ($ttl === null) {
         $ttl = $this->defaultTtl;
     }
     $ttl += $response->getMaxAge();
     if ($ttl) {
         $response->setHeader('X-Guzzle-Cache', "key={$key}; ttl={$ttl}");
         // Remove excluded headers from the response  (see RFC 2616:13.5.1)
         foreach ($this->excludeResponseHeaders as $header) {
             $response->removeHeader($header);
         }
         // Add a Date header to the response if none is set (for validation)
         if (!$response->getDate()) {
             $response->setHeader('Date', gmdate(ClientInterface::HTTP_DATE));
         }
         $this->cache->save($key, array($response->getStatusCode(), $response->getHeaders()->toArray(), $response->getBody(true)), $ttl);
     }
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:19,代码来源:DefaultCacheStorage.php

示例5: writeHead

 public function writeHead($status = 200, array $headers = array())
 {
     if ($this->headWritten) {
         throw new \Exception('Response head has already been written.');
     }
     $response = new GuzzleResponse($status, $headers);
     $response->setHeader('X-Powered-By', 'React/alpha');
     $data = (string) $response;
     $this->conn->write($data);
     $this->headWritten = true;
 }
开发者ID:ramiyer,项目名称:react,代码行数:11,代码来源:Response.php

示例6: createResponse

 /**
  * Reads response meta tags to guess content-type charset.
  */
 protected function createResponse(GuzzleResponse $response)
 {
     $body = $response->getBody(true);
     $contentType = $response->getContentType();
     if (!$contentType || false === strpos($contentType, 'charset=')) {
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
     }
     $response->setHeader('Content-Type', $contentType);
     return parent::createResponse($response);
 }
开发者ID:lenninsanchez,项目名称:donadores,代码行数:15,代码来源:Client.php

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

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

示例9: saveCache

 /**
  * Save data to the cache adapter
  *
  * @param string   $key      The cache key
  * @param Response $response The response to cache
  * @param int      $lifetime Amount of seconds to cache
  *
  * @return int Returns the lifetime of the cached data
  */
 protected function saveCache($key, Response $response, $lifetime = null)
 {
     $lifetime = $lifetime ?: $this->defaultLifetime;
     // If the data is cacheable, then save it to the cache adapter
     if ($lifetime) {
         // Remove excluded headers from the response  (see RFC 2616:13.5.1)
         foreach ($this->excludeResponseHeaders as $header) {
             $response->removeHeader($header);
         }
         // Add a Date header to the response if none is set (for validation)
         if (!$response->getDate()) {
             $response->setHeader('Date', Utils::getHttpDate('now'));
         }
         $data = array('c' => $response->getStatusCode(), 'h' => $response->getHeaders(), 'b' => $response->getBody(true));
         if ($this->serialize) {
             $data = serialize($data);
         }
         $this->getCacheAdapter()->save($key, $data, $lifetime);
     }
     return $lifetime;
 }
开发者ID:norv,项目名称:guzzle,代码行数:30,代码来源:CachePlugin.php

示例10: testCalculatesFreshness

 /**
  * @covers Guzzle\Http\Message\Response::getFreshness
  * @covers Guzzle\Http\Message\Response::isFresh
  */
 public function testCalculatesFreshness()
 {
     $response = new Response(200);
     $this->assertNull($response->isFresh());
     $this->assertNull($response->getFreshness());
     $response->addCacheControlDirective('max-age', 120);
     $response->setHeader('Age', 100);
     $this->assertEquals(20, $response->getFreshness());
     $this->assertTrue($response->isFresh());
     $response->setHeader('Age', 150);
     $this->assertEquals(-30, $response->getFreshness());
     $this->assertFalse($response->isFresh());
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:17,代码来源:ResponseTest.php

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

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

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


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