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

Removed obsolete RingCentral/Psr7 dependency #485

Closed
wants to merge 1 commit into from
Closed
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
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/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 React\Http\Psr7\str($response);
}, 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 React\Http\Psr7\str($response);
}, 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 React\Http\Psr7\str($response);
}, 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 React\Http\Psr7\str($response);
}, 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' . PHP_EOL . React\Http\Psr7\str($response));

$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(), $in)->then(function (ResponseInterface $response) {
echo 'Received' . PHP_EOL . Psr7\str($response);
echo 'Received' . PHP_EOL . React\Http\Psr7\str($response);
}, 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)
React\Http\Psr7\str($outgoing)
);
});

Expand Down
2 changes: 1 addition & 1 deletion examples/91-client-benchmark-download.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

$client->requestStreaming('GET', $url)->then(function (ResponseInterface $response) {
echo 'Headers received' . PHP_EOL;
echo RingCentral\Psr7\str($response);
echo React\Http\Psr7\str($response);

$stream = $response->getBody();
assert($stream instanceof ReadableStreamInterface);
Expand Down
4 changes: 2 additions & 2 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace React\Http;

use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use RingCentral\Psr7\Uri;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\Http\Io\Sender;
use React\Http\Io\Transaction;
use React\Http\Message\Request;
use React\Http\Psr7\Uri;
use React\Promise\PromiseInterface;
use React\Socket\ConnectorInterface;
use React\Stream\ReadableStreamInterface;
use InvalidArgumentException;

/**
* @final This class is final and shouldn't be extended as it is likely to be marked final in a future release.
Expand Down
5 changes: 2 additions & 3 deletions src/Io/ClientRequestStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use Evenement\EventEmitter;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use React\Http\Message\Response;
use React\Http\Psr7\Utils;
use React\Promise;
use React\Socket\ConnectionInterface;
use React\Socket\ConnectorInterface;
use React\Stream\WritableStreamInterface;
use RingCentral\Psr7 as gPsr;

/**
* @event response
Expand Down Expand Up @@ -156,7 +155,7 @@ public function handleData($data)
// buffer until double CRLF (or double LF for compatibility with legacy servers)
if (false !== strpos($this->buffer, "\r\n\r\n") || false !== strpos($this->buffer, "\n\n")) {
try {
$response = gPsr\parse_response($this->buffer);
$response = Utils::parseResponse($this->buffer);
$bodyChunk = (string) $response->getBody();
} catch (\InvalidArgumentException $exception) {
$this->closeError($exception);
Expand Down
2 changes: 1 addition & 1 deletion src/Io/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use React\EventLoop\LoopInterface;
use React\Http\Message\Response;
use React\Http\Message\ResponseException;
use React\Http\Psr7\Uri;
use React\Promise\Deferred;
use React\Promise\Promise;
use React\Promise\PromiseInterface;
use React\Stream\ReadableStreamInterface;
use RingCentral\Psr7\Uri;

/**
* @internal
Expand Down
6 changes: 3 additions & 3 deletions src/Message/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Psr\Http\Message\UriInterface;
use React\Http\Io\BufferedBody;
use React\Http\Io\ReadableBodyStream;
use React\Http\Psr7\Request as BaseRequest;
use React\Stream\ReadableStreamInterface;
use RingCentral\Psr7\Request as BaseRequest;

/**
* Respresents an outgoing HTTP request message.
* Represents an outgoing HTTP request message.
*
* This class implements the
* [PSR-7 `RequestInterface`](https://www.php-fig.org/psr/psr-7/#32-psrhttpmessagerequestinterface)
Expand All @@ -28,7 +28,7 @@
*
* @see RequestInterface
*/
final class Request extends BaseRequest implements RequestInterface
final class Request extends BaseRequest
{
/**
* @param string $method HTTP method for the request.
Expand Down
2 changes: 1 addition & 1 deletion src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Psr\Http\Message\StreamInterface;
use React\Http\Io\BufferedBody;
use React\Http\Io\HttpBodyStream;
use React\Http\Psr7\Response as Psr7Response;
use React\Stream\ReadableStreamInterface;
use RingCentral\Psr7\Response as Psr7Response;

/**
* Represents an outgoing server response message.
Expand Down
4 changes: 2 additions & 2 deletions src/Message/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Psr\Http\Message\UriInterface;
use React\Http\Io\BufferedBody;
use React\Http\Io\HttpBodyStream;
use React\Http\Psr7\Request as BaseRequest;
use React\Stream\ReadableStreamInterface;
use RingCentral\Psr7\Request as BaseRequest;

/**
* Respresents an incoming server request message.
* Represents an incoming server request message.
*
* This class implements the
* [PSR-7 `ServerRequestInterface`](https://www.php-fig.org/psr/psr-7/#321-psrhttpmessageserverrequestinterface)
Expand Down
142 changes: 142 additions & 0 deletions src/Psr7/BufferStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace React\Http\Psr7;

use Psr\Http\Message\StreamInterface;

/**
* @internal
*/
class BufferStream implements StreamInterface
{
/** @var int */
private $hwm;

/** @var string */
private $buffer = '';

/**
* @param int $hwm High water mark, representing the preferred maximum
* buffer size. If the size of the buffer exceeds the high
* water mark, then calls to write will continue to succeed
* but will return 0 to inform writers to slow down
* until the buffer has been drained by reading from it.
*/
public function __construct($hwm = 16384)
{
$this->hwm = $hwm;
}

public function __toString()
{
return $this->getContents();
}

public function getContents()
{
$buffer = $this->buffer;
$this->buffer = '';

return $buffer;
}

public function close()
{
$this->buffer = '';
}

public function detach()
{
$this->close();

return null;
}

public function getSize()
{
return strlen($this->buffer);
}

public function isReadable()
{
return true;
}

public function isWritable()
{
return true;
}

public function isSeekable()
{
return false;
}

public function rewind()
{
$this->seek(0);
}

public function seek($offset, $whence = SEEK_SET)
{
throw new \RuntimeException('Cannot seek a BufferStream');
}

public function eof()
{
return $this->buffer === '';
}

public function tell()
{
throw new \RuntimeException('Cannot determine the position of a BufferStream');
}

/**
* Reads data from the buffer.
*/
public function read($length)
{
$currentLength = strlen($this->buffer);

if ($length >= $currentLength) {
// No need to slice the buffer because we don't have enough data.
$result = $this->buffer;
$this->buffer = '';
} else {
// Slice up the result to provide a subset of the buffer.
$result = substr($this->buffer, 0, $length);
$this->buffer = substr($this->buffer, $length);
}

return $result;
}

/**
* Writes data to the buffer.
*/
public function write($string)
{
$this->buffer .= $string;

if (strlen($this->buffer) >= $this->hwm) {
return 0;
}

return strlen($string);
}

/**
* {@inheritdoc}
*
* @return mixed
*/
public function getMetadata($key = null)
{
if ($key === 'hwm') {
return $this->hwm;
}

return $key ? null : array();
}
}
Loading