| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Symfony\Contracts\HttpClient; |
| 13 |
|
| 14 |
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; |
| 15 |
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; |
| 16 |
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; |
| 17 |
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; |
| 18 |
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; |
| 19 |
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; |
| 20 |
|
| 21 |
/** |
| 22 |
* A (lazily retrieved) HTTP response. |
| 23 |
* |
| 24 |
* @author Nicolas Grekas <[email protected]> |
| 25 |
*/ |
| 26 |
interface ResponseInterface |
| 27 |
{ |
| 28 |
/** |
| 29 |
* Gets the HTTP status code of the response. |
| 30 |
* |
| 31 |
* @throws TransportExceptionInterface when a network error occurs |
| 32 |
*/ |
| 33 |
public function getStatusCode(): int; |
| 34 |
|
| 35 |
/** |
| 36 |
* Gets the HTTP headers of the response. |
| 37 |
* |
| 38 |
* @param bool $throw Whether an exception should be thrown on 3/4/5xx status codes |
| 39 |
* |
| 40 |
* @return string[][] The headers of the response keyed by header names in lowercase |
| 41 |
* |
| 42 |
* @throws TransportExceptionInterface When a network error occurs |
| 43 |
* @throws RedirectionExceptionInterface On a 3xx when $throw is true and the "max_redirects" option has been reached |
| 44 |
* @throws ClientExceptionInterface On a 4xx when $throw is true |
| 45 |
* @throws ServerExceptionInterface On a 5xx when $throw is true |
| 46 |
*/ |
| 47 |
public function getHeaders(bool $throw = true): array; |
| 48 |
|
| 49 |
/** |
| 50 |
* Gets the response body as a string. |
| 51 |
* |
| 52 |
* @param bool $throw Whether an exception should be thrown on 3/4/5xx status codes |
| 53 |
* |
| 54 |
* @throws TransportExceptionInterface When a network error occurs |
| 55 |
* @throws RedirectionExceptionInterface On a 3xx when $throw is true and the "max_redirects" option has been reached |
| 56 |
* @throws ClientExceptionInterface On a 4xx when $throw is true |
| 57 |
* @throws ServerExceptionInterface On a 5xx when $throw is true |
| 58 |
*/ |
| 59 |
public function getContent(bool $throw = true): string; |
| 60 |
|
| 61 |
/** |
| 62 |
* Gets the response body decoded as array, typically from a JSON payload. |
| 63 |
* |
| 64 |
* @param bool $throw Whether an exception should be thrown on 3/4/5xx status codes |
| 65 |
* |
| 66 |
* @throws DecodingExceptionInterface When the body cannot be decoded to an array |
| 67 |
* @throws TransportExceptionInterface When a network error occurs |
| 68 |
* @throws RedirectionExceptionInterface On a 3xx when $throw is true and the "max_redirects" option has been reached |
| 69 |
* @throws ClientExceptionInterface On a 4xx when $throw is true |
| 70 |
* @throws ServerExceptionInterface On a 5xx when $throw is true |
| 71 |
*/ |
| 72 |
public function toArray(bool $throw = true): array; |
| 73 |
|
| 74 |
/** |
| 75 |
* Closes the response stream and all related buffers. |
| 76 |
* |
| 77 |
* No further chunk will be yielded after this method has been called. |
| 78 |
*/ |
| 79 |
public function cancel(): void; |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns info coming from the transport layer. |
| 83 |
* |
| 84 |
* This method SHOULD NOT throw any ExceptionInterface and SHOULD be non-blocking. |
| 85 |
* The returned info is "live": it can be empty and can change from one call to |
| 86 |
* another, as the request/response progresses. |
| 87 |
* |
| 88 |
* The following info MUST be returned: |
| 89 |
* - canceled (bool) - true if the response was canceled using ResponseInterface::cancel(), false otherwise |
| 90 |
* - error (string|null) - the error message when the transfer was aborted, null otherwise |
| 91 |
* - http_code (int) - the last response code or 0 when it is not known yet |
| 92 |
* - http_method (string) - the HTTP verb of the last request |
| 93 |
* - redirect_count (int) - the number of redirects followed while executing the request |
| 94 |
* - redirect_url (string|null) - the resolved location of redirect responses, null otherwise |
| 95 |
* - response_headers (array) - an array modelled after the special $http_response_header variable |
| 96 |
* - start_time (float) - the time when the request was sent or 0.0 when it's pending |
| 97 |
* - url (string) - the last effective URL of the request |
| 98 |
* - user_data (mixed) - the value of the "user_data" request option, null if not set |
| 99 |
* |
| 100 |
* When the "capture_peer_cert_chain" option is true, the "peer_certificate_chain" |
| 101 |
* attribute SHOULD list the peer certificates as an array of OpenSSL X.509 resources. |
| 102 |
* |
| 103 |
* Other info SHOULD be named after curl_getinfo()'s associative return value. |
| 104 |
* |
| 105 |
* @return mixed An array of all available info, or one of them when $type is |
| 106 |
* provided, or null when an unsupported type is requested |
| 107 |
*/ |
| 108 |
public function getInfo(string $type = null); |
| 109 |
} |
| 110 |
|