From 30c802c9db77d90dc0d6ef43d9a60573863a0969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 23 Mar 2024 17:42:14 +0100 Subject: [PATCH] Drop leftover RingCentral PSR-7 dependency, use own PSR-7 implementation --- composer.json | 3 +-- examples/01-client-get-request.php | 2 +- examples/02-client-concurrent-requests.php | 6 +++--- examples/04-client-post-json.php | 2 +- examples/05-client-put-xml.php | 2 +- examples/11-client-http-proxy.php | 2 +- examples/12-client-socks-proxy.php | 2 +- examples/13-client-ssh-proxy.php | 2 +- examples/14-client-unix-domain-sockets.php | 3 +-- examples/21-client-request-streaming-to-stdout.php | 3 +-- examples/22-client-stream-upload-from-stdin.php | 3 +-- examples/71-server-http-proxy.php | 2 +- examples/91-client-benchmark-download.php | 3 +-- src/Io/ClientRequestStream.php | 3 ++- tests/Middleware/RequestBodyBufferMiddlewareTest.php | 5 ++--- 15 files changed, 19 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 5198470e..23783c0c 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,7 @@ "react/event-loop": "^1.2", "react/promise": "^3 || ^2.3 || ^1.2.1", "react/socket": "^1.12", - "react/stream": "^1.2", - "ringcentral/psr7": "^1.2" + "react/stream": "^1.2" }, "require-dev": { "clue/http-proxy-react": "^1.8", diff --git a/examples/01-client-get-request.php b/examples/01-client-get-request.php index 34a79bbb..278f6597 100644 --- a/examples/01-client-get-request.php +++ b/examples/01-client-get-request.php @@ -8,7 +8,7 @@ $client = new Browser(); $client->get('http://google.com/')->then(function (ResponseInterface $response) { - var_dump($response->getHeaders(), (string)$response->getBody()); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/02-client-concurrent-requests.php b/examples/02-client-concurrent-requests.php index 7b1b77a0..e372515c 100644 --- a/examples/02-client-concurrent-requests.php +++ b/examples/02-client-concurrent-requests.php @@ -8,19 +8,19 @@ $client = new Browser(); $client->head('http://www.github.com/clue/http-react')->then(function (ResponseInterface $response) { - var_dump($response->getHeaders(), (string)$response->getBody()); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $client->get('http://google.com/')->then(function (ResponseInterface $response) { - var_dump($response->getHeaders(), (string)$response->getBody()); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $client->get('http://www.lueck.tv/psocksd')->then(function (ResponseInterface $response) { - var_dump($response->getHeaders(), (string)$response->getBody()); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/04-client-post-json.php b/examples/04-client-post-json.php index 477c3426..18fa596d 100644 --- a/examples/04-client-post-json.php +++ b/examples/04-client-post-json.php @@ -22,7 +22,7 @@ ), json_encode($data) )->then(function (ResponseInterface $response) { - echo (string)$response->getBody(); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/05-client-put-xml.php b/examples/05-client-put-xml.php index 6055363a..10ee46fc 100644 --- a/examples/05-client-put-xml.php +++ b/examples/05-client-put-xml.php @@ -19,7 +19,7 @@ ), $xml->asXML() )->then(function (ResponseInterface $response) { - echo (string)$response->getBody(); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/11-client-http-proxy.php b/examples/11-client-http-proxy.php index f450fbc2..ec7fc2b6 100644 --- a/examples/11-client-http-proxy.php +++ b/examples/11-client-http-proxy.php @@ -25,7 +25,7 @@ // demo fetching HTTP headers (or bail out otherwise) $browser->get('https://www.google.com/')->then(function (ResponseInterface $response) { - echo RingCentral\Psr7\str($response); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/12-client-socks-proxy.php b/examples/12-client-socks-proxy.php index ecedf242..8c525509 100644 --- a/examples/12-client-socks-proxy.php +++ b/examples/12-client-socks-proxy.php @@ -25,7 +25,7 @@ // demo fetching HTTP headers (or bail out otherwise) $browser->get('https://www.google.com/')->then(function (ResponseInterface $response) { - echo RingCentral\Psr7\str($response); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/13-client-ssh-proxy.php b/examples/13-client-ssh-proxy.php index 64d0c282..93e6e256 100644 --- a/examples/13-client-ssh-proxy.php +++ b/examples/13-client-ssh-proxy.php @@ -21,7 +21,7 @@ // demo fetching HTTP headers (or bail out otherwise) $browser->get('https://www.google.com/')->then(function (ResponseInterface $response) { - echo RingCentral\Psr7\str($response); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/14-client-unix-domain-sockets.php b/examples/14-client-unix-domain-sockets.php index e9718141..5af0394d 100644 --- a/examples/14-client-unix-domain-sockets.php +++ b/examples/14-client-unix-domain-sockets.php @@ -4,7 +4,6 @@ use React\Http\Browser; use React\Socket\FixedUriConnector; use React\Socket\UnixConnector; -use RingCentral\Psr7; require __DIR__ . '/../vendor/autoload.php'; @@ -18,7 +17,7 @@ // demo fetching HTTP headers (or bail out otherwise) $browser->get('http://localhost/info')->then(function (ResponseInterface $response) { - echo Psr7\str($response); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/21-client-request-streaming-to-stdout.php b/examples/21-client-request-streaming-to-stdout.php index 2f24d035..b3cbbe39 100644 --- a/examples/21-client-request-streaming-to-stdout.php +++ b/examples/21-client-request-streaming-to-stdout.php @@ -4,7 +4,6 @@ use Psr\Http\Message\ResponseInterface; use React\Stream\ReadableStreamInterface; use React\Stream\WritableResourceStream; -use RingCentral\Psr7; require __DIR__ . '/../vendor/autoload.php'; @@ -22,7 +21,7 @@ $info->write('Requesting ' . $url . '…' . PHP_EOL); $client->requestStreaming('GET', $url)->then(function (ResponseInterface $response) use ($info, $out) { - $info->write('Received' . PHP_EOL . Psr7\str($response)); + $info->write('Received ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . PHP_EOL); $body = $response->getBody(); assert($body instanceof ReadableStreamInterface); diff --git a/examples/22-client-stream-upload-from-stdin.php b/examples/22-client-stream-upload-from-stdin.php index f29b08ab..f0a68c5f 100644 --- a/examples/22-client-stream-upload-from-stdin.php +++ b/examples/22-client-stream-upload-from-stdin.php @@ -3,7 +3,6 @@ use Psr\Http\Message\ResponseInterface; use React\Http\Browser; use React\Stream\ReadableResourceStream; -use RingCentral\Psr7; require __DIR__ . '/../vendor/autoload.php'; @@ -20,7 +19,7 @@ echo 'Sending STDIN as POST to ' . $url . '…' . PHP_EOL; $client->post($url, array('Content-Type' => 'text/plain'), $in)->then(function (ResponseInterface $response) { - echo 'Received' . PHP_EOL . Psr7\str($response); + echo (string) $response->getBody(); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); diff --git a/examples/71-server-http-proxy.php b/examples/71-server-http-proxy.php index cf63c4ae..de9fa10b 100644 --- a/examples/71-server-http-proxy.php +++ b/examples/71-server-http-proxy.php @@ -28,7 +28,7 @@ // left up as an exercise: use an HTTP client to send the outgoing request // and forward the incoming response to the original client request return React\Http\Message\Response::plaintext( - RingCentral\Psr7\str($outgoing) + $outgoing->getMethod() . ' ' . $outgoing->getRequestTarget() . ' HTTP/' . $outgoing->getProtocolVersion() . "\r\n\r\n" . (string) $outgoing->getBody() ); }); diff --git a/examples/91-client-benchmark-download.php b/examples/91-client-benchmark-download.php index 44e99087..712d9f10 100644 --- a/examples/91-client-benchmark-download.php +++ b/examples/91-client-benchmark-download.php @@ -29,8 +29,7 @@ echo 'Requesting ' . $url . '…' . PHP_EOL; $client->requestStreaming('GET', $url)->then(function (ResponseInterface $response) { - echo 'Headers received' . PHP_EOL; - echo RingCentral\Psr7\str($response); + echo 'Received ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . PHP_EOL; $stream = $response->getBody(); assert($stream instanceof ReadableStreamInterface); diff --git a/src/Io/ClientRequestStream.php b/src/Io/ClientRequestStream.php index 25c96ea8..12c15caf 100644 --- a/src/Io/ClientRequestStream.php +++ b/src/Io/ClientRequestStream.php @@ -277,7 +277,8 @@ public function close() */ public function hasMessageKeepAliveEnabled(MessageInterface $message) { - $connectionOptions = \RingCentral\Psr7\normalize_header(\strtolower($message->getHeaderLine('Connection'))); + // @link https://www.rfc-editor.org/rfc/rfc9110#section-7.6.1 + $connectionOptions = \array_map('trim', \explode(',', \strtolower($message->getHeaderLine('Connection')))); if (\in_array('close', $connectionOptions, true)) { return false; diff --git a/tests/Middleware/RequestBodyBufferMiddlewareTest.php b/tests/Middleware/RequestBodyBufferMiddlewareTest.php index fd818a8c..40c23378 100644 --- a/tests/Middleware/RequestBodyBufferMiddlewareTest.php +++ b/tests/Middleware/RequestBodyBufferMiddlewareTest.php @@ -4,13 +4,13 @@ use Psr\Http\Message\ServerRequestInterface; use React\EventLoop\Loop; +use React\Http\Io\BufferedBody; use React\Http\Io\HttpBodyStream; use React\Http\Message\Response; use React\Http\Message\ServerRequest; use React\Http\Middleware\RequestBodyBufferMiddleware; use React\Stream\ThroughStream; use React\Tests\Http\TestCase; -use RingCentral\Psr7\BufferStream; final class RequestBodyBufferMiddlewareTest extends TestCase { @@ -45,8 +45,7 @@ public function testAlreadyBufferedResolvesImmediately() { $size = 1024; $body = str_repeat('x', $size); - $stream = new BufferStream(1024); - $stream->write($body); + $stream = new BufferedBody($body); $serverRequest = new ServerRequest( 'GET', 'https://example.com/',