当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setStatus方法代码示例

本文整理汇总了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;
 }
开发者ID:adrianoaguiar,项目名称:magento-elasticsearch-module,代码行数:33,代码来源:RequestMediator.php

示例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);
 }
开发者ID:steverhoades,项目名称:async-talk-examples,代码行数:25,代码来源:Router.php

示例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;
 }
开发者ID:unkerror,项目名称:Budabot,代码行数:12,代码来源:Hixie76.php

示例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;
 }
开发者ID:DannyHuisman,项目名称:Ratchet,代码行数:17,代码来源:Hixie76.php


注:本文中的Guzzle\Http\Message\Response::setStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。