本文整理汇总了PHP中Response::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getHeader方法的具体用法?PHP Response::getHeader怎么用?PHP Response::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::getHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDeleteHeader
public function testDeleteHeader()
{
$this->object->setHeader('Sample', 'value');
$this->assertThat($this->object->getHeader('sample'), $this->equalTo('value'));
$this->object->deleteHeader('Sample');
$this->assertThat($this->object->getHeader('sample'), $this->equalTo(null));
}
示例2: getLatestResponseHeaders
/**
* {@inheritdoc}
*/
public function getLatestResponseHeaders()
{
if (null === $this->response) {
return;
}
return ['reset' => (int) (string) $this->response->getHeader('RateLimit-Reset'), 'remaining' => (int) (string) $this->response->getHeader('RateLimit-Remaining'), 'limit' => (int) (string) $this->response->getHeader('RateLimit-Limit')];
}
示例3: matchModified
/**
* Returns whether a resource has been modified between two requests.
*
* @return bool
*/
protected function matchModified()
{
$lastModified = $this->response->getHeader("Last-Modified");
$modifiedSince = $this->request->getModifiedSince();
if ($modifiedSince && $lastModified) {
return strtotime($modifiedSince) >= strtotime($lastModified);
}
return false;
}
示例4: redirect
/**
* redirect from response 3xx
*/
protected function redirect()
{
$redirect_url = $this->response->getHeader("location");
$curl = new static($redirect_url);
if ($this->cookie_jar) {
$curl->storeSession($this->cookie_jar);
}
$this->response = $curl->get();
$this->redirect_urls[] = $redirect_url;
}
示例5: testConstruct
public function testConstruct()
{
$response = new Response(["test" => "value"], "php://memory", 201, "1.1");
$this->assertInstanceOf('Psr\\Http\\Message\\StreamInterface', $response->getBody());
$this->assertEquals(["test" => ["value"]], $response->getHeaders());
$this->assertEquals("1.1", $response->getProtocolVersion());
$this->assertEquals(["value"], $response->getHeader("test"));
$this->assertEquals(201, $response->getStatusCode());
$this->assertEquals("Created", $response->getReasonPhrase());
}
示例6: __construct
public function __construct(Response $parent)
{
$status = $parent->getStatus();
$convertToJson = false;
$ok = self::statusIsOK($status);
if ($ok) {
$contentType = $parent->getHeader('Content-Type');
if (!empty($contentType)) {
$convertToJson = stristr($contentType, '/json') !== false;
}
}
$bodyString = $parent->getBody();
parent::__construct($convertToJson ? json_decode($bodyString) : $bodyString, $parent->getHeaders(), $status);
$this->ok = $ok;
}
示例7: validateResponse
/**
* {@inheritdoc}
*/
public function validateResponse(Request $request, Response $response) : bool
{
if (Response::SWITCHING_PROTOCOLS !== $response->getStatusCode()) {
return false;
}
if ('upgrade' !== strtolower($response->getHeader('Connection'))) {
return false;
}
if ('websocket' !== strtolower($response->getHeader('Upgrade'))) {
return false;
}
$key = $request->getHeader('Sec-WebSocket-Key');
if (!$response->hasHeader('Sec-WebSocket-Accept')) {
return false;
}
return $this->responseKey($key) === $response->getHeader('Sec-WebSocket-Accept');
}
示例8: onReceive
function onReceive($serv, $client_id, $from_id, $data)
{
$response = new Response();
$response->body = json_encode(array(1, 2, 3));
$this->server->getSwoole()->send($client_id, $response->getHeader() . $response->body);
sleep(1);
$this->server->getSwoole()->close($client_id);
return;
// //检测request data完整性
// $ret = $this->checkData($client_id, $data);
// switch($ret)
// {
// //错误的请求
// case self::ST_ERROR;
// $this->server->close($client_id);
// return;
// //请求不完整,继续等待
// case self::ST_WAIT:
// return;
// default:
// break;
// }
// //完整的请求
// //开始处理
// $request = $this->requests[$client_id];
// $info = $serv->connection_info($client_id);
// $request->remote_ip = $info['remote_ip'];
// $_SERVER['SWOOLE_CONNECTION_INFO'] = $info;
// $this->parseRequest($request);
// $request->fd = $client_id;
// $this->currentRequest = $request;
// if ($this->async)
// {
// $this->onAsyncRequest($request);
// }
// else
// {
// //处理请求,产生response对象
// $response = $this->onRequest($request);
// //发送response
// $this->response($request, $response);
// }
Console::output("onReceive");
}
示例9: trim
/**
* @param Response $response
*/
function __construct(Response $response)
{
$this->response = $response;
if (($h = $response->getHeader("Content-Type", Header::class)) && $h->match("application/json", Header::MATCH_WORD) && ($failure = json_decode($response->getBody()))) {
$message = $failure->message;
if (isset($failure->errors)) {
$this->errors = (array) $failure->errors;
}
} else {
$message = trim($response->getBody()->toString());
}
if (!strlen($message)) {
$message = $response->getTransferInfo("error");
}
if (!strlen($message)) {
$message = $response->getResponseStatus();
}
parent::__construct($message, $response->getResponseCode(), null);
}
示例10: buildOutgoingResponse
/**
* {@inheritdoc}
*/
public function buildOutgoingResponse(Response $response, Request $request = null, float $timeout = 0, bool $allowPersistent = false) : \Generator
{
if ('upgrade' === strtolower($response->getHeader('Connection'))) {
return $response;
}
if ($allowPersistent && null !== $request && 'keep-alive' === strtolower($request->getHeader('Connection'))) {
$response = $response->withHeader('Connection', 'keep-alive')->withHeader('Keep-Alive', sprintf('timeout=%d, max=%d', $this->keepAliveTimeout, $this->keepAliveMax));
} else {
$response = $response->withHeader('Connection', 'close');
}
$response = $response->withoutHeader('Content-Encoding');
if ($this->compressionEnabled && null !== $request && $request->hasHeader('Accept-Encoding') && $response->hasHeader('Content-Type') && preg_match('/gzip|deflate/i', $request->getHeader('Accept-Encoding'), $matches)) {
$encoding = strtolower($matches[0]);
$contentType = $response->getHeader('Content-Type');
foreach ($this->compressTypes as $pattern) {
if (preg_match($pattern, $contentType)) {
$response = $response->withHeader('Content-Encoding', $encoding);
break;
}
}
}
return yield from $this->buildOutgoingStream($response, $timeout);
}
示例11: import
/**
* Import handler for the endpoint's underlying data
*
* \seekat\Call will call this when the request will have finished.
*
* @param Response $response
* @return API self
* @throws UnexpectedValueException
* @throws RequestException
* @throws \Exception
*/
function import(Response $response) : API
{
$this->__log->info(__FUNCTION__ . ": " . $response->getInfo(), ["url" => (string) $this->__url]);
if ($response->getResponseCode() >= 400) {
$e = new RequestException($response);
$this->__log->critical(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
throw $e;
}
if (!($type = $response->getHeader("Content-Type", Header::class))) {
$e = new RequestException($response);
$this->__log->error(__FUNCTION__ . ": Empty Content-Type -> " . $e->getMessage(), ["url" => (string) $this->__url]);
throw $e;
}
try {
$this->__type = new ContentType($type);
$this->__data = $this->__type->parseBody($response->getBody());
if ($link = $response->getHeader("Link", Header::class)) {
$this->__links = new Links($link);
}
} catch (\Exception $e) {
$this->__log->error(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
throw $e;
}
return $this;
}
示例12: updateFromResponse
/**
* Updates the cookie jar from a Response object.
*
* @param Symfony\Components\BrowserKit\Response $response A Response object
* @param string $url The base URL
*/
public function updateFromResponse(Response $response, $uri = null)
{
foreach ($response->getHeader('Set-Cookie', false) as $cookie) {
$this->set(Cookie::fromString($cookie), $uri);
}
}
示例13: updateFromResponse
/**
* Updates the cookie jar from a Response object.
*
* @param Response $response A Response object
* @param string $uri The base URL
*/
public function updateFromResponse(Response $response, $uri = null)
{
$cookies = array();
foreach ($response->getHeader('Set-Cookie', false) as $cookie) {
foreach (explode(',', $cookie) as $i => $part) {
if (0 === $i || preg_match('/^(?P<token>\\s*[0-9A-Za-z!#\\$%\\&\'\\*\\+\\-\\.^_`\\|~]+)=/', $part)) {
$cookies[] = ltrim($part);
} else {
$cookies[count($cookies) - 1] .= ',' . $part;
}
}
}
foreach ($cookies as $cookie) {
$this->set(Cookie::fromString($cookie, $uri));
}
}
示例14: updateFromResponse
/**
* Updates the cookie jar from a Response object.
*
* @param Response $response A Response object
* @param string $uri The base URL
*/
public function updateFromResponse(Response $response, $uri = null)
{
$this->updateFromSetCookie($response->getHeader('Set-Cookie', false), $uri);
}
示例15: getResponseHeader
/**
* Get response header(s) after the request has been sent.
* @param string $name Header name (optional), If name was given and and not found NULL is returned
* @param string $default Default value in case header with $name was not found
* @return array|string|NULL
*/
public function getResponseHeader($name = NULL, $default = NULL)
{
return $this->response->getHeader($name, $default);
}