本文整理汇总了PHP中GuzzleHttp\Message\Response::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setHeader方法的具体用法?PHP Response::setHeader怎么用?PHP Response::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\Response
的用法示例。
在下文中一共展示了Response::setHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Response
function it_can_get_the_response_headers(ClientInterface $client)
{
$url = 'http://doc.build/api/documents/someid/payload';
$response = new Response(200);
$response->setHeader('Content-Disposition', 'attachment');
$response->setHeader('filename', 'TestDocument1.docx');
$response->setBody(Stream::factory(""));
$client->get($url, Argument::any())->willReturn($response);
$this->get('documents/someid/payload');
$expected = ['Content-Disposition' => ['attachment'], 'filename' => ['TestDocument1.docx']];
$this->getResponseHeaders()->shouldEqual($expected);
}
示例2: createResponse
/**
* Taken from Mink\BrowserKitDriver
*
* @param Response $response
*
* @return \Symfony\Component\BrowserKit\Response
*/
protected function createResponse(Response $response)
{
$contentType = $response->getHeader('Content-Type');
$matches = null;
if (!$contentType or strpos($contentType, 'charset=') === false) {
$body = $response->getBody(true);
if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
$response->setHeader('Content-Type', $contentType);
}
$headers = $response->getHeaders();
$status = $response->getStatusCode();
$matchesMeta = null;
$matchesHeader = null;
$isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
$isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
$matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
$uri = $this->getAbsoluteUri($matches[2]);
$partsUri = parse_url($uri);
$partsCur = parse_url($this->getHistory()->current()->getUri());
foreach ($partsCur as $key => $part) {
if ($key === 'fragment') {
continue;
}
if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
$status = 302;
$headers['Location'] = $uri;
break;
}
}
}
return new BrowserKitResponse($response->getBody(), $status, $headers);
}
示例3: makeResponse
/**
* Create a Response object from a stub.
*
* @param $stub
* @return \GuzzleHttp\Message\Response
*/
private function makeResponse($stub)
{
$response = new Response(200);
$response->setHeader('Content-Type', 'application/json');
$responseBody = Stream::factory(fopen('./tests/Destiny/stubs/' . $stub . '.txt', 'r+'));
$response->setBody($responseBody);
return $response;
}
示例4: createResponse
/**
* Taken from Mink\BrowserKitDriver
*
* @param Response $response
*
* @return \Symfony\Component\BrowserKit\Response
*/
protected function createResponse(Response $response)
{
$contentType = $response->getHeader('Content-Type');
if (!$contentType or strpos($contentType, 'charset=') === false) {
$body = $response->getBody(true);
if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
$response->setHeader('Content-Type', $contentType);
}
$headers = $response->getHeaders();
$status = $response->getStatusCode();
if (preg_match('/\\<meta[^\\>]+http-equiv="refresh" content=".*?url=(.*?)"/i', $response->getBody(true), $matches)) {
$status = 302;
$headers['Location'] = $matches[1];
}
if (preg_match('~url=(.*)~', (string) $response->getHeader('Refresh'), $matches)) {
$status = 302;
$headers['Location'] = $matches[1];
}
return new BrowserKitResponse($response->getBody(), $status, $headers);
}
示例5: testGetHeader
public function testGetHeader()
{
$this->guzzleResponse->setHeader('bar', 'foo');
$this->assertEquals('foo', $this->response->getHeader('bar'));
}