Skip to content
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

Rename Server to HttpServer to avoid class name collisions and ambiguities #417

Merged
merged 2 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 67 additions & 61 deletions README.md

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions examples/51-server-hello-world.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
return new Response(
200,
array(
Expand All @@ -16,7 +15,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/52-server-count-visitors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

$counter = 0;
$server = new Server(function (ServerRequestInterface $request) use (&$counter) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) use (&$counter) {
return new Response(
200,
array(
Expand All @@ -17,7 +16,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/53-server-whatsmyip.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
$body = "Your IP is: " . $request->getServerParams()['REMOTE_ADDR'];

return new Response(
Expand All @@ -18,7 +17,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/54-server-query-parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
$queryParams = $request->getQueryParams();

$body = 'The query parameter "foo" is not set. Click the following link ';
Expand All @@ -25,7 +24,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/55-server-cookie-handling.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
$key = 'react\php';

if (isset($request->getCookieParams()[$key])) {
Expand All @@ -31,7 +30,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/56-server-sleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop;
use React\Http\Message\Response;
use React\Http\Server;
use React\Promise\Promise;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
return new Promise(function ($resolve, $reject) {
Loop::addTimer(1.5, function() use ($resolve) {
$response = new Response(
Expand All @@ -23,7 +22,7 @@
});
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/57-server-error-handling.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;
use React\Promise\Promise;

require __DIR__ . '/../vendor/autoload.php';

$count = 0;
$server = new Server(function (ServerRequestInterface $request) use (&$count) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) use (&$count) {
return new Promise(function ($resolve, $reject) use (&$count) {
$count++;

Expand All @@ -28,7 +27,7 @@
});
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/58-server-stream-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop;
use React\Http\Message\Response;
use React\Http\Server;
use React\Stream\ThroughStream;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
if ($request->getMethod() !== 'GET' || $request->getUri()->getPath() !== '/') {
return new Response(404);
}
Expand Down Expand Up @@ -39,7 +38,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
7 changes: 3 additions & 4 deletions examples/59-server-json-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
if ($request->getHeaderLine('Content-Type') !== 'application/json') {
return new Response(
415, // Unsupported Media Type
Expand Down Expand Up @@ -53,7 +52,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
9 changes: 4 additions & 5 deletions examples/61-server-hello-world-https.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
return new Response(
200,
array(
Expand All @@ -16,11 +15,11 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new \React\Socket\SecureServer($socket, null, array(
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$socket = new React\Socket\SecureServer($socket, null, array(
'local_cert' => isset($argv[2]) ? $argv[2] : __DIR__ . '/localhost.pem'
));
$server->listen($socket);
$http->listen($socket);

//$socket->on('error', 'printf');

Expand Down
7 changes: 3 additions & 4 deletions examples/62-server-form-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use React\Http\Middleware\RequestBodyBufferMiddleware;
use React\Http\Middleware\RequestBodyParserMiddleware;
use React\Http\Middleware\StreamingRequestMiddleware;
use React\Http\Server;

require __DIR__ . '/../vendor/autoload.php';

Expand Down Expand Up @@ -121,15 +120,15 @@

// Note how this example explicitly uses the advanced `StreamingRequestMiddleware` to apply
// custom request buffering limits below before running our request handler.
$server = new Server(
$http = new React\Http\HttpServer(
new StreamingRequestMiddleware(),
new LimitConcurrentRequestsMiddleware(100), // 100 concurrent buffering handlers, queue otherwise
new RequestBodyBufferMiddleware(8 * 1024 * 1024), // 8 MiB max, ignore body otherwise
new RequestBodyParserMiddleware(100 * 1024, 1), // 1 file with 100 KiB max, reject upload otherwise
$handler
);

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0', null);
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
8 changes: 4 additions & 4 deletions examples/63-server-streaming-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Note how this example uses the advanced `StreamingRequestMiddleware` to allow streaming
// the incoming HTTP request. This very simple example merely counts the size
// of the streaming body, it does not otherwise buffer its contents in memory.
$server = new React\Http\Server(
$http = new React\Http\HttpServer(
new React\Http\Middleware\StreamingRequestMiddleware(),
function (Psr\Http\Message\ServerRequestInterface $request) {
$body = $request->getBody();
Expand Down Expand Up @@ -42,9 +42,9 @@ function (Psr\Http\Message\ServerRequestInterface $request) {
}
);

$server->on('error', 'printf');
$http->on('error', 'printf');

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
10 changes: 4 additions & 6 deletions examples/71-server-http-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
// $ curl -v --proxy http://localhost:8080 http://reactphp.org/

use Psr\Http\Message\RequestInterface;
use React\EventLoop\Factory;
use React\Http\Message\Response;
use React\Http\Server;
use RingCentral\Psr7;

require __DIR__ . '/../vendor/autoload.php';

// Note how this example uses the `Server` without the `StreamingRequestMiddleware`.
// Note how this example uses the `HttpServer` without the `StreamingRequestMiddleware`.
// This means that this proxy buffers the whole request before "processing" it.
// As such, this is store-and-forward proxy. This could also use the advanced
// `StreamingRequestMiddleware` to forward the incoming request as it comes in.
$server = new Server(function (RequestInterface $request) {
$http = new React\Http\HttpServer(function (RequestInterface $request) {
if (strpos($request->getRequestTarget(), '://') === false) {
return new Response(
400,
Expand Down Expand Up @@ -46,7 +44,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
9 changes: 4 additions & 5 deletions examples/72-server-http-connect-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@

use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
use React\Http\Server;
use React\Socket\Connector;
use React\Socket\ConnectionInterface;

require __DIR__ . '/../vendor/autoload.php';

$connector = new Connector();

// Note how this example uses the `Server` without the `StreamingRequestMiddleware`.
// Note how this example uses the `HttpServer` without the `StreamingRequestMiddleware`.
// Unlike the plain HTTP proxy, the CONNECT method does not contain a body
// and we establish an end-to-end connection over the stream object, so this
// doesn't have to store any payload data in memory at all.
$server = new Server(function (ServerRequestInterface $request) use ($connector) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) use ($connector) {
if ($request->getMethod() !== 'CONNECT') {
return new Response(
405,
Expand Down Expand Up @@ -51,7 +50,7 @@ function ($e) {
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
9 changes: 4 additions & 5 deletions examples/81-server-upgrade-echo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop;
use React\Http\Message\Response;
use React\Http\Server;
use React\Stream\ThroughStream;

require __DIR__ . '/../vendor/autoload.php';

// Note how this example uses the `Server` without the `StreamingRequestMiddleware`.
// Note how this example uses the `HttpServer` without the `StreamingRequestMiddleware`.
// The initial incoming request does not contain a body and we upgrade to a
// stream object below.
$server = new Server(function (ServerRequestInterface $request) {
$http = new React\Http\HttpServer(function (ServerRequestInterface $request) {
if ($request->getHeaderLine('Upgrade') !== 'echo' || $request->getProtocolVersion() === '1.0') {
return new Response(
426,
Expand Down Expand Up @@ -57,7 +56,7 @@
);
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$server->listen($socket);
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
$http->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
Loading