Skip to content

Commit

Permalink
Merge pull request #110 from clue-labs/pause-resume
Browse files Browse the repository at this point in the history
Forward pause/resume from request to connection
  • Loading branch information
WyriHaximus authored Feb 11, 2017
2 parents 441fd2d + 14e82b9 commit fd85e7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function __construct(SocketServerInterface $io)
// attach remote ip to the request as metadata
$request->remoteAddress = $conn->getRemoteAddress();

// forward pause/resume calls to underlying connection
$request->on('pause', array($conn, 'pause'));
$request->on('resume', array($conn, 'resume'));

$that->handleRequest($conn, $request, $bodyBuffer);

$conn->removeListener('data', array($parser, 'feed'));
Expand All @@ -35,12 +39,6 @@ public function __construct(SocketServerInterface $io)
$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');
});
});

$listener = array($parser, 'feed');
Expand Down
28 changes: 28 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ public function testRequestEvent()
$this->assertInstanceOf('React\Http\Response', $responseAssertion);
}

public function testRequestPauseWillbeForwardedToConnection()
{
$server = new Server($this->socket);
$server->on('request', function (Request $request) {
$request->pause();
});

$this->connection->expects($this->once())->method('pause');
$this->socket->emit('connection', array($this->connection));

$data = $this->createGetRequest();
$this->connection->emit('data', array($data));
}

public function testRequestResumeWillbeForwardedToConnection()
{
$server = new Server($this->socket);
$server->on('request', function (Request $request) {
$request->resume();
});

$this->connection->expects($this->once())->method('resume');
$this->socket->emit('connection', array($this->connection));

$data = $this->createGetRequest();
$this->connection->emit('data', array($data));
}

public function testResponseContainsPoweredByHeader()
{
$server = new Server($this->socket);
Expand Down

0 comments on commit fd85e7c

Please sign in to comment.