Ejemplo n.º 1
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)
         $parser = new RequestParser();
         $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'));
         $parser->on('expects_continue', function () use($conn) {
             $conn->write("HTTP/1.1 100 Continue\r\n\r\n");
         });
     });
 }
Ejemplo n.º 2
0
 public function testBodyShouldNotOverflowHeader()
 {
     $error = null;
     $parser = new RequestParser();
     $parser->on('headers', $this->expectCallableOnce());
     $parser->on('error', function ($message) use(&$error) {
         $error = $message;
     });
     $data = str_repeat('A', 4097);
     $parser->feed($this->createAdvancedPostRequest() . $data);
     $this->assertNull($error);
 }