當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::setHeaders方法代碼示例

本文整理匯總了PHP中Zend\Http\Response::setHeaders方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::setHeaders方法的具體用法?PHP Response::setHeaders怎麽用?PHP Response::setHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Http\Response的用法示例。


在下文中一共展示了Response::setHeaders方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: sendHandshakeResponse

 private function sendHandshakeResponse()
 {
     try {
         $challengeHeader = $this->getHandshakeRequest()->getHeader('Sec-Websocket-Key', null);
         if (!$challengeHeader) {
             throw new Exception("No Sec-WebSocket-Key received!");
         }
         // Check for newer handshake
         $challenge = $challengeHeader->getFieldValue();
         // Build response
         $response = new Response();
         $response->setStatusCode(101);
         $response->setReasonPhrase("WebSocket Protocol Handshake");
         $headers = new Headers();
         $response->setHeaders($headers);
         $headers->addHeaderLine("Upgrade", "WebSocket");
         $headers->addHeaderLine("Connection", "Upgrade");
         $headers->addHeaderLine("Sec-WebSocket-Accept", self::calcHybiResponse($challenge));
         $this->setResponse($response);
         $handshakeRequest = new Handshake($this->getHandshakeRequest(), $this->getHandshakeResponse());
         $this->emit("handshake", array($handshakeRequest));
         if ($handshakeRequest->isAborted()) {
             $this->close();
         } else {
             $this->_socket->write($response->toString());
             $this->logger->debug("Got an HYBI style request, sent HYBY handshake response");
             $this->connected = true;
             $this->emit("connect");
         }
     } catch (Exception $e) {
         $this->logger->err("Connection error, message: " . $e->getMessage());
         $this->close();
     }
 }
開發者ID:rb-cohen,項目名稱:phpws,代碼行數:34,代碼來源:WebSocketTransportHybi.php

示例2: testRequestCanSetHeaders

 public function testRequestCanSetHeaders()
 {
     $response = new Response();
     $headers = new \Zend\Http\Headers();
     $ret = $response->setHeaders($headers);
     $this->assertInstanceOf('Zend\\Http\\Response', $ret);
     $this->assertSame($headers, $response->getHeaders());
 }
開發者ID:haoyanfei,項目名稱:zf2,代碼行數:8,代碼來源:ResponseTest.php

示例3: setUp

 public function setUp()
 {
     $response = new Response();
     $response->setHeaders(new Headers());
     $mvcEvent = new MvcEvent();
     $mvcEvent->setResponse($response);
     $this->error = new ApiError($mvcEvent);
 }
開發者ID:sebaks,項目名稱:zend-mvc-controller,代碼行數:8,代碼來源:ApiErrorTest.php

示例4: testFromResponseInCookie

 public function testFromResponseInCookie()
 {
     $response = new Response();
     $headers = new Headers();
     $header = new SetCookie("foo", "bar");
     $header->setDomain("www.zend.com");
     $header->setPath("/");
     $headers->addHeader($header);
     $response->setHeaders($headers);
     $response = Cookies::fromResponse($response, "http://www.zend.com");
     $this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo'));
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:12,代碼來源:CookiesTest.php

示例5: testWrongContentTypeThrowsInvalidResponseException

 public function testWrongContentTypeThrowsInvalidResponseException()
 {
     $this->setExpectedException('Magium\\Mail\\Api\\InvalidResponseException');
     $builder = $this->getMockBuilder('Zend\\Http\\Client')->setMethods(['send']);
     $client = $builder->getMock();
     /* @var $client \Zend\Http\Client */
     $response = new Response();
     $response->setContent(json_encode(['error' => 'error message']));
     $response->setHeaders(Headers::fromString('Content-Type: wrong'));
     $client->expects($this->once())->method('send')->willReturn($response);
     $generator = new Generator(new Configuration(), $client, 'abcd');
     $generator->generate();
 }
開發者ID:magium,項目名稱:MagiumMail,代碼行數:13,代碼來源:ErrorTest.php

示例6: testUrlIsRight

 public function testUrlIsRight()
 {
     $builder = $this->getMockBuilder('Zend\\Http\\Client')->setMethods(['send']);
     $client = $builder->getMock();
     /* @var $client \Zend\Http\Client */
     $response = new Response();
     $response->setContent(json_encode(['email' => 'test@example.com']));
     $response->setHeaders(Headers::fromString('Content-Type: application/json'));
     $client->expects($this->once())->method('send')->willReturn($response);
     $configuration = new Configuration();
     $generator = new Generator($configuration, $client, 'abcd');
     $email = $generator->generate();
     self::assertEquals('test@example.com', $email);
     self::assertEquals($configuration->getApiEndpointUrl(), $client->getUri()->toString());
 }
開發者ID:magium,項目名稱:MagiumMail,代碼行數:15,代碼來源:SuccessTest.php

示例7: sendHandshakeResponse

 private function sendHandshakeResponse()
 {
     // Last 8 bytes of the client's handshake are used for key calculation later
     $l8b = $this->request->getContent();
     // Check for 2-key based handshake (Hixie protocol draft)
     $key1 = $this->getHandshakeRequest()->getHeader('Sec-Websocket-Key1')->getFieldValue();
     $key2 = $this->getHandshakeRequest()->getHeader('Sec-Websocket-Key2')->getFieldValue();
     // Origin checking (TODO)
     $originHeader = $this->getHandshakeRequest()->getHeader('Origin', null);
     $host = $this->getHandshakeRequest()->getHeader('Host')->getFieldValue();
     $location = $this->getHandshakeRequest()->getUriString();
     // Build response
     $response = new Response();
     $response->setStatusCode(101);
     $response->setReasonPhrase("WebSocket Protocol Handshake");
     $headers = new Headers();
     $response->setHeaders($headers);
     $headers->addHeaderLine("Upgrade", "WebSocket");
     $headers->addHeaderLine("Connection", "Upgrade");
     if ($originHeader) {
         $headers->addHeaderLine("Sec-WebSocket-Origin", $originHeader->getFieldValue());
     }
     $headers->addHeaderLine("Sec-WebSocket-Location", "ws://{$host}{$location}");
     // Build HIXIE response
     $response->setContent(self::calcHixieResponse($key1, $key2, $l8b));
     $this->setResponse($response);
     $handshakeRequest = new Handshake($this->getHandshakeRequest(), $this->getHandshakeResponse());
     $this->emit("handshake", [$handshakeRequest]);
     if ($handshakeRequest->isAborted()) {
         $this->close();
     } else {
         $this->socket->write($response->toString());
         $this->logger->debug("Got an HYBI style request, sent HYBY handshake response");
         $this->emit("connect");
     }
 }
開發者ID:valinurovam,項目名稱:phpws,代碼行數:36,代碼來源:WebSocketTransportHixie.php

示例8: testGetContent

 /**
  * @covers Hermes\Api\Response::__construct
  * @covers Hermes\Api\Response::getContent
  */
 public function testGetContent()
 {
     $http = new Client();
     $response = new ZendResponse();
     $headers = new Headers();
     $headers->addHeaderLine('Content-Type', 'application/json');
     $response->setHeaders($headers);
     $response->setContent(static::$sampleJson);
     $this->object = new Response($http, $response);
     $content = $this->object->getContent();
 }
開發者ID:mt-olympus,項目名稱:hermes,代碼行數:15,代碼來源:ResponseTest.php


注:本文中的Zend\Http\Response::setHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。