本文整理汇总了PHP中GuzzleHttp\Message\ResponseInterface::hasHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::hasHeader方法的具体用法?PHP ResponseInterface::hasHeader怎么用?PHP ResponseInterface::hasHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\ResponseInterface
的用法示例。
在下文中一共展示了ResponseInterface::hasHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decode
public function decode(ResponseInterface $raw, $totalTime = 0)
{
$executionTime = $callTime = 0;
if ($raw->hasHeader('X-Execution-Time')) {
$executionTime = $raw->getHeader('X-Execution-Time');
}
if ($raw->hasHeader('X-Call-Time')) {
$callTime = $raw->getHeader('X-Call-Time');
}
$body = '';
try {
$body = (string) $raw->getBody();
$result = $this->_getDecoder()->decode($body, self::FORMAT, $this->_getDecodeContext());
} catch (\Exception $e) {
if (!empty($body)) {
$body = ' (' . $body . ')';
}
error_log("Invalid API Response: " . $body);
throw new InvalidApiResponseException("Unable to decode raw api response.", 500, $e);
}
if (!property_exists($result, 'type') || !property_exists($result, 'status') || !property_exists($result, 'result') || !property_exists($result->status, 'message') || !property_exists($result->status, 'code')) {
error_log("Invalid API Result: " . json_encode($result));
throw new InvalidApiResponseException("Invalid api result", 500);
}
if ($executionTime === 0) {
$executionTime = $totalTime;
}
if ($callTime === 0) {
$callTime = $executionTime;
}
return ResponseBuilder::create(ApiCallData::create($result->type, $result->result, $result->status->code, $result->status->message, (double) str_replace([',', 'ms'], '', $totalTime), (double) str_replace([',', 'ms'], '', $executionTime), (double) str_replace([',', 'ms'], '', $callTime)));
}
示例2: getExpected
private function getExpected(ResponseInterface $response)
{
if (!($body = $response->getBody())) {
return false;
} elseif ($response->hasHeader('Transfer-Encoding') || $response->hasHeader('Content-Encoding')) {
// Currently does not support un-gzipping or inflating responses
return false;
}
return call_user_func($this->expectedFn, $response);
}
示例3: canValidate
private function canValidate(ResponseInterface $response)
{
if (!($body = $response->getBody())) {
return false;
} elseif ($response->hasHeader('Transfer-Encoding') || $response->hasHeader('Content-Encoding')) {
// Currently does not support un-gzipping or inflating responses
return false;
} elseif (!$body->isSeekable()) {
return false;
} elseif ($this->sizeCutoff !== null && $body->getSize() > $this->sizeCutoff) {
return false;
}
return true;
}
示例4: getLocation
/**
* Gets the Location header.
*
* @throws \RuntimeException If the Location header is missing
*
* @return string
*/
public function getLocation()
{
if (!$this->response->hasHeader('Location')) {
throw new \RuntimeException('Response is missing a Location header');
}
return $this->response->getHeader('Location');
}
示例5: getResponseAge
/**
* Gets the age of a response in seconds.
*
* @param ResponseInterface $response
*
* @return int
*/
public static function getResponseAge(ResponseInterface $response)
{
if ($response->hasHeader('Age')) {
return (int) $response->getHeader('Age');
}
$date = strtotime($response->getHeader('Date') ?: 'now');
return time() - $date;
}
示例6: handle304Response
private function handle304Response(RequestInterface $request, ResponseInterface $response, ResponseInterface $validated, CompleteEvent $event)
{
// Make sure that this response has the same ETag
if ($validated->getHeader('ETag') !== $response->getHeader('ETag')) {
// Revalidation failed, so remove from cache and retry.
$this->storage->delete($request);
$event->intercept($event->getClient()->send($request));
return;
}
// Replace cached headers with any of these headers from the
// origin server that might be more up to date
$modified = false;
foreach (self::$replaceHeaders as $name) {
if ($validated->hasHeader($name) && $validated->getHeader($name) != $response->getHeader($name)) {
$modified = true;
$response->setHeader($name, $validated->getHeader($name));
}
}
// Store the updated response in cache
if ($modified) {
$this->storage->cache($request, $response);
}
}
示例7: parseTokenResponse
/**
* Parses the fetched tokens.
*
* @param $resp GuzzleHttp\Message\ReponseInterface the response.
* @return array the tokens parsed from the response body.
*/
public function parseTokenResponse(ResponseInterface $resp)
{
$body = $resp->getBody()->getContents();
if ($resp->hasHeader('Content-Type') && $resp->getHeader('Content-Type') == 'application/x-www-form-urlencoded') {
$res = array();
parse_str($body, $res);
return $res;
} else {
// Assume it's JSON; if it's not there needs to be an exception, so
// we use the json decode exception instead of adding a new one.
return $resp->json();
}
}
示例8: theResponseHeaderLocationShouldContainsPath
/**
* Checks that the response has header location contains path
*
* @Then /^the response header location should contains "([^"]+)"$/
*/
public function theResponseHeaderLocationShouldContainsPath($path)
{
Assertions::assertTrue($this->response->hasHeader('location'));
Assertions::assertContains($path, $this->response->getHeader('location'));
}
示例9: theOcChecksumHeaderShouldNotBeThere
/**
* @Then The OC-Checksum header should not be there
*/
public function theOcChecksumHeaderShouldNotBeThere()
{
if ($this->response->hasHeader('OC-Checksum')) {
throw new \Exception("Expected no checksum header but got " . $this->response->getHeader('OC-Checksum'));
}
}