Exemple #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");
         });
     });
 }
Exemple #2
0
 public function parseHeaders($data)
 {
     $request = parent::parseHeaders($data);
     $this->fixHeaderNames($request);
     return $request;
 }
Exemple #3
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);
 }