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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ and the default [`Connector`](https://github.com/reactphp/socket-client) and [DN

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

### DNS

The [`Sender`](#sender) is also resposible for creating the underlying TCP/IP
connection to the remove HTTP server and hence has to orchestrate DNS lookups.
By default, it uses a `Connector` instance which uses Google's public DNS servers
(`8.8.8.8`).

If you need custom DNS settings, you explicitly create a [`Sender`](#sender) instance
with your DNS server address (or `React\Dns\Resolver` instance) like this:

```php
$dns = '127.0.0.1';
$sender = Sender::createFromLoopDns($loop, $dns);
$browser = $browser->withSender($sender);
```

See also [`Browser::withSender()`](#withsender) for more details.

### SOCKS proxy

You can also establish your outgoing connections through a SOCKS proxy server
Expand Down
21 changes: 18 additions & 3 deletions src/Io/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use React\SocketClient\SecureConnector;
use RuntimeException;
use React\SocketClient\ConnectorInterface;
use React\Dns\Resolver\Resolver;

class Sender
{
Expand All @@ -27,10 +28,24 @@ class Sender
*/
public static function createFromLoop(LoopInterface $loop)
{
$dnsResolverFactory = new ResolverFactory();
$resolver = $dnsResolverFactory->createCached('8.8.8.8', $loop);
return self::createFromLoopDns($loop, '8.8.8.8');
}

/**
* create sender attached to the given event loop and DNS resolver
*
* @param LoopInterface $loop
* @param Resolver|string $dns DNS resolver instance or IP address
* @return self
*/
public static function createFromLoopDns(LoopInterface $loop, $dns)
{
if (!($dns instanceof Resolver)) {
$dnsResolverFactory = new ResolverFactory();
$dns = $dnsResolverFactory->createCached($dns, $loop);
}

$connector = new Connector($loop, $resolver);
$connector = new Connector($loop, $dns);

return self::createFromLoopConnectors($loop, $connector);
}
Expand Down