Skip to content

Commit

Permalink
Merge remote-tracking branch 'beaucollins/http-response-emit-end'
Browse files Browse the repository at this point in the history
* beaucollins/http-response-emit-end:
  React\Http\Response emits 'end' event when stream is ended
  • Loading branch information
igorw committed Dec 19, 2012
2 parents 6c2b060 + a7a6184 commit 4ce8583
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/React/Http/Response.php
Expand Up @@ -98,7 +98,7 @@ public function end($data = null)
$this->conn->write("0\r\n\r\n");
}

$this->emit('close');
$this->emit('end');
$this->removeAllListeners();
$this->conn->end();
}
Expand Down
13 changes: 13 additions & 0 deletions tests/React/Tests/Http/ResponseTest.php
Expand Up @@ -71,6 +71,19 @@ public function testResponseBodyShouldBeChunkedCorrectly()
$response->write("World\n");
$response->end();
}

public function testResponseShouldEmitEndOnStreamEnd(){
$conn = $this->getMock('React\Socket\ConnectionInterface');
$response = new Response( $conn );
$ended = false;
$response->on( 'end', function() use (&$ended){
$ended = true;
});
$response->end();

$this->assertTrue( $ended, "Response did not emit 'end'" );

}

/** @test */
public function writeContinueShouldSendContinueLineBeforeRealHeaders()
Expand Down

0 comments on commit 4ce8583

Please sign in to comment.