Skip to content

Commit 2538e61

Browse files
committed
Import clue/reactphp-buzz v2.9.0
Change namespace from `Clue\React\Buzz` to `React\Http` and update all tests with merged namespaces. See https://github.com/clue/reactphp-buzz for original repo.
1 parent b39f484 commit 2538e61

32 files changed

Lines changed: 6291 additions & 45 deletions

LICENSE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Christian Lück
14
Copyright (c) 2012 Igor Wiedler, Chris Boden
25

36
Permission is hereby granted, free of charge, to any person obtaining a copy

README.md

Lines changed: 1326 additions & 2 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
"license": "MIT",
66
"require": {
77
"php": ">=5.3.0",
8-
"ringcentral/psr7": "^1.2",
9-
"react/socket": "^1.0 || ^0.8.3",
10-
"react/stream": "^1.0 || ^0.7.1",
11-
"react/promise": "^2.3 || ^1.2.1",
128
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
13-
"react/promise-stream": "^1.1"
9+
"psr/http-message": "^1.0",
10+
"react/event-loop": "^1.0 || ^0.5",
11+
"react/http-client": "^0.5.10",
12+
"react/promise": "^2.3 || ^1.2.1",
13+
"react/promise-stream": "^1.1",
14+
"react/socket": "^1.1",
15+
"react/stream": "^1.0 || ^0.7.5",
16+
"ringcentral/psr7": "^1.2"
1417
},
1518
"require-dev": {
1619
"clue/block-react": "^1.1",
20+
"clue/http-proxy-react": "^1.3",
21+
"clue/reactphp-ssh-proxy": "^1.0",
22+
"clue/socks-react": "^1.0",
1723
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35"
1824
},
1925
"autoload": {

examples/01-google.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use React\Http\Browser;
4+
use Psr\Http\Message\ResponseInterface;
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
$loop = React\EventLoop\Factory::create();
9+
$client = new Browser($loop);
10+
11+
$client->get('http://google.com/')->then(function (ResponseInterface $response) {
12+
var_dump($response->getHeaders(), (string)$response->getBody());
13+
});
14+
15+
$loop->run();

examples/02-concurrent.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use React\Http\Browser;
4+
use Psr\Http\Message\ResponseInterface;
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
$loop = React\EventLoop\Factory::create();
9+
$client = new Browser($loop);
10+
11+
$client->head('http://www.github.com/clue/http-react')->then(function (ResponseInterface $response) {
12+
var_dump($response->getHeaders(), (string)$response->getBody());
13+
});
14+
15+
$client->get('http://google.com/')->then(function (ResponseInterface $response) {
16+
var_dump($response->getHeaders(), (string)$response->getBody());
17+
});
18+
19+
$client->get('http://www.lueck.tv/psocksd')->then(function (ResponseInterface $response) {
20+
var_dump($response->getHeaders(), (string)$response->getBody());
21+
});
22+
23+
$loop->run();

examples/03-any.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
// concurrently request a number of URLs.
4+
// return immediately once the first is completed, cancel all others.
5+
6+
use React\Http\Browser;
7+
use Psr\Http\Message\ResponseInterface;
8+
9+
require __DIR__ . '/../vendor/autoload.php';
10+
11+
$loop = React\EventLoop\Factory::create();
12+
$client = new Browser($loop);
13+
14+
$promises = array(
15+
$client->head('http://www.github.com/clue/http-react'),
16+
$client->get('https://httpbin.org/'),
17+
$client->get('https://google.com'),
18+
$client->get('http://www.lueck.tv/psocksd'),
19+
$client->get('http://www.httpbin.org/absolute-redirect/5')
20+
);
21+
22+
React\Promise\any($promises)->then(function (ResponseInterface $response) use ($promises) {
23+
// first response arrived => cancel all other pending requests
24+
foreach ($promises as $promise) {
25+
$promise->cancel();
26+
}
27+
28+
var_dump($response->getHeaders());
29+
echo PHP_EOL . $response->getBody();
30+
});
31+
32+
$loop->run();

examples/04-post-json.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use React\Http\Browser;
4+
use Psr\Http\Message\ResponseInterface;
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
$loop = React\EventLoop\Factory::create();
9+
$client = new Browser($loop);
10+
11+
$data = array(
12+
'name' => array(
13+
'first' => 'Alice',
14+
'name' => 'Smith'
15+
),
16+
'email' => 'alice@example.com'
17+
);
18+
19+
$client->post(
20+
'https://httpbin.org/post',
21+
array(
22+
'Content-Type' => 'application/json'
23+
),
24+
json_encode($data)
25+
)->then(function (ResponseInterface $response) {
26+
echo (string)$response->getBody();
27+
}, 'printf');
28+
29+
$loop->run();

examples/05-put-xml.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use React\Http\Browser;
4+
use Psr\Http\Message\ResponseInterface;
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
$loop = React\EventLoop\Factory::create();
9+
$client = new Browser($loop);
10+
11+
$xml = new SimpleXMLElement('<users></users>');
12+
$child = $xml->addChild('user');
13+
$child->alias = 'clue';
14+
$child->name = 'Christian Lück';
15+
16+
$client->put(
17+
'https://httpbin.org/put',
18+
array(
19+
'Content-Type' => 'text/xml'
20+
),
21+
$xml->asXML()
22+
)->then(function (ResponseInterface $response) {
23+
echo (string)$response->getBody();
24+
}, 'printf');
25+
26+
$loop->run();

examples/11-http-proxy.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use React\Http\Browser;
4+
use Clue\React\HttpProxy\ProxyConnector as HttpConnectClient;
5+
use Psr\Http\Message\ResponseInterface;
6+
use React\EventLoop\Factory as LoopFactory;
7+
use React\Socket\Connector;
8+
9+
require __DIR__ . '/../vendor/autoload.php';
10+
11+
$loop = LoopFactory::create();
12+
13+
// create a new HTTP CONNECT proxy client which connects to a HTTP CONNECT proxy server listening on localhost:8080
14+
// not already running a HTTP CONNECT proxy server? Try LeProxy.org!
15+
$proxy = new HttpConnectClient('127.0.0.1:8080', new Connector($loop));
16+
17+
// create a Browser object that uses the HTTP CONNECT proxy client for connections
18+
$connector = new Connector($loop, array(
19+
'tcp' => $proxy,
20+
'dns' => false
21+
));
22+
$browser = new Browser($loop, $connector);
23+
24+
// demo fetching HTTP headers (or bail out otherwise)
25+
$browser->get('https://www.google.com/')->then(function (ResponseInterface $response) {
26+
echo RingCentral\Psr7\str($response);
27+
}, 'printf');
28+
29+
$loop->run();

examples/12-socks-proxy.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use React\Http\Browser;
4+
use Clue\React\Socks\Client as SocksClient;
5+
use Psr\Http\Message\ResponseInterface;
6+
use React\EventLoop\Factory as LoopFactory;
7+
use React\Socket\Connector;
8+
9+
require __DIR__ . '/../vendor/autoload.php';
10+
11+
$loop = LoopFactory::create();
12+
13+
// create a new SOCKS proxy client which connects to a SOCKS proxy server listening on localhost:1080
14+
// not already running a SOCKS proxy server? Try LeProxy.org or this: `ssh -D 1080 localhost`
15+
$proxy = new SocksClient('127.0.0.1:1080', new Connector($loop));
16+
17+
// create a Browser object that uses the SOCKS proxy client for connections
18+
$connector = new Connector($loop, array(
19+
'tcp' => $proxy,
20+
'dns' => false
21+
));
22+
$browser = new Browser($loop, $connector);
23+
24+
// demo fetching HTTP headers (or bail out otherwise)
25+
$browser->get('https://www.google.com/')->then(function (ResponseInterface $response) {
26+
echo RingCentral\Psr7\str($response);
27+
}, 'printf');
28+
29+
$loop->run();

0 commit comments

Comments
 (0)