X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=http%2FClient.md;h=14626a7f78136e2ac27b5bf57aece85246fb6f23;hb=71a35b9d0d6597cf2a143847bcbcfef1420d0d5d;hp=faacc4493fef0740b7fdb59a469bda06751c1b64;hpb=470544f38dc95f63cf667dea87fdf8364445b33d;p=mdref%2Fmdref-http diff --git a/http/Client.md b/http/Client.md index faacc44..14626a7 100644 --- a/http/Client.md +++ b/http/Client.md @@ -1,14 +1,119 @@ # class http\Client implements SplSubject, Countable -The HTTP client. +The HTTP client. See http\Client\Curl's [options](http/Client/Curl#Options:) which is the only driver currently supported. + +## Changelog: + +Version | Change +--------|------- +2.3.0 | Deprecated methods:
http\Client::enablePipelining() and
http\Client::enableEvents().
Added Methods:
http\Client::configure(),
http\Client::getAvailableConfiguration() and
http\Client::getAvailableOptions(). + +## Examples: + +### Sending a simple GET request: + + "My Client/0.1"] + ); + $request->setOptions(["timeout"=>1]); + + $client = new http\Client; + $client->enqueue($request)->send(); + + // pop the last retrieved response + $response = $client->getResponse(); + printf("%s returned '%s' (%d)\n", + $response->getTransferInfo("effective_url"), + $response->getInfo(), + $response->getResponseCode() + ); + ?> + +#### Yields: + + http://localhost/ returned 'HTTP/1.1 200 OK' (200) + + +### Submitting a standard form: + + "application/x-www-form-urlencoded"] + ); + $request->getBody()->append(new http\QueryString([ + "user" => "mike", + "name" => "Michael Wallner" + ])); + + $client = new http\Client; + $client->setOptions(["ssl" => [ + "version" => http\Client\Curl\SSL_VERSION_TLSv1 + ]]); + $client->enqueue($request)->send(); + + // ask for the response for this specific request + $response = $client->getResponse($request); + printf("-> %s\n", $response->getInfo()); + + ?> + +#### Yields: + + -> HTTP/1.1 200 OK + + +### Submitting a multipart form: + + getBody()->addForm([ + "user" => "mike", + "name" => "Michael Wallner" + ], [ + [ + "name" => "image", + "type" => "image/jpeg", + "file" => "image.jpg" + ] + ]); + + $client = new http\Client; + $client->setOptions(["ssl" => [ + "version" => http\Client\Curl\SSL_VERSION_TLSv1 + ]]); + $client->enqueue($request)->send(); + + // ask for the response for this specific request + $response = $client->getResponse($request); + printf("-> %.2F kB\n @ %.2F Mbit", + .001 * $response->getTransferInfo("size_upload"), + .0000008 * $response->getTransferInfo("speed_upload") + ); + ?> + +#### Yields: + + -> 15.98 kB @ 6.77 Mbit + ## Properties: -* private $observers = NULL - SplObjectStorage, attached observers. -* protected $options = NULL - Array of set options. -* protected $history = NULL - http\Message request/response history. -* public $recordHistory = false - Boolean flag whether to record history in http\Client::$history. +* private SplObjectStorage $observers = NULL + Attached observers. +* protected array $options = NULL + Set options. +* protected http\Message $history = NULL + Request/response history. +* public bool $recordHistory = false + Whether to record history in http\Client::$history.