ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
|
A rudimentary HTTP client. More...
Public Member Functions | |
__construct () | |
Initializes the client. More... | |
send (RequestInterface $request) | |
Sends a request to a HTTP server, and returns a response. More... | |
sendAsync (RequestInterface $request, callable $success=null, callable $error=null) | |
Sends a HTTP request asynchronously. More... | |
poll () | |
This method checks if any http requests have gotten results, and if so, call the appropriate success or error handlers. More... | |
wait () | |
Processes every HTTP request in the queue, and waits till they are all completed. More... | |
setThrowExceptions ($throwExceptions) | |
If this is set to true, the Client will automatically throw exceptions upon HTTP errors. More... | |
addCurlSetting ($name, $value) | |
Adds a CURL setting. More... | |
Public Member Functions inherited from Sabre\Event\EventEmitterInterface | |
on ($eventName, callable $callBack, $priority=100) | |
Subscribe to an event. More... | |
once ($eventName, callable $callBack, $priority=100) | |
Subscribe to an event exactly once. More... | |
emit ($eventName, array $arguments=[], callable $continueCallBack=null) | |
Emits an event. More... | |
listeners ($eventName) | |
Returns the list of listeners for an event. More... | |
removeListener ($eventName, callable $listener) | |
Removes a specific listener from an event. More... | |
removeAllListeners ($eventName=null) | |
Removes all listeners. More... | |
Data Fields | |
const | STATUS_SUCCESS = 0 |
const | STATUS_CURLERROR = 1 |
const | STATUS_HTTPERROR = 2 |
Protected Member Functions | |
doRequest (RequestInterface $request) | |
This method is responsible for performing a single request. More... | |
createCurlSettingsArray (RequestInterface $request) | |
Turns a RequestInterface object into an array with settings that can be fed to curl_setopt. More... | |
parseCurlResult ($response, $curlHandle) | |
Parses the result of a curl call in a format that's a bit more convenient to work with. More... | |
sendAsyncInternal (RequestInterface $request, callable $success, callable $error, $retryCount=0) | |
Sends an asynchronous HTTP request. More... | |
curlExec ($curlHandle) | |
Calls curl_exec. More... | |
curlStuff ($curlHandle) | |
Returns a bunch of information about a curl request. More... | |
Protected Attributes | |
$curlSettings = [] | |
$throwExceptions = false | |
$maxRedirects = 5 | |
Private Attributes | |
$curlHandle | |
$curlMultiHandle | |
$curlMultiMap = [] | |
A rudimentary HTTP client.
This object wraps PHP's curl extension and provides an easy way to send it a Request object, and return a Response object.
This is by no means intended as the next best HTTP client, but it does the job and provides a simple integration with the rest of sabre/http.
This client emits the following events: beforeRequest(RequestInterface $request) afterRequest(RequestInterface $request, ResponseInterface $response) error(RequestInterface $request, ResponseInterface $response, bool &$retry, int $retryCount) exception(RequestInterface $request, ClientException $e, bool &$retry, int $retryCount)
The beforeRequest event allows you to do some last minute changes to the request before it's done, such as adding authentication headers.
The afterRequest event will be emitted after the request is completed succesfully.
If a HTTP error is returned (status code higher than 399) the error event is triggered. It's possible using this event to retry the request, by setting retry to true.
The amount of times a request has retried is passed as $retryCount, which can be used to avoid retrying indefinitely. The first time the event is called, this will be 0.
It's also possible to intercept specific http errors, by subscribing to for example 'error:401'.
Definition at line 44 of file Client.php.
Sabre\HTTP\Client::__construct | ( | ) |
Initializes the client.
Definition at line 72 of file Client.php.
References Sabre\HTTP\Version\VERSION.
Sabre\HTTP\Client::addCurlSetting | ( | $name, | |
$value | |||
) |
Adds a CURL setting.
These settings will be included in every HTTP request.
int | $name | |
mixed | $value |
Definition at line 331 of file Client.php.
References $name.
Referenced by Sabre\DAV\Client\__construct().
|
protected |
Turns a RequestInterface object into an array with settings that can be fed to curl_setopt.
RequestInterface | $request |
Definition at line 397 of file Client.php.
References Sabre\HTTP\Client\$curlSettings, $key, $values, Sabre\HTTP\MessageInterface\getBody(), Sabre\HTTP\MessageInterface\getHeaders(), Sabre\HTTP\RequestInterface\getMethod(), and Sabre\HTTP\RequestInterface\getUrl().
Referenced by Sabre\HTTP\Client\doRequest(), and Sabre\HTTP\Client\sendAsyncInternal().
|
protected |
Calls curl_exec.
This method exists so it can easily be overridden and mocked.
resource | $curlHandle |
Definition at line 576 of file Client.php.
References Sabre\HTTP\Client\$curlHandle.
Referenced by Sabre\HTTP\Client\doRequest().
|
protected |
Returns a bunch of information about a curl request.
This method exists so it can easily be overridden and mocked.
resource | $curlHandle |
Definition at line 590 of file Client.php.
References Sabre\HTTP\Client\$curlHandle.
Referenced by Sabre\HTTP\Client\parseCurlResult().
|
protected |
This method is responsible for performing a single request.
RequestInterface | $request |
Definition at line 343 of file Client.php.
References $response, Sabre\HTTP\Client\createCurlSettingsArray(), Sabre\HTTP\Client\curlExec(), and Sabre\HTTP\Client\parseCurlResult().
Referenced by Sabre\HTTP\Client\send().
|
protected |
Parses the result of a curl call in a format that's a bit more convenient to work with.
The method returns an array with the following elements:
string | $response | |
resource | $curlHandle |
Definition at line 478 of file Client.php.
References Sabre\HTTP\Client\$curlHandle, $header, $response, and Sabre\HTTP\Client\curlStuff().
Referenced by Sabre\HTTP\Client\doRequest(), and Sabre\HTTP\Client\poll().
Sabre\HTTP\Client::poll | ( | ) |
This method checks if any http requests have gotten results, and if so, call the appropriate success or error handlers.
This method will return true if there are still requests waiting to return, and false if all the work is done.
Definition at line 199 of file Client.php.
References $r, $request, $retry, Sabre\Event\EventEmitterInterface\emit(), Sabre\HTTP\Client\parseCurlResult(), and Sabre\HTTP\Client\sendAsyncInternal().
Referenced by Sabre\HTTP\Client\sendAsync(), and Sabre\HTTP\Client\wait().
Sabre\HTTP\Client::send | ( | RequestInterface | $request | ) |
Sends a request to a HTTP server, and returns a response.
RequestInterface | $request |
Definition at line 89 of file Client.php.
References $code, $request, $response, $retry, Sabre\HTTP\Client\doRequest(), Sabre\Event\EventEmitterInterface\emit(), Sabre\HTTP\RequestInterface\getUrl(), and Sabre\Event\Promise\resolve().
Referenced by Sabre\DAV\Client\options(), Sabre\DAV\Client\propFind(), Sabre\DAV\Client\propPatch(), and Sabre\DAV\Client\request().
Sabre\HTTP\Client::sendAsync | ( | RequestInterface | $request, |
callable | $success = null , |
||
callable | $error = null |
||
) |
Sends a HTTP request asynchronously.
Due to the nature of PHP, you must from time to time poll to see if any new responses came in.
After calling sendAsync, you must therefore occasionally call the poll() method, or wait().
RequestInterface | $request | |
callable | $success | |
callable | $error |
Definition at line 181 of file Client.php.
References $success, Sabre\Event\EventEmitterInterface\emit(), Sabre\HTTP\Client\poll(), and Sabre\HTTP\Client\sendAsyncInternal().
|
protected |
Sends an asynchronous HTTP request.
We keep this in a separate method, so we can call it without triggering the beforeRequest event and don't do the poll().
RequestInterface | $request | |
callable | $success | |
callable | $error | |
int | $retryCount |
Definition at line 546 of file Client.php.
References $request, $success, and Sabre\HTTP\Client\createCurlSettingsArray().
Referenced by Sabre\HTTP\Client\poll(), and Sabre\HTTP\Client\sendAsync().
Sabre\HTTP\Client::setThrowExceptions | ( | $throwExceptions | ) |
If this is set to true, the Client will automatically throw exceptions upon HTTP errors.
This means that if a response came back with a status code greater than or equal to 400, we will throw a ClientHttpException.
This only works for the send() method. Throwing exceptions for sendAsync() is not supported.
bool | $throwExceptions |
Definition at line 316 of file Client.php.
References Sabre\HTTP\Client\$throwExceptions.
Sabre\HTTP\Client::wait | ( | ) |
Processes every HTTP request in the queue, and waits till they are all completed.
Definition at line 294 of file Client.php.
References Sabre\HTTP\Client\poll().
|
private |
Definition at line 371 of file Client.php.
Referenced by Sabre\HTTP\Client\curlExec(), Sabre\HTTP\Client\curlStuff(), and Sabre\HTTP\Client\parseCurlResult().
|
private |
Definition at line 380 of file Client.php.
|
private |
Definition at line 388 of file Client.php.
|
protected |
Definition at line 51 of file Client.php.
Referenced by Sabre\HTTP\Client\createCurlSettingsArray().
|
protected |
Definition at line 65 of file Client.php.
|
protected |
Definition at line 58 of file Client.php.
Referenced by Sabre\HTTP\Client\setThrowExceptions().
const Sabre\HTTP\Client::STATUS_CURLERROR = 1 |
Definition at line 456 of file Client.php.
Referenced by Sabre\HTTP\ClientTest\testParseCurlError().
const Sabre\HTTP\Client::STATUS_HTTPERROR = 2 |
Definition at line 457 of file Client.php.
const Sabre\HTTP\Client::STATUS_SUCCESS = 0 |
Definition at line 455 of file Client.php.
Referenced by Sabre\HTTP\ClientTest\testParseCurlResult().