Skip to content

Commit

Permalink
Merge pull request #84 from clue-labs/unix
Browse files Browse the repository at this point in the history
Update Socket dependency and support Unix Domain Sockets (UDS) again
  • Loading branch information
clue authored Sep 17, 2017
2 parents c05a50b + 068395f commit 332fd03
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
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();

0 comments on commit 332fd03

Please sign in to comment.