@@ -35,8 +35,7 @@ This is an HTTP server which responds with `Hello World` to every request.
3535$loop = React\EventLoop\Factory::create();
3636$socket = new React\Socket\Server(8080, $loop);
3737
38- $http = new React\Http\Server($socket);
39- $http->on('request', function (Request $request, Response $response) {
38+ $http = new React\Http\Server($socket, function (Request $request, Response $response) {
4039 $response->writeHead(200, array('Content-Type' => 'text/plain'));
4140 $response->end("Hello World!\n");
4241});
@@ -51,7 +50,7 @@ See also the [examples](examples).
5150### Server
5251
5352The ` Server ` class is responsible for handling incoming connections and then
54- emit a ` request ` event for each incoming HTTP request .
53+ execute the execute the callback function passed to the constructor .
5554
5655It attaches itself to an instance of ` React\Socket\ServerInterface ` which
5756emits underlying streaming connections in order to then parse incoming data
@@ -76,22 +75,18 @@ $socket = new SecureServer($socket, $loop, array(
7675$http = new React\Http\Server($socket);
7776```
7877
79- For each incoming connection, it emits a ` request ` event with the respective
78+ For each incoming connection, it executes the callback function with the respective
8079[ ` Request ` ] ( #request ) and [ ` Response ` ] ( #response ) objects:
8180
8281``` php
83- $http->on('request' , function (Request $request, Response $response) {
82+ $http = new React\Http\Server($socket , function (Request $request, Response $response) {
8483 $response->writeHead(200, array('Content-Type' => 'text/plain'));
8584 $response->end("Hello World!\n");
8685});
8786```
8887
8988See also [ ` Request ` ] ( #request ) and [ ` Response ` ] ( #response ) for more details.
9089
91- > Note that you SHOULD always listen for the ` request ` event.
92- Failing to do so will result in the server parsing the incoming request,
93- but never sending a response back to the client.
94-
9590Checkout [ Request] ( #request ) for details about the request data body.
9691
9792The ` Server ` supports both HTTP/1.1 and HTTP/1.0 request messages.
@@ -120,7 +115,7 @@ Listen on the `data` event and the `end` event of the [Request](#request)
120115to evaluate the data of the request body:
121116
122117``` php
123- $http->on('request' , function (Request $request, Response $response) {
118+ $http = new React\Http\Server($socket , function (RequestInterface $request, Response $response) {
124119 $contentLength = 0;
125120 $request->on('data', function ($data) use (& $contentLength) {
126121 $contentLength += strlen($data);
@@ -247,7 +242,7 @@ This method is mostly useful in combination with the
247242[ ` expectsContinue() ` ] ( #expectscontinue ) method like this:
248243
249244``` php
250- $http->on('request' , function (Request $request, Response $response) {
245+ $http = new React\Http\Server($socket , function (Request $request, Response $response) {
251246 if ($request->expectsContinue()) {
252247 $response->writeContinue();
253248 }
0 commit comments