| Línea 50... |
Línea 50... |
| 50 |
* into relative URIs. Can be a string or instance of UriInterface.
|
50 |
* into relative URIs. Can be a string or instance of UriInterface.
|
| 51 |
* - **: any request option
|
51 |
* - **: any request option
|
| 52 |
*
|
52 |
*
|
| 53 |
* @param array $config Client configuration settings.
|
53 |
* @param array $config Client configuration settings.
|
| 54 |
*
|
54 |
*
|
| 55 |
* @see \GuzzleHttp\RequestOptions for a list of available request options.
|
55 |
* @see RequestOptions for a list of available request options.
|
| 56 |
*/
|
56 |
*/
|
| 57 |
public function __construct(array $config = [])
|
57 |
public function __construct(array $config = [])
|
| 58 |
{
|
58 |
{
|
| 59 |
if (!isset($config['handler'])) {
|
59 |
if (!isset($config['handler'])) {
|
| 60 |
$config['handler'] = HandlerStack::create();
|
60 |
$config['handler'] = HandlerStack::create();
|
| Línea 118... |
Línea 118... |
| 118 |
* @throws GuzzleException
|
118 |
* @throws GuzzleException
|
| 119 |
*/
|
119 |
*/
|
| 120 |
public function send(RequestInterface $request, array $options = []): ResponseInterface
|
120 |
public function send(RequestInterface $request, array $options = []): ResponseInterface
|
| 121 |
{
|
121 |
{
|
| 122 |
$options[RequestOptions::SYNCHRONOUS] = true;
|
122 |
$options[RequestOptions::SYNCHRONOUS] = true;
|
| - |
|
123 |
|
| 123 |
return $this->sendAsync($request, $options)->wait();
|
124 |
return $this->sendAsync($request, $options)->wait();
|
| 124 |
}
|
125 |
}
|
| Línea 125... |
Línea 126... |
| 125 |
|
126 |
|
| 126 |
/**
|
127 |
/**
|
| 127 |
* The HttpClient PSR (PSR-18) specify this method.
|
128 |
* The HttpClient PSR (PSR-18) specify this method.
|
| 128 |
*
|
129 |
*
|
| 129 |
* @inheritDoc
|
130 |
* {@inheritDoc}
|
| 130 |
*/
|
131 |
*/
|
| 131 |
public function sendRequest(RequestInterface $request): ResponseInterface
|
132 |
public function sendRequest(RequestInterface $request): ResponseInterface
|
| 132 |
{
|
133 |
{
|
| 133 |
$options[RequestOptions::SYNCHRONOUS] = true;
|
134 |
$options[RequestOptions::SYNCHRONOUS] = true;
|
| Línea 182... |
Línea 183... |
| 182 |
* @throws GuzzleException
|
183 |
* @throws GuzzleException
|
| 183 |
*/
|
184 |
*/
|
| 184 |
public function request(string $method, $uri = '', array $options = []): ResponseInterface
|
185 |
public function request(string $method, $uri = '', array $options = []): ResponseInterface
|
| 185 |
{
|
186 |
{
|
| 186 |
$options[RequestOptions::SYNCHRONOUS] = true;
|
187 |
$options[RequestOptions::SYNCHRONOUS] = true;
|
| - |
|
188 |
|
| 187 |
return $this->requestAsync($method, $uri, $options)->wait();
|
189 |
return $this->requestAsync($method, $uri, $options)->wait();
|
| 188 |
}
|
190 |
}
|
| Línea 189... |
Línea 191... |
| 189 |
|
191 |
|
| 190 |
/**
|
192 |
/**
|
| Línea 226... |
Línea 228... |
| 226 |
*/
|
228 |
*/
|
| 227 |
private function configureDefaults(array $config): void
|
229 |
private function configureDefaults(array $config): void
|
| 228 |
{
|
230 |
{
|
| 229 |
$defaults = [
|
231 |
$defaults = [
|
| 230 |
'allow_redirects' => RedirectMiddleware::$defaultSettings,
|
232 |
'allow_redirects' => RedirectMiddleware::$defaultSettings,
|
| 231 |
'http_errors' => true,
|
233 |
'http_errors' => true,
|
| 232 |
'decode_content' => true,
|
234 |
'decode_content' => true,
|
| 233 |
'verify' => true,
|
235 |
'verify' => true,
|
| 234 |
'cookies' => false,
|
236 |
'cookies' => false,
|
| 235 |
'idn_conversion' => false,
|
237 |
'idn_conversion' => false,
|
| 236 |
];
|
238 |
];
|
| Línea 237... |
Línea 239... |
| 237 |
|
239 |
|
| Línea 238... |
Línea 240... |
| 238 |
// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
|
240 |
// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
|
| Línea 352... |
Línea 354... |
| 352 |
}
|
354 |
}
|
| Línea 353... |
Línea 355... |
| 353 |
|
355 |
|
| 354 |
if (isset($options['form_params'])) {
|
356 |
if (isset($options['form_params'])) {
|
| 355 |
if (isset($options['multipart'])) {
|
357 |
if (isset($options['multipart'])) {
|
| 356 |
throw new InvalidArgumentException('You cannot use '
|
358 |
throw new InvalidArgumentException('You cannot use '
|
| 357 |
. 'form_params and multipart at the same time. Use the '
|
359 |
.'form_params and multipart at the same time. Use the '
|
| 358 |
. 'form_params option if you want to send application/'
|
360 |
.'form_params option if you want to send application/'
|
| 359 |
. 'x-www-form-urlencoded requests, and the multipart '
|
361 |
.'x-www-form-urlencoded requests, and the multipart '
|
| 360 |
. 'option to send multipart/form-data requests.');
|
362 |
.'option to send multipart/form-data requests.');
|
| 361 |
}
|
363 |
}
|
| 362 |
$options['body'] = \http_build_query($options['form_params'], '', '&');
|
364 |
$options['body'] = \http_build_query($options['form_params'], '', '&');
|
| 363 |
unset($options['form_params']);
|
365 |
unset($options['form_params']);
|
| 364 |
// Ensure that we don't have the header in different case and set the new value.
|
366 |
// Ensure that we don't have the header in different case and set the new value.
|
| Línea 401... |
Línea 403... |
| 401 |
switch ($type) {
|
403 |
switch ($type) {
|
| 402 |
case 'basic':
|
404 |
case 'basic':
|
| 403 |
// Ensure that we don't have the header in different case and set the new value.
|
405 |
// Ensure that we don't have the header in different case and set the new value.
|
| 404 |
$modify['set_headers'] = Psr7\Utils::caselessRemove(['Authorization'], $modify['set_headers']);
|
406 |
$modify['set_headers'] = Psr7\Utils::caselessRemove(['Authorization'], $modify['set_headers']);
|
| 405 |
$modify['set_headers']['Authorization'] = 'Basic '
|
407 |
$modify['set_headers']['Authorization'] = 'Basic '
|
| 406 |
. \base64_encode("$value[0]:$value[1]");
|
408 |
.\base64_encode("$value[0]:$value[1]");
|
| 407 |
break;
|
409 |
break;
|
| 408 |
case 'digest':
|
410 |
case 'digest':
|
| 409 |
// @todo: Do not rely on curl
|
411 |
// @todo: Do not rely on curl
|
| 410 |
$options['curl'][\CURLOPT_HTTPAUTH] = \CURLAUTH_DIGEST;
|
412 |
$options['curl'][\CURLOPT_HTTPAUTH] = \CURLAUTH_DIGEST;
|
| 411 |
$options['curl'][\CURLOPT_USERPWD] = "$value[0]:$value[1]";
|
413 |
$options['curl'][\CURLOPT_USERPWD] = "$value[0]:$value[1]";
|
| Línea 435... |
Línea 437... |
| 435 |
if (\is_bool($options['sink'])) {
|
437 |
if (\is_bool($options['sink'])) {
|
| 436 |
throw new InvalidArgumentException('sink must not be a boolean');
|
438 |
throw new InvalidArgumentException('sink must not be a boolean');
|
| 437 |
}
|
439 |
}
|
| 438 |
}
|
440 |
}
|
| Línea -... |
Línea 441... |
| - |
|
441 |
|
| - |
|
442 |
if (isset($options['version'])) {
|
| - |
|
443 |
$modify['version'] = $options['version'];
|
| - |
|
444 |
}
|
| 439 |
|
445 |
|
| 440 |
$request = Psr7\Utils::modifyRequest($request, $modify);
|
446 |
$request = Psr7\Utils::modifyRequest($request, $modify);
|
| 441 |
if ($request->getBody() instanceof Psr7\MultipartStream) {
|
447 |
if ($request->getBody() instanceof Psr7\MultipartStream) {
|
| 442 |
// Use a multipart/form-data POST if a Content-Type is not set.
|
448 |
// Use a multipart/form-data POST if a Content-Type is not set.
|
| 443 |
// Ensure that we don't have the header in different case and set the new value.
|
449 |
// Ensure that we don't have the header in different case and set the new value.
|
| 444 |
$options['_conditional'] = Psr7\Utils::caselessRemove(['Content-Type'], $options['_conditional']);
|
450 |
$options['_conditional'] = Psr7\Utils::caselessRemove(['Content-Type'], $options['_conditional']);
|
| 445 |
$options['_conditional']['Content-Type'] = 'multipart/form-data; boundary='
|
451 |
$options['_conditional']['Content-Type'] = 'multipart/form-data; boundary='
|
| 446 |
. $request->getBody()->getBoundary();
|
452 |
.$request->getBody()->getBoundary();
|
| Línea 447... |
Línea 453... |
| 447 |
}
|
453 |
}
|
| 448 |
|
454 |
|
| 449 |
// Merge in conditional headers if they are not present.
|
455 |
// Merge in conditional headers if they are not present.
|
| Línea 467... |
Línea 473... |
| 467 |
* Return an InvalidArgumentException with pre-set message.
|
473 |
* Return an InvalidArgumentException with pre-set message.
|
| 468 |
*/
|
474 |
*/
|
| 469 |
private function invalidBody(): InvalidArgumentException
|
475 |
private function invalidBody(): InvalidArgumentException
|
| 470 |
{
|
476 |
{
|
| 471 |
return new InvalidArgumentException('Passing in the "body" request '
|
477 |
return new InvalidArgumentException('Passing in the "body" request '
|
| 472 |
. 'option as an array to send a request is not supported. '
|
478 |
.'option as an array to send a request is not supported. '
|
| 473 |
. 'Please use the "form_params" request option to send a '
|
479 |
.'Please use the "form_params" request option to send a '
|
| 474 |
. 'application/x-www-form-urlencoded request, or the "multipart" '
|
480 |
.'application/x-www-form-urlencoded request, or the "multipart" '
|
| 475 |
. 'request option to send a multipart/form-data request.');
|
481 |
.'request option to send a multipart/form-data request.');
|
| 476 |
}
|
482 |
}
|
| 477 |
}
|
483 |
}
|