本文整理汇总了PHP中Buzz\Message\Response::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getHeader方法的具体用法?PHP Response::getHeader怎么用?PHP Response::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Buzz\Message\Response
的用法示例。
在下文中一共展示了Response::getHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rev
public function rev(Response $response)
{
if ($response->isSuccessful()) {
return $this->decode($response->getHeader('Etag'));
}
throw new RugException('not_found', 'The specified document or revision cannot be found or has been deleted');
}
示例2: processSetCookieHeaders
/**
* Processes Set-Cookie headers from a request/response pair.
*
* @param Message\Request $request A request object
* @param Message\Response $response A response object
*/
public function processSetCookieHeaders(Message\Request $request, Message\Response $response)
{
foreach ($response->getHeader('Set-Cookie', false) as $header) {
$cookie = new Cookie();
$cookie->fromSetCookieHeader($header, parse_url($request->getHost(), PHP_URL_HOST));
$this->addCookie($cookie);
}
}
示例3: assertHttpResponseHasHeader
protected function assertHttpResponseHasHeader(HttpResponse $response, $header, $expectedValue = null)
{
$headerValue = $response->getHeader($header);
self::assertNotNull($headerValue, "Failed asserting that response has a {$header} header");
if ($expectedValue !== null) {
self::assertEquals($expectedValue, $headerValue);
}
}
示例4: handleResponseAuthHeader
/**
* @param \Buzz\Message\Response $response
*/
private function handleResponseAuthHeader(\Buzz\Message\Response $response)
{
$token = $response->getHeader('Update-Client-Auth');
if ($token) {
$this->client->setAuthToken($token);
$this->setTokenToCache($token);
}
}
示例5: __construct
/**
* @param string|null $message
*/
public function __construct(RequestInterface $request, Response $response, $message = null)
{
$this->request = $request;
$this->response = $response;
if ($message === null) {
$curlError = $response->getHeader('X-Curl-Error-Result');
$message = sprintf('HTTP %s request to "%s%s" failed: %d - "%s".', $request->getMethod(), $request->getHost(), $request->getResource(), $curlError ?: $response->getStatusCode(), $curlError ? curl_strerror($curlError) : $response->getReasonPhrase());
}
parent::__construct($message);
}
示例6: isExpired
/**
* @param Response $response
* @param int $minFresh
* @return bool
*/
public function isExpired(Response $response, $minFresh = 5)
{
$expires = $response->getHeader('expires');
if ($expires !== null) {
$parsedExpires = strtotime($expires);
if ($parsedExpires === false || time() + $minFresh > $parsedExpires) {
return true;
}
}
return false;
}
示例7: decompressContent
private function decompressContent(\Buzz\Message\Response $response)
{
if (!($content_encoding = $response->getHeader('Content-Encoding'))) {
return;
}
$content = $response->getContent();
if (strpos($content_encoding, 'deflate') !== false) {
$content = gzuncompress($content);
}
if (strpos($content_encoding, 'gzip') !== false) {
$content = gzinflate(substr($content, 10));
}
$response->setContent($content);
}
示例8: getPagination
protected static function getPagination(Response $response)
{
$header = $response->getHeader('Link');
if (empty($header)) {
return;
}
$pagination = [];
foreach (explode(',', $header) as $link) {
preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match);
if (3 === count($match)) {
$pagination[$match[2]] = $match[1];
}
}
return $pagination;
}
示例9: assertHttpResponseDeletesSessionCookie
private static function assertHttpResponseDeletesSessionCookie($session, Response $response)
{
self::assertStringStartsWith("{$session->name}=deleted;", $response->getHeader('set-cookie'));
}
示例10: validateResponse
/**
* @param Response $response
* @param string $method
* @param array $arguments
* @return \stdClass
* @throws \RuntimeException
*/
protected function validateResponse($response, $method, $arguments)
{
if (!in_array($response->getStatusCode(), array(200, 401, 409))) {
throw new \RuntimeException('Unexpected response received from Transmission');
}
if ($response->getStatusCode() == 401) {
throw new \RuntimeException('Access to Transmission requires authentication');
}
if ($response->getStatusCode() == 409) {
$this->setToken($response->getHeader(self::TOKEN_HEADER));
return $this->call($method, $arguments);
}
return json_decode($response->getContent());
}
示例11: mimeTypeByResponse
/**
* @param Response $response
*
* @return string|null
*/
protected function mimeTypeByResponse(Response $response)
{
$mimeType = $response->getHeader('Content-Type', false);
if (count($mimeType) > 0) {
$mimeType = array_pop($mimeType);
$mimeType = explode(';', $mimeType);
$mimeType = trim(array_shift($mimeType));
if ('text/plain' !== strtolower($mimeType)) {
return $mimeType;
}
}
return null;
}
示例12: sendCookiesFromResponse
/**
* Send cookies to client from a contao response object
*
* @param Response $response
* @return bool
*/
protected function sendCookiesFromResponse(Response $response)
{
// Set cookies from the contao response
if ($response->getHeader('set-cookie')) {
$delimiter = ' || ';
$cookies = explode($delimiter, $response->getHeader('set-cookie', $delimiter));
foreach ($cookies as $cookie) {
// The second param has to be false otherwise other cookies like from phpbb itself are replaced
header('Set-Cookie: ' . $cookie, false);
}
// The following won't work because the expire value is not an int and conversion something like
// 16-Jan-2016 18:07:35 GMT to an int is really unnecessary overhead
// although it's looks cleaner at first like above solution
// $cookieJar = new CookieJar();
// $cookieJar->processSetCookieHeaders($browser->getLastRequest(), $response);
// foreach($cookieJar->getCookies() as $cookie) {
// setcookie($cookie->getName(), $cookie->getValue(), $cookie->getAttribute('expires'), $cookie->getAttribute('path'), $cookie->getAttribute('domain'), $cookie->getAttribute('secure'),$cookie->getAttribute('httponly'));
// } }
}
}
示例13: isJsonResponse
/**
* Checks if we had a successfull response with Json content in it
*
* @param Response $response
* @return bool
*/
protected function isJsonResponse(Response $response)
{
return $response->getStatusCode() == 200 && $response->getHeader('content-type') == 'application/json';
}
示例14: collectLocations
/**
* @Then /^save new item location as "([^"]*)"$/
* @param string $location
*
* @return boolean
*/
public function collectLocations($locationIndex)
{
$this->response = $this->client->getLastResponse();
$this->locations[$locationIndex] = $this->response->getHeader('X-Location');
}
示例15: getSessionIdFromResponse
protected function getSessionIdFromResponse(Response $response)
{
$statusCode = $response->getStatusCode();
if ($statusCode === 200) {
$content = json_decode($response->getContent(), true);
if ($content['status'] !== 0) {
throw new LibraryException(sprintf('Expected status 0, got "%s".', $content['status']));
}
return $content['sessionId'];
}
if ($statusCode !== 302) {
echo $response->getContent();
throw new LibraryException(sprintf('The response should be a redirection, response code from server was "%s"', $statusCode));
}
$location = $response->getHeader('Location');
if (!preg_match('#/session/([0-9a-f\\-]+)?#', $location, $vars)) {
throw new LibraryException(sprintf('The Location should end with /session/<session-id> (location returned: %s)', $location));
}
return $vars[1];
}