Skip to content
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
42 changes: 0 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ mess with most of the low-level details.
* [submit()](#submit)
* [send()](#send)
* [withOptions()](#withoptions)
* [withSender()](#withsender)
* [withBase()](#withbase)
* [withoutBase()](#withoutbase)
* [ResponseInterface](#responseinterface)
* [RequestInterface](#requestinterface)
* [UriInterface](#uriinterface)
* [ResponseException](#responseexception)
* [Advanced](#advanced)
* [Sender](#sender)
* [SOCKS proxy](#socks-proxy)
* [Options](#options)
* [Install](#install)
Expand Down Expand Up @@ -106,11 +104,6 @@ $connector = new \React\Socket\Connector($loop, array(
$browser = new Browser($loop, $connector);
```

Legacy notice: This project previously used different APIs that are now
deprecated, but continue to work unchanged. This legacy API will be removed in
a future version, so it's highly recommended to upgrade to the above API.
See also [`Sender`](#sender).

#### Methods

The `Browser` offers several methods that resemble the HTTP protocol methods:
Expand Down Expand Up @@ -363,22 +356,6 @@ actually returns a *new* [`Browser`](#browser) instance with the [options](#opti

See [options](#options) for more details.

#### withSender()

> [deprecated] The `Sender` is deprecated and will likely be removed in a
future version.

The `withSender(Sender $sender)` method can be used to change the [`Sender`](#sender) instance to use:

```php
$newBrowser = $browser->withSender($sender);
```

Notice that the [`Browser`](#browser) is an immutable object, i.e. the `withSender()` method
actually returns a *new* [`Browser`](#browser) instance with the given [`Sender`](#sender) applied.

See [`Sender`](#sender) for more details.

#### withBase()

The `withBase($baseUri)` method can be used to change the base URI used to
Expand Down Expand Up @@ -457,25 +434,6 @@ The `getResponse()` method can be used to access its underlying [`ResponseIntefa

## Advanced

### Sender

> [deprecated] The `Sender` is deprecated and will likely be removed in a
future version.

The `Sender` is responsible for passing the [`RequestInterface`](#requestinterface) objects to
the underlying [`HttpClient`](https://github.com/reactphp/http-client) library
and keeps track of its transmission and converts its reponses back to [`ResponseInterface`](#responseinterface) objects.

It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage)
and the default [`Connector`](https://github.com/reactphp/socket-client) and [DNS `Resolver`](https://github.com/reactphp/dns).

See also [`Browser::withSender()`](#withsender) for changing the `Sender` instance during runtime.

Legacy notice: The `Sender` class mostly exists in order to abstract changes
on the underlying components away from this package. As such, it offers a number
of legacy APIs that are now deprecated and no longer in active use. These APIs
continue to work unchanged, but will be removed in a future version.

### SOCKS proxy

You can also establish your outgoing connections through a SOCKS proxy server
Expand Down
29 changes: 5 additions & 24 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,13 @@ class Browser
* Instantiate the Browser
*
* @param LoopInterface $loop
* @param ConnectorInterface|Sender|null $connector [optional] Connector to
* use. Should be `null` in order to use default Connector. Passing a
* Sender instance is deprecated and only supported for BC reasons and
* will be removed in future versions.
* @param MessageFactory $messageFactory [internal] Only used internally and
* will be removed in future versions.
* @param ConnectorInterface|null $connector [optional] Connector to use.
* Should be `null` in order to use default Connector.
*/
public function __construct(LoopInterface $loop, $connector = null, MessageFactory $messageFactory = null)
public function __construct(LoopInterface $loop, ConnectorInterface $connector = null)
{
if (!$connector instanceof Sender) {
$connector = Sender::createFromLoop($loop, $connector);
}
if ($messageFactory === null) {
$messageFactory = new MessageFactory();
}
$this->sender = $connector;
$this->messageFactory = $messageFactory;
$this->sender = Sender::createFromLoop($loop, $connector);
$this->messageFactory = new MessageFactory();
}

public function get($url, $headers = array())
Expand Down Expand Up @@ -142,13 +132,4 @@ public function withOptions(array $options)

return $browser;
}

/** @deprecated */
public function withSender(Sender $sender)
{
$browser = clone $this;
$browser->sender = $sender;

return $browser;
}
}
38 changes: 16 additions & 22 deletions src/Io/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@
use React\Stream\ReadableStreamInterface;

/**
* @deprecated as of v1.4.0, see `Browser`
* [Internal] Sends requests and receives responses
*
* The `Sender` is responsible for passing the [`RequestInterface`](#requestinterface) objects to
* the underlying [`HttpClient`](https://github.com/reactphp/http-client) library
* and keeps track of its transmission and converts its reponses back to [`ResponseInterface`](#responseinterface) objects.
*
* It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage)
* and the default [`Connector`](https://github.com/reactphp/socket-client) and [DNS `Resolver`](https://github.com/reactphp/dns).
*
* The `Sender` class mostly exists in order to abstract changes on the underlying
* components away from this package in order to provide backwards and forwards
* compatibility.
*
* @internal You SHOULD NOT rely on this API, it is subject to change without prior notice!
* @see Browser
*/
class Sender
Expand Down Expand Up @@ -44,32 +57,13 @@ public static function createFromLoop(LoopInterface $loop, ConnectorInterface $c
return new self(new HttpClient($loop, $connector));
}

/**
* [deprecated] create sender attached to the given event loop and DNS resolver
*
* @param LoopInterface $loop
* @param \React\Dns\Resolver\Resolver|string $dns DNS resolver instance or IP address
* @return self
* @deprecated as of v1.2.0, see createFromLoop()
* @see self::createFromLoop()
*/
public static function createFromLoopDns(LoopInterface $loop, $dns)
{
return self::createFromLoop($loop, new Connector($loop, array(
'dns' => $dns
)));
}

private $http;

/**
* [deprecated] Instantiate Sender
* [internal] Instantiate Sender
*
* @param HttpClient $http
* @deprecated explicitly calling this constructor is deprecated and it
* will be removed in a future version! Please use the above static
* `create*()` methods instead for future compatibility
* @see self::createFromLoop()
* @internal
*/
public function __construct(HttpClient $http)
{
Expand Down
17 changes: 6 additions & 11 deletions tests/BrowserTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use Clue\React\Buzz\Browser;
use RingCentral\Psr7\Uri;
use Clue\React\Block;
use Clue\React\Buzz\Browser;
use Psr\Http\Message\RequestInterface;
use React\Promise\Promise;
use RingCentral\Psr7\Uri;

class BrowserTest extends TestCase
{
Expand All @@ -16,16 +16,11 @@ public function setUp()
{
$this->loop = $this->getMock('React\EventLoop\LoopInterface');
$this->sender = $this->getMockBuilder('Clue\React\Buzz\Io\Sender')->disableOriginalConstructor()->getMock();
$this->browser = new Browser($this->loop, $this->sender);
}
$this->browser = new Browser($this->loop);

public function testWithSender()
{
$sender = $this->getMockBuilder('Clue\React\Buzz\Io\Sender')->disableOriginalConstructor()->getMock();

$browser = $this->browser->withSender($sender);

$this->assertNotSame($this->browser, $browser);
$ref = new ReflectionProperty($this->browser, 'sender');
$ref->setAccessible(true);
$ref->setValue($this->browser, $this->sender);
}

public function testWithBase()
Expand Down
11 changes: 4 additions & 7 deletions tests/FunctionalBrowserTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

use React\EventLoop\Factory;
use Clue\React\Block;
use Clue\React\Buzz\Browser;
use Clue\React\Buzz\Io\Sender;
use Clue\React\Buzz\Message\ResponseException;
use Clue\React\Block;
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\Http\Response;
use React\Promise\Stream;
use React\Socket\Connector;
Expand Down Expand Up @@ -95,8 +94,7 @@ public function testVerifyPeerEnabledForBadSslRejects()
)
));

$sender = Sender::createFromLoop($this->loop, $connector);
$browser = $this->browser->withSender($sender);
$browser = new Browser($this->loop, $connector);

$this->setExpectedException('RuntimeException');
Block\await($browser->get('https://self-signed.badssl.com/'), $this->loop);
Expand All @@ -115,8 +113,7 @@ public function testVerifyPeerDisabledForBadSslResolves()
)
));

$sender = Sender::createFromLoop($this->loop, $connector);
$browser = $this->browser->withSender($sender);
$browser = new Browser($this->loop, $connector);

Block\await($browser->get('https://self-signed.badssl.com/'), $this->loop);
}
Expand Down