本文整理汇总了PHP中GuzzleHttp\Message\Response::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getHeaders方法的具体用法?PHP Response::getHeaders怎么用?PHP Response::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\Response
的用法示例。
在下文中一共展示了Response::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deduce
/**
* @return ErrorResponse|SuccessResponse
*/
public function deduce()
{
/* @var array $response */
$response = (array) $this->response->json();
if (array_key_exists('type', $response) && $response['type'] === 'error') {
return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
示例2: __construct
/**
* Constructor
*
* @param GuzzleResponse $response
*/
public function __construct(GuzzleResponse $response)
{
$headers = $response->getHeaders();
//-- this is a hack on my part and I'm terribly sorry it exists
//-- but deal with it.
foreach ($headers as $header => $value) {
$this->headers[$header] = implode(',', array_values((array) $value));
}
$this->url = $response->getEffectiveUrl();
$url_parts = explode('?', $this->url);
if (isset($url_parts[1])) {
$query = explode('&', $url_parts[1]);
foreach ($query as $params) {
$kv = explode('=', $params);
$this->params[$kv[0]] = isset($kv[1]) ? $kv[1] : '';
}
}
// $this->params = $response->request_parameters;
// $this->method = $response->request_method;
$this->json = $response->json();
// $json = json_decode($this->json, TRUE);
$this->data = isset($this->json['data']) ? $this->json['data'] : [];
$this->meta = isset($this->json['meta']) ? $this->json['meta'] : [];
if (isset($this->json['code']) && $this->json['code'] !== 200) {
$this->meta = $this->json;
}
$this->pagination = isset($this->json['pagination']) ? $this->json['pagination'] : [];
$this->user = isset($this->json['user']) ? $this->json['user'] : [];
$this->access_token = isset($this->json['access_token']) ? $this->json['access_token'] : NULL;
$this->limit = isset($this->headers[self::RATE_LIMIT_HEADER]) ? $this->headers[self::RATE_LIMIT_HEADER] : 0;
$this->remaining = isset($this->headers[self::RATE_LIMIT_REMAINING_HEADER]) ? $this->headers[self::RATE_LIMIT_REMAINING_HEADER] : 0;
}
示例3: lastResponseHeaders
/**
* Returns the SOAP headers from the last response.
*
* @return mix The last SOAP response headers.
*/
public function lastResponseHeaders()
{
if ($this->response instanceof Response) {
return $this->response->getHeaders();
}
return [];
}
示例4: 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);
}
示例5:
/**
* @param \GuzzleHttp\Message\Response $response
*/
function __construct($response)
{
parent::__construct($response->getStatusCode(), $response->getHeaders(), $response->getBody());
$jsonBody = $this->json();
if (array_key_exists("code", $jsonBody)) {
$this->internal_code = $jsonBody["code"];
$this->internal_message = $jsonBody["message"];
$this->internal_type = $jsonBody["type"];
}
if (array_key_exists("atoken", $jsonBody) || array_key_exists("uid", $jsonBody)) {
$this->internal_code = 200;
$this->internal_type = $jsonBody["type"] = "oauthResponse";
}
}
示例6: createResponseFromGuzzleResponse
/**
* @param GuzzleResponse $guzzleResponse
*
* @return Response
*/
protected function createResponseFromGuzzleResponse(GuzzleResponse $guzzleResponse)
{
$content = null;
if ($guzzleResponse->getBody() !== null) {
$content = $guzzleResponse->getBody()->getContents();
}
$response = new Response($content, $guzzleResponse->getStatusCode());
$response->setHeaders($guzzleResponse->getHeaders());
$deniedHeaders = array('transfer-encoding', 'x-powered-by', 'content-length', 'content-encoding');
foreach ($deniedHeaders as $headerName) {
$response->removeHeader($headerName);
}
return $response;
}
示例7: testDoesTheSameAsResponseWhenDereferenced
public function testDoesTheSameAsResponseWhenDereferenced()
{
$str = Stream::factory('foo');
$response = new Response(200, ['Foo' => 'bar'], $str);
$future = MockTest::createFuture(function () use($response) {
return $response;
});
$this->assertFalse($this->readAttribute($future, 'isRealized'));
$this->assertEquals(200, $future->getStatusCode());
$this->assertTrue($this->readAttribute($future, 'isRealized'));
// Deref again does nothing.
$future->wait();
$this->assertTrue($this->readAttribute($future, 'isRealized'));
$this->assertEquals('bar', $future->getHeader('Foo'));
$this->assertEquals(['bar'], $future->getHeaderAsarray('Foo'));
$this->assertSame($response->getHeaders(), $future->getHeaders());
$this->assertSame($response->getBody(), $future->getBody());
$this->assertSame($response->getProtocolVersion(), $future->getProtocolVersion());
$this->assertSame($response->getEffectiveUrl(), $future->getEffectiveUrl());
$future->setEffectiveUrl('foo');
$this->assertEquals('foo', $response->getEffectiveUrl());
$this->assertSame($response->getReasonPhrase(), $future->getReasonPhrase());
$this->assertTrue($future->hasHeader('foo'));
$future->removeHeader('Foo');
$this->assertFalse($future->hasHeader('foo'));
$this->assertFalse($response->hasHeader('foo'));
$future->setBody(Stream::factory('true'));
$this->assertEquals('true', (string) $response->getBody());
$this->assertTrue($future->json());
$this->assertSame((string) $response, (string) $future);
$future->setBody(Stream::factory('<a><b>c</b></a>'));
$this->assertEquals('c', (string) $future->xml()->b);
$future->addHeader('a', 'b');
$this->assertEquals('b', $future->getHeader('a'));
$future->addHeaders(['a' => '2']);
$this->assertEquals('b, 2', $future->getHeader('a'));
$future->setHeader('a', '2');
$this->assertEquals('2', $future->getHeader('a'));
$future->setHeaders(['a' => '3']);
$this->assertEquals(['a' => ['3']], $future->getHeaders());
}
示例8: 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);
}
示例9: getGuzzleResponseData
/**
* @param $response HttpResponse
*
* @throws ServerException
*/
private function getGuzzleResponseData($response)
{
if (!is_a($response, 'GuzzleHttp\\Message\\Response')) {
$this->splitResponseToHeadersArrayAndBody($response);
$response = new Response($this->status, $this->headers, null, []);
$this->body = (string) $this->body;
// $this->status = (int) explode(' ', $this->status)[1];
$statusLineArray = explode(" ", trim($this->headers['status'][0]));
$this->status = (int) $statusLineArray[1];
} else {
$this->status = $response->getStatusCode();
$this->body = (string) $response->getBody();
$response->requestHandler = $this->request->requestHandler;
}
$this->headers = $response->getHeaders();
if ($this->verboseExtractStatusLine === true) {
$this->getVerboseStatusLine($response);
}
if (in_array(intval($this->status), $this->enabledHttpServerExceptions)) {
$this->getVerboseStatusLine($response);
throw new ServerException($this->statusPhrase, $this->status);
}
}
示例10: createResponse
protected function createResponse(GuzzleResponse $response)
{
$headers = $response->getHeaders();
return new Response($response->getBody(true), $response->getStatusCode(), $headers);
}
示例11: getHeaders
/**
* @return array
*/
public function getHeaders()
{
return $this->response->getHeaders();
}
示例12: convertResponse
private static function convertResponse(Response $response)
{
$headers = array_map(function ($h) {
return implode(', ', $h);
}, $response->getHeaders());
return ['status' => $response->getStatusCode(), 'reason' => $response->getReasonPhrase(), 'headers' => $headers, 'body' => base64_encode((string) $response->getBody())];
}
示例13: buildSymfonyResponseFromGuzzleResponse
/**
* Convert a Guzzle Response to a Symfony Response
*
* @param GuzzleResponse $prerenderedResponse
* @return SymfonyResponse
*/
private function buildSymfonyResponseFromGuzzleResponse(GuzzleResponse $prerenderedResponse)
{
$body = $prerenderedResponse->getBody();
$statusCode = $prerenderedResponse->getStatusCode();
$headers = $prerenderedResponse->getHeaders();
return new SymfonyResponse($body, $statusCode, $headers);
}
示例14: hardCheckByHeader
/**
* Error check by header
* @param \GuzzleHttp\Message\Response $metaData
* @return array
*/
private function hardCheckByHeader(\GuzzleHttp\Message\Response $metaData)
{
$headers = array_change_key_case($metaData->getHeaders());
$statusCode = (int) $metaData->getStatusCode();
$isErrorPageCode = ['40x' => [401, 403, 404], '50x' => [500, 502, 503], '30x' => [301, 302, 308]];
foreach ($isErrorPageCode as $errorType => $statuses) {
if (in_array($statusCode, $statuses)) {
return ['result' => false, 'status' => "NG : status code {$errorType}"];
}
}
if ($statusCode === 200 && $statusCode === 304) {
return ['result' => true];
}
if (array_key_exists('content-length', $headers) && $headers['content-length'][0] < $this->contentsSize) {
return ['result' => false, 'status' => 'NG : contentsSize'];
}
return ['result' => true];
}
示例15: proxyResponseHeaders
/**
* @param GuzzleHttp\Message\Response
*/
public function proxyResponseHeaders(Response $response = null)
{
if (!$response) {
return;
}
$headers = $response->getHeaders();
foreach ($headers as $header_name => $header_values) {
$header_values = is_array($header_values) ? $header_values : (array) $header_values;
foreach ($header_values as $header_value) {
// Only attempt proxying when WF protocol is detected
if ($this->isLineWildfireProtocol($header_name)) {
$this->_proxy($header_value);
}
}
// foreach header_values
}
// foreach headers
}