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

Update Socket dependency and support Unix Domain Sockets (UDS) again #84

Merged
merged 1 commit into from
Sep 17, 2017
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mess with most of the low-level details.
* [ResponseException](#responseexception)
* [Advanced](#advanced)
* [SOCKS proxy](#socks-proxy)
* [Unix domain sockets](#unix-domain-sockets)
* [Options](#options)
* [Install](#install)
* [Tests](#tests)
Expand Down Expand Up @@ -444,6 +445,31 @@ This works for both plain HTTP and SSL encrypted HTTPS requests.

See also the [SOCKS example](examples/11-socks-proxy.php).

### Unix domain sockets

By default, this library supports transport over plaintext TCP/IP and secure
TLS connections for the `http://` and `https://` URI schemes respectively.
This library also supports Unix domain sockets (UDS) when explicitly configured.

In order to use a UDS path, you have to explicitly configure the connector to
override the destination URI so that the hostname given in the request URI will
no longer be used to establish the connection:

```php
$connector = new \React\Socket\FixedUriConnector(
'unix:///var/run/docker.sock',
new \React\Socket\UnixConnector($loop)
);

$browser = new Browser($loop, $connector);

$client->get('http://localhost/info')->then(function (ResponseInterface $response) {
var_dump($response->getHeaders(), (string)$response->getBody());
});
```

See also the [Unix Domain Sockets (UDS) example](examples/12-unix-domain-sockets.php).

### Options

The [`Browser`](#browser) class exposes several options for the handling of
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
"php": ">=5.4",
"psr/http-message": "^1.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/http-client": "^0.5",
"react/http-client": "^0.5.6",
"react/promise": "^2.2.1",
"react/promise-stream": "^0.1.1",
"react/socket": "^1.0 || ^0.8",
"react/stream": "^1.0 || ^0.7 || ^0.6 || ^0.5 || ^0.4.6",
"react/socket": "^1.0 || ^0.8.4",
"react/stream": "^1.0 || ^0.7",
"ringcentral/psr7": "^1.2"
},
"require-dev": {
"clue/block-react": "^1.0",
"clue/socks-react": "^0.8 || ^0.7",
"clue/socks-react": "^0.8",
"phpunit/phpunit": "^4.5",
"react/http": "^0.7.2"
}
Expand Down
27 changes: 27 additions & 0 deletions examples/12-unix-domain-sockets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Clue\React\Buzz\Browser;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\FixedUriConnector;
use React\Socket\UnixConnector;
use RingCentral\Psr7;

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

$loop = LoopFactory::create();

// create a Browser object that uses the a Unix Domain Sockets (UDS) path for all requests
$connector = new FixedUriConnector(
'unix:///var/run/docker.sock',
new UnixConnector($loop)
);

$browser = new Browser($loop, $connector);

// demo fetching HTTP headers (or bail out otherwise)
$browser->get('http://localhost/info')->then(function (ResponseInterface $response) {
echo Psr7\str($response);
}, 'printf');

$loop->run();