Пример #1
0
 public function testHeaderOverflowShouldEmitError()
 {
     $error = null;
     $parser = new RequestHeaderParser();
     $parser->on('headers', $this->expectCallableNever());
     $parser->on('error', function ($message) use(&$error) {
         $error = $message;
     });
     $data = str_repeat('A', 4097);
     $parser->feed($data);
     $this->assertInstanceOf('OverflowException', $error);
     $this->assertSame('Maximum header size of 4096 exceeded.', $error->getMessage());
 }
Пример #2
0
 public function __construct(SocketServerInterface $io)
 {
     $this->io = $io;
     $this->io->on('connection', function (ConnectionInterface $conn) {
         // TODO: http 1.1 keep-alive
         // TODO: chunked transfer encoding (also for outgoing data)
         // TODO: multipart parsing
         $parser = new RequestHeaderParser();
         $parser->on('headers', function (Request $request, $bodyBuffer) use($conn, $parser) {
             // attach remote ip to the request as metadata
             $request->remoteAddress = $conn->getRemoteAddress();
             $this->handleRequest($conn, $request, $bodyBuffer);
             $conn->removeListener('data', array($parser, 'feed'));
             $conn->on('end', function () use($request) {
                 $request->emit('end');
             });
             $conn->on('data', function ($data) use($request) {
                 $request->emit('data', array($data));
             });
             $request->on('pause', function () use($conn) {
                 $conn->emit('pause');
             });
             $request->on('resume', function () use($conn) {
                 $conn->emit('resume');
             });
         });
         $conn->on('data', array($parser, 'feed'));
     });
 }
Пример #3
0
 public function __construct(SocketServerInterface $io)
 {
     $this->io = $io;
     $server = $this;
     $this->io->on('connect', function ($conn) use($server) {
         // TODO: http 1.1 keep-alive
         // TODO: chunked transfer encoding (also for outgoing data)
         // TODO: multipart parsing
         $parser = new RequestHeaderParser();
         $parser->on('headers', function (Request $request, $bodyBuffer) use($server, $conn, $parser) {
             $server->handleRequest($conn, $request, $bodyBuffer);
             $conn->removeListener('data', array($parser, 'feed'));
             $conn->on('data', function ($data) use($request) {
                 $request->emit('data', array($data));
             });
         });
         $conn->on('data', array($parser, 'feed'));
     });
 }
Пример #4
0
 public function testGuzzleRequestParseException()
 {
     $error = null;
     $parser = new RequestHeaderParser();
     $parser->on('headers', $this->expectCallableNever());
     $parser->on('error', function ($message) use(&$error) {
         $error = $message;
     });
     $this->assertSame(1, count($parser->listeners('headers')));
     $this->assertSame(1, count($parser->listeners('error')));
     $parser->feed("\r\n\r\n");
     $this->assertInstanceOf('InvalidArgumentException', $error);
     $this->assertSame('Invalid message', $error->getMessage());
     $this->assertSame(0, count($parser->listeners('headers')));
     $this->assertSame(0, count($parser->listeners('error')));
 }