Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 166
Automatically close response stream once client connection closes#188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -16,6 +16,7 @@ | ||
| use React\Promise\Promise; | ||
| use React\Promise\PromiseInterface; | ||
| use React\Promise\Stream; | ||
| use React\Stream\ThroughStream; | ||
| class FunctionalServerTest extends TestCase | ||
| { | ||
| @@ -351,6 +352,100 @@ public function testSecureHttpsOnHttpStandardPortReturnsUriWithPort() | ||
| $socket->close(); | ||
| } | ||
| public function testClosedStreamFromRequestHandlerWillSendEmptyBody() | ||
| { | ||
| $loop = Factory::create(); | ||
| $socket = new Socket(0, $loop); | ||
| $connector = new Connector($loop); | ||
| $stream = new ThroughStream(); | ||
| $stream->close(); | ||
| $server = new Server($socket, function (RequestInterface $request) use ($stream) { | ||
| return new Response(200, array(), $stream); | ||
| }); | ||
| $result = $connector->connect($socket->getAddress())->then(function (ConnectionInterface $conn) use ($loop) { | ||
| $conn->write("GET / HTTP/1.0\r\n\r\n"); | ||
| return Stream\buffer($conn); | ||
| }); | ||
| $response = Block\await($result, $loop, 1.0); | ||
| $this->assertStringStartsWith("HTTP/1.0 200 OK", $response); | ||
| $this->assertStringEndsWith("\r\n\r\n", $response); | ||
| $socket->close(); | ||
| } | ||
| public function testStreamFromRequestHandlerWillBeClosedIfConnectionClosesWhileSendingBody() | ||
| { | ||
| $loop = Factory::create(); | ||
| $socket = new Socket(0, $loop); | ||
| $connector = new Connector($loop); | ||
| $stream = new ThroughStream(); | ||
| $stream->on('close', $this->expectCallableOnce()); | ||
| $server = new Server($socket, function (RequestInterface $request) use ($stream) { | ||
| return new Response(200, array(), $stream); | ||
| }); | ||
| $result = $connector->connect($socket->getAddress())->then(function (ConnectionInterface $conn) use ($loop) { | ||
| $conn->write("GET / HTTP/1.0\r\nContent-Length: 100\r\n\r\n"); | ||
| $loop->addTimer(0.1, function() use ($conn) { | ||
| $conn->end(); | ||
| }); | ||
| return Stream\buffer($conn); | ||
| }); | ||
| $response = Block\await($result, $loop, 1.0); | ||
| $this->assertStringStartsWith("HTTP/1.0 200 OK", $response); | ||
| $this->assertStringEndsWith("\r\n\r\n", $response); | ||
| $socket->close(); | ||
| } | ||
| public function testStreamFromRequestHandlerWillBeClosedIfConnectionClosesButWillOnlyBeDetectedOnNextWrite() | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test also fails: https://travis-ci.org/reactphp/http/jobs/235196355#L228 MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed tests by increasing test timeouts | ||
| { | ||
| $loop = Factory::create(); | ||
| $socket = new Socket(0, $loop); | ||
| $connector = new Connector($loop); | ||
| $stream = new ThroughStream(); | ||
| $stream->on('close', $this->expectCallableOnce()); | ||
| $server = new Server($socket, function (RequestInterface $request) use ($stream) { | ||
| return new Response(200, array(), $stream); | ||
| }); | ||
| $result = $connector->connect($socket->getAddress())->then(function (ConnectionInterface $conn) use ($loop) { | ||
| $conn->write("GET / HTTP/1.0\r\n\r\n"); | ||
| $loop->addTimer(0.1, function() use ($conn) { | ||
| $conn->end(); | ||
| }); | ||
| return Stream\buffer($conn); | ||
| }); | ||
| $response = Block\await($result, $loop, 1.0); | ||
| $stream->write('nope'); | ||
| Block\sleep(0.1, $loop); | ||
| $stream->write('nope'); | ||
| Block\sleep(0.1, $loop); | ||
| $this->assertStringStartsWith("HTTP/1.0 200 OK", $response); | ||
| $this->assertStringEndsWith("\r\n\r\n", $response); | ||
| $socket->close(); | ||
| } | ||
| } | ||
| function noScheme($uri) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test fails: https://travis-ci.org/reactphp/http/jobs/235196355#L223
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed tests by increasing test timeouts