コード例 #1
0
ファイル: ParserTest.php プロジェクト: lt/artax
 /**
  * @dataProvider provideParseExpectations
  */
 public function testIncrementalParse($msg, $method, $uri, $protocol, $headers, $body)
 {
     $msgParser = new Parser();
     $byteIncrement = 1;
     $msgLen = strlen($msg);
     for ($i = 0; $i < $msgLen; $i += $byteIncrement) {
         $msgPart = $msg[$i];
         $parsedRequestArr = $msgParser->parse($msgPart);
         if (NULL !== $parsedRequestArr) {
             break;
         }
     }
     $actualBody = $parsedRequestArr['body'] ? stream_get_contents($parsedRequestArr['body']) : $parsedRequestArr['body'];
     $this->assertEquals($method, $parsedRequestArr['method']);
     $this->assertEquals($uri, $parsedRequestArr['uri']);
     $this->assertEquals($protocol, $parsedRequestArr['protocol']);
     $this->assertEquals($headers, $parsedRequestArr['headers']);
     $this->assertEquals($body, $actualBody);
 }
コード例 #2
0
ファイル: Client.php プロジェクト: softwarevamp/artax
 private function onCryptoCompletion(RequestCycle $cycle)
 {
     $parser = new Parser(Parser::MODE_RESPONSE);
     $parser->enqueueResponseMethodMatch($cycle->request->getMethod());
     $parser->setAllOptions([Parser::OP_DISCARD_BODY => $cycle->options[self::OP_DISCARD_BODY], Parser::OP_RETURN_BEFORE_ENTITY => true, Parser::OP_BODY_DATA_CALLBACK => function ($data) use($cycle) {
         $cycle->futureResponse->update([Notify::RESPONSE_BODY_DATA, $data]);
     }]);
     $cycle->parser = $parser;
     $cycle->readWatcher = $this->reactor->onReadable($cycle->socket, function () use($cycle) {
         $this->onReadableSocket($cycle);
     });
     $timeout = $cycle->options[self::OP_MS_TRANSFER_TIMEOUT];
     if ($timeout > 0) {
         $cycle->transferTimeoutWatcher = $this->reactor->once(function () use($cycle, $timeout) {
             $this->fail($cycle, new TimeoutException(sprintf('Allowed transfer timeout exceeded: %d ms', $timeout)));
         }, $timeout);
     }
     $this->writeRequest($cycle);
 }