本文整理汇总了PHP中Guzzle\Http\Message\Response::setStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setStatus方法的具体用法?PHP Response::setStatus怎么用?PHP Response::setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Response
的用法示例。
在下文中一共展示了Response::setStatus方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: receiveResponseHeader
/**
* Receive a response header from curl
*
* @param resource $curl Curl handle
* @param string $header Received header
*
* @return int
*/
public function receiveResponseHeader($curl, $header)
{
static $normalize = array("\r", "\n");
$length = strlen($header);
$header = str_replace($normalize, '', $header);
if (strpos($header, 'HTTP/') === 0) {
$startLine = explode(' ', $header, 3);
$code = $startLine[1];
$status = isset($startLine[2]) ? $startLine[2] : '';
// Only download the body of the response to the specified response
// body when a successful response is received.
if ($code >= 200 && $code < 300) {
$body = $this->request->getResponseBody();
} else {
$body = EntityBody::factory();
}
$response = new Response($code, null, $body);
$response->setStatus($code, $status);
$this->request->startResponse($response);
$this->request->dispatch('request.receive.status_line', array('request' => $this, 'line' => $header, 'status_code' => $code, 'reason_phrase' => $status));
} elseif ($pos = strpos($header, ':')) {
$this->request->getResponse()->addHeader(trim(substr($header, 0, $pos)), trim(substr($header, $pos + 1)));
}
return $length;
}
示例2: dispatch
public function dispatch($request, $connection)
{
$response = new Response(200);
$path = $request->getPath();
if ($this->match($path)) {
echo "Found match for path: {$path}" . PHP_EOL;
if (is_callable($this->routes[$path])) {
call_user_func_array($this->routes[$path], array($request, $response, $connection));
} else {
throw new \Exception('Invalid route definition.');
}
return;
}
if (is_null($this->fileHandler)) {
throw new \Exception('No file handler configured');
}
if (false === $this->fileHandler->canHandleRequest($request)) {
$response->setStatus(404);
$response->setBody('File not found');
$connection->send($response);
$connection->close();
return;
}
$this->fileHandler->handleRequest($request, $response, $connection);
}
示例3: handshake
/**
* @param Guzzle\Http\Message\RequestInterface
* @return Guzzle\Http\Message\Response
*/
public function handshake(RequestInterface $request)
{
$body = $this->sign($request->getHeader('Sec-WebSocket-Key1', true), $request->getHeader('Sec-WebSocket-Key2', true), (string) $request->getBody());
$headers = array('Upgrade' => 'WebSocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Origin' => $request->getHeader('Origin', true), 'Sec-WebSocket-Location' => 'ws://' . $request->getHeader('Host', true) . $request->getPath());
$response = new Response(101, $headers, $body);
$response->setStatus(101, 'WebSocket Protocol Handshake');
return $response;
}
示例4: handshake
/**
* @param \Guzzle\Http\Message\RequestInterface $request
* @return \Guzzle\Http\Message\Response
* @throws \UnderflowException If there hasn't been enough data received
*/
public function handshake(RequestInterface $request)
{
$body = substr($request->getBody(), 0, 8);
if (8 !== strlen($body)) {
throw new \UnderflowException("Not enough data received to issue challenge response");
}
$challenge = $this->sign((string) $request->getHeader('Sec-WebSocket-Key1'), (string) $request->getHeader('Sec-WebSocket-Key2'), $body);
$headers = array('Upgrade' => 'WebSocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Origin' => (string) $request->getHeader('Origin'), 'Sec-WebSocket-Location' => 'ws://' . (string) $request->getHeader('Host') . $request->getPath());
$response = new Response(101, $headers, $challenge);
$response->setStatus(101, 'WebSocket Protocol Handshake');
return $response;
}