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

Drop leftover RingCentral PSR-7 dependency, use own PSR-7 implementation #522

Merged
merged 1 commit into from
Mar 26, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/01-client-get-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
6 changes: 3 additions & 3 deletions examples/02-client-concurrent-requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
2 changes: 1 addition & 1 deletion examples/04-client-post-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
2 changes: 1 addition & 1 deletion examples/05-client-put-xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
2 changes: 1 addition & 1 deletion examples/11-client-http-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
2 changes: 1 addition & 1 deletion examples/12-client-socks-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
2 changes: 1 addition & 1 deletion examples/13-client-ssh-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
3 changes: 1 addition & 2 deletions examples/14-client-unix-domain-sockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use React\Http\Browser;
use React\Socket\FixedUriConnector;
use React\Socket\UnixConnector;
use RingCentral\Psr7;

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

Expand All @@ -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;
});
3 changes: 1 addition & 2 deletions examples/21-client-request-streaming-to-stdout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions examples/22-client-stream-upload-from-stdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
});
2 changes: 1 addition & 1 deletion examples/71-server-http-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
});

Expand Down
3 changes: 1 addition & 2 deletions examples/91-client-benchmark-download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Io/ClientRequestStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions tests/Middleware/RequestBodyBufferMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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/',
Expand Down