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

Add new Uri class for new PSR-7 implementation #521

Merged
merged 2 commits 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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ multiple concurrent HTTP requests without blocking.
* [xml()](#xml)
* [Request](#request-1)
* [ServerRequest](#serverrequest)
* [Uri](#uri)
* [ResponseException](#responseexception)
* [React\Http\Middleware](#reacthttpmiddleware)
* [StreamingRequestMiddleware](#streamingrequestmiddleware)
Expand Down Expand Up @@ -2664,6 +2665,18 @@ application reacts to certain HTTP requests.
> Internally, this implementation builds on top of a base class which is
considered an implementation detail that may change in the future.

#### Uri

The `React\Http\Message\Uri` class can be used to
respresent a URI (or URL).

This class implements the
[PSR-7 `UriInterface`](https://www.php-fig.org/psr/psr-7/#35-psrhttpmessageuriinterface).

This is mostly used internally to represent the URI of each HTTP request
message for our HTTP client and server implementations. Likewise, you may
also use this class with other HTTP implementations and for tests.

#### ResponseException

The `React\Http\Message\ResponseException` is an `Exception` sub-class that will be used to reject
Expand Down
4 changes: 2 additions & 2 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace React\Http;

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\Message\Uri;
use React\Promise\PromiseInterface;
use React\Socket\ConnectorInterface;
use React\Stream\ReadableStreamInterface;
Expand Down Expand Up @@ -834,7 +834,7 @@ private function requestMayBeStreaming($method, $url, array $headers = array(),
{
if ($this->baseUrl !== null) {
// ensure we're actually below the base URL
$url = Uri::resolve($this->baseUrl, $url);
$url = Uri::resolve($this->baseUrl, new Uri($url));
}

foreach ($this->defaultHeaders as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Io/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use RingCentral\Psr7\Uri;
use React\Http\Message\Uri;

/**
* [Internal] Abstract HTTP request base class (PSR-7)
Expand Down
4 changes: 2 additions & 2 deletions 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\Message\Uri;
use React\Promise\Deferred;
use React\Promise\Promise;
use React\Promise\PromiseInterface;
use React\Stream\ReadableStreamInterface;
use RingCentral\Psr7\Uri;

/**
* @internal
Expand Down Expand Up @@ -264,7 +264,7 @@ public function onResponse(ResponseInterface $response, RequestInterface $reques
private function onResponseRedirect(ResponseInterface $response, RequestInterface $request, Deferred $deferred, ClientRequestState $state)
{
// resolve location relative to last request URI
$location = Uri::resolve($request->getUri(), $response->getHeaderLine('Location'));
$location = Uri::resolve($request->getUri(), new Uri($response->getHeaderLine('Location')));

$request = $this->makeRedirectRequest($request, $location, $response->getStatusCode());
$this->progress('redirect', array($request));
Expand Down