Exemplo n.º 1
0
 /**
  * Tests the HTTP headers are parsed correctly.
  */
 public function testParseHeaders()
 {
     $requestLine = "GET / HTTP/1.1";
     $headerArray = ["Header1" => "Value1", "Header2" => "Value2", "Header3" => "Value3", "Header4" => "Value4"];
     $requestString = self::BuildRequest($requestLine, $headerArray);
     $req = HttpRequest::FromString($requestString);
     self::assertEquals($headerArray, $req->getHeaders());
     self::assertEquals($requestLine, $req->getRequestLine());
 }
    /**
     * Tests a good handshake.
     */
    public function testValidateGoodRequest()
    {
        // from the RFC
        $requestString = <<<REQ
GET / HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13

REQ;
        $req = HttpRequest::FromString($requestString);
        $webSocketRequest = new WebSocketRequest($req);
        self::assertTrue($webSocketRequest->validate());
    }