-
Notifications
You must be signed in to change notification settings - Fork 53
HTTP clients
This library brings you two (three) HTTP client implementations. Milo\Github\Http\CurlClient and Milo\Github\Http\StreamClient. cURL client is used as default when cURL extension is loaded. If not, StreamClient is used.
Client uses cURL extension. You can pass cURL options to its constructor. Some of them are hard-coded in class implementation, check out the source code.
# Without parameters
$client = new Milo\Github\Http\CurlClient;
# Set some SSL parameters
$client = new Milo\Github\Http\CurlClient([
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_CONNECTTIMEOUT => 2,
]);
This client uses file_get_contents()
and HTTP context. You can pass SSL context options by constructor.
# Without parameters
$client = new Milo\Github\Http\StreamClient;
# Set some SSL parameters
$client = new Milo\Github\Http\CurlClient([
'verify_peer' => TRUE,
'cafile' => '/etc/ssl/trusted.ca.pem',
]);
It is not real client. It is a client wrapper with caching capability. The reason for the client is the rate limiting.
It uses Milo\Github\Storages\ICache interface to store cacheable responses. Default naive implementation is the FileCache.
$cache = new Milo\Github\Storages\FileCache('/tmp');
$client = new Milo\Github\Http\CachedClient($cache);
# Or specify wrapped client explicitly
$cache = new Milo\Github\Storages\FileCache('/tmp');
$realClient = new Milo\Github\Http\StreamClient;
$client = new Milo\Github\Http\CachedClient($cache, $realClient);
Client interface has onRequest()
and onResponse()
methods just for debugging purpose.
$client->onRequest(function(Milo\Github\Http\Request $request) {
var_dump($request);
});
$client->onResponse(function(Milo\Github\Http\Response $response) {
var_dump($response);
});