本文整理汇总了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));
}
}
}
示例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));
}
}
}
示例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);
}