Debian Codegraph @

vendor/guzzlehttp/guzzle/src/Client.php

raw
1 <?php
2
3 namespace GuzzleHttp;
4
5 use GuzzleHttp\Cookie\CookieJar;
6 use GuzzleHttp\Cookie\CookieJarInterface;
7 use GuzzleHttp\Exception\GuzzleException;
8 use GuzzleHttp\Exception\InvalidArgumentException;
9 use GuzzleHttp\Handler\CurlShareHandleState;
10 use GuzzleHttp\Promise as P;
11 use GuzzleHttp\Promise\PromiseInterface;
12 use Psr\Http\Message\RequestInterface;
13 use Psr\Http\Message\ResponseInterface;
14 use Psr\Http\Message\StreamInterface;
15 use Psr\Http\Message\UriInterface;
16
17 /**
18 * @final
19 */
20 class Client implements ClientInterface, \Psr\Http\Client\ClientInterface
21 {
22 use ClientTrait;
23
24 /**
25 * @var array Default request options
26 */
27 private $config;
28
29 /**
30 * Clients accept an array of constructor parameters.
31 *
32 * Here's an example of creating a client using a base_uri and an array of
33 * default request options to apply to each request:
34 *
35 * $client = new Client([
36 * 'base_uri' => 'http://www.foo.com/1.0/',
37 * 'timeout' => 0,
38 * 'allow_redirects' => false,
39 * 'proxy' => '192.168.16.1:10'
40 * ]);
41 *
42 * Client configuration settings include the following options:
43 *
44 * - handler: (callable) Function that transfers HTTP requests over the
45 * wire. The function is called with a Psr7\Http\Message\RequestInterface
46 * and array of transfer options, and must return a
47 * GuzzleHttp\Promise\PromiseInterface that is fulfilled with a
48 * Psr7\Http\Message\ResponseInterface on success.
49 * If no handler is provided, a default handler will be created
50 * that enables all of the request options below by attaching all of the
51 * default middleware to the handler.
52 * - base_uri: (string|UriInterface) Base URI of the client that is merged
53 * into relative URIs. Can be a string or instance of UriInterface.
54 * - transport_sharing: (string|null) Transport sharing mode for the
55 * default handler. Accepts TransportSharing::* or null. Defaults to null.
56 * - **: any request option
57 *
58 * @param array $config Client configuration settings.
59 *
60 * @see RequestOptions for a list of available request options.
61 */
62 public function __construct(array $config = [])
63 {
64 $transportSharing = \array_key_exists('transport_sharing', $config) ? $config['transport_sharing'] : null;
65 $transportSharingMode = CurlShareHandleState::normalizeMode($transportSharing, 'transport_sharing');
66 unset($config['transport_sharing']);
67
68 if (!isset($config['handler'])) {
69 $config['handler'] = $transportSharingMode === TransportSharing::NONE
70 ? HandlerStack::create()
71 : HandlerStack::create(Utils::chooseHandler(['transport_sharing' => $transportSharingMode]));
72 } elseif (!\is_callable($config['handler'])) {
73 throw new InvalidArgumentException('handler must be a callable');
74 } elseif ($transportSharingMode === TransportSharing::HANDLER_REQUIRE) {
75 throw new InvalidArgumentException('The "transport_sharing" client option can only require sharing when Guzzle creates the default handler. Configure the "transport_sharing" option on CurlHandler or CurlMultiHandler when providing a custom cURL handler.');
76 }
77
78 // Convert the base_uri to a UriInterface
79 if (isset($config['base_uri'])) {
80 $config['base_uri'] = Psr7\Utils::uriFor($config['base_uri']);
81 }
82
83 $this->configureDefaults($config);
84 }
85
86 /**
87 * @param string $method
88 * @param array $args
89 *
90 * @return PromiseInterface|ResponseInterface
91 *
92 * @deprecated Client::__call will be removed in guzzlehttp/guzzle:8.0.
93 */
94 public function __call($method, $args)
95 {
96 if (\count($args) < 1) {
97 throw new InvalidArgumentException('Magic request methods require a URI and optional options array');
98 }
99
100 $uri = $args[0];
101 $opts = $args[1] ?? [];
102
103 $isAsync = \substr($method, -5) === 'Async';
104 $method = $isAsync ? \substr($method, 0, -5) : $method;
105 $method = \strtoupper($method);
106
107 return $isAsync
108 ? $this->requestAsync($method, $uri, $opts)
109 : $this->request($method, $uri, $opts);
110 }
111
112 /**
113 * Asynchronously send an HTTP request.
114 *
115 * @param array $options Request options to apply to the given
116 * request and to the transfer. See {@see RequestOptions}.
117 */
118 public function sendAsync(RequestInterface $request, array $options = []): PromiseInterface
119 {
120 // Merge the base URI into the request URI if needed.
121 $options = $this->prepareDefaults($options);
122
123 return $this->transfer(
124 $request->withUri($this->buildUri($request->getUri(), $options), $request->hasHeader('Host')),
125 $options
126 );
127 }
128
129 /**
130 * Send an HTTP request.
131 *
132 * @param array $options Request options to apply to the given
133 * request and to the transfer. See {@see RequestOptions}.
134 *
135 * @throws GuzzleException
136 */
137 public function send(RequestInterface $request, array $options = []): ResponseInterface
138 {
139 $options[RequestOptions::SYNCHRONOUS] = true;
140
141 return $this->sendAsync($request, $options)->wait();
142 }
143
144 /**
145 * The HttpClient PSR (PSR-18) specify this method.
146 *
147 * {@inheritDoc}
148 */
149 public function sendRequest(RequestInterface $request): ResponseInterface
150 {
151 $options[RequestOptions::SYNCHRONOUS] = true;
152 $options[RequestOptions::ALLOW_REDIRECTS] = false;
153 $options[RequestOptions::HTTP_ERRORS] = false;
154
155 return $this->sendAsync($request, $options)->wait();
156 }
157
158 /**
159 * Create and send an asynchronous HTTP request.
160 *
161 * Use an absolute path to override the base path of the client, or a
162 * relative path to append to the base path of the client. The URL can
163 * contain the query string as well. Use an array to provide a URL
164 * template and additional variables to use in the URL template expansion.
165 *
166 * @param string $method HTTP method
167 * @param string|UriInterface $uri URI object or string.
168 * @param array $options Request options to apply. See {@see RequestOptions}.
169 */
170 public function requestAsync(string $method, $uri = '', array $options = []): PromiseInterface
171 {
172 $normalizedMethod = \strtoupper($method);
173 if ($method !== $normalizedMethod) {
174 \trigger_deprecation(
175 'guzzlehttp/guzzle',
176 '7.11',
177 'Passing a non-uppercase HTTP method to Client::requestAsync() is deprecated; guzzlehttp/guzzle 8.0 will preserve HTTP method casing. Pass an uppercase method explicitly if uppercase is required.'
178 );
179 $method = $normalizedMethod;
180 }
181
182 $options = $this->prepareDefaults($options);
183 // Remove request modifying parameter because it can be done up-front.
184 $headers = $options['headers'] ?? [];
185 $droppedHeaderNames = self::castDeprecatedHeaderOptionValues($headers);
186 if ($droppedHeaderNames !== [] && isset($options['_conditional'])) {
187 $options['_conditional'] = Psr7\Utils::caselessRemove($droppedHeaderNames, $options['_conditional']);
188 }
189 $body = $options['body'] ?? null;
190 $version = self::normalizeProtocolVersion($options['version'] ?? '1.1');
191 // Merge the URI into the base URI.
192 $uri = $this->buildUri(Psr7\Utils::uriFor($uri), $options);
193 if (\is_array($body)) {
194 throw $this->invalidBody();
195 }
196 $body = self::createBodyStream($body);
197 $request = new Psr7\Request($method, $uri, $headers, $body, $version);
198 // Remove the option so that they are not doubly-applied.
199 unset($options['headers'], $options['body'], $options['version']);
200
201 return $this->transfer($request, $options);
202 }
203
204 /**
205 * Create and send an HTTP request.
206 *
207 * Use an absolute path to override the base path of the client, or a
208 * relative path to append to the base path of the client. The URL can
209 * contain the query string as well.
210 *
211 * @param string $method HTTP method.
212 * @param string|UriInterface $uri URI object or string.
213 * @param array $options Request options to apply. See {@see RequestOptions}.
214 *
215 * @throws GuzzleException
216 */
217 public function request(string $method, $uri = '', array $options = []): ResponseInterface
218 {
219 $normalizedMethod = \strtoupper($method);
220 if ($method !== $normalizedMethod) {
221 \trigger_deprecation(
222 'guzzlehttp/guzzle',
223 '7.11',
224 'Passing a non-uppercase HTTP method to Client::request() is deprecated; guzzlehttp/guzzle 8.0 will preserve HTTP method casing. Pass an uppercase method explicitly if uppercase is required.'
225 );
226 $method = $normalizedMethod;
227 }
228
229 $options[RequestOptions::SYNCHRONOUS] = true;
230
231 return $this->requestAsync($method, $uri, $options)->wait();
232 }
233
234 /**
235 * Get a client configuration option.
236 *
237 * These options include default request options of the client, a "handler"
238 * (if utilized by the concrete client), and a "base_uri" if utilized by
239 * the concrete client.
240 *
241 * @param string|null $option The config option to retrieve.
242 *
243 * @return mixed
244 */
245 public function getConfig(?string $option = null)
246 {
247 return $option === null
248 ? $this->config
249 : ($this->config[$option] ?? null);
250 }
251
252 private function buildUri(UriInterface $uri, array $config): UriInterface
253 {
254 if (isset($config['base_uri'])) {
255 $uri = Psr7\UriResolver::resolve(Psr7\Utils::uriFor($config['base_uri']), $uri);
256 }
257
258 $idnOptions = Utils::normalizeIdnConversionOption($config['idn_conversion'] ?? null);
259 if ($idnOptions !== null) {
260 $uri = Utils::idnUriConvert($uri, $idnOptions);
261 }
262
263 if ($uri->getScheme() === '' && $uri->getHost() !== '') {
264 $uri = $uri->withScheme('http');
265 }
266
267 return $uri;
268 }
269
270 /**
271 * Configures the default options for a client.
272 */
273 private function configureDefaults(array $config): void
274 {
275 $defaults = [
276 'allow_redirects' => RedirectMiddleware::$defaultSettings,
277 'http_errors' => true,
278 'decode_content' => true,
279 'verify' => true,
280 'cookies' => false,
281 'idn_conversion' => false,
282 'protocols' => ['http', 'https'],
283 ];
284
285 // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
286
287 // We can only trust the HTTP_PROXY environment variable in a CLI
288 // process due to the fact that PHP has no reliable mechanism to
289 // get environment variables that start with "HTTP_".
290 if (\PHP_SAPI === 'cli' && ($proxy = Utils::getenv('HTTP_PROXY'))) {
291 $defaults['proxy']['http'] = $proxy;
292 }
293
294 if ($proxy = Utils::getenv('HTTPS_PROXY')) {
295 $defaults['proxy']['https'] = $proxy;
296 }
297
298 if ($noProxy = Utils::getenv('NO_PROXY')) {
299 $cleanedNoProxy = \str_replace(' ', '', $noProxy);
300 $defaults['proxy']['no'] = \explode(',', $cleanedNoProxy);
301 }
302
303 $this->config = $config + $defaults;
304
305 if (!empty($config['cookies']) && $config['cookies'] === true) {
306 $this->config['cookies'] = new CookieJar();
307 }
308
309 // Add the default user-agent header.
310 if (!isset($this->config['headers'])) {
311 $this->config['headers'] = ['User-Agent' => Utils::defaultUserAgent()];
312 } else {
313 // Add the User-Agent header if one was not already set.
314 $hasUserAgent = false;
315 foreach (\array_keys($this->config['headers']) as $name) {
316 if (\strtolower((string) $name) === 'user-agent') {
317 $hasUserAgent = true;
318 break;
319 }
320 }
321
322 if (!$hasUserAgent) {
323 $this->config['headers']['User-Agent'] = Utils::defaultUserAgent();
324 }
325 }
326
327 if (\is_array($this->config['headers'])) {
328 self::warnAboutInvalidHeaderOptionTypes($this->config['headers']);
329 self::castDeprecatedHeaderOptionValues($this->config['headers']);
330 }
331 }
332
333 /**
334 * Merges default options into the array.
335 *
336 * @param array $options Options to modify by reference
337 */
338 private function prepareDefaults(array $options): array
339 {
340 self::warnAboutRequestLevelHandler($options);
341
342 $defaults = $this->config;
343
344 if (!empty($defaults['headers'])) {
345 // Default headers are only added if they are not present.
346 $defaults['_conditional'] = $defaults['headers'];
347 unset($defaults['headers']);
348 }
349
350 // Special handling for headers is required as they are added as
351 // conditional headers and as headers passed to a request ctor.
352 if (\array_key_exists('headers', $options)) {
353 // Allows default headers to be unset.
354 if ($options['headers'] === null) {
355 $defaults['_conditional'] = [];
356 unset($options['headers']);
357 } elseif (!\is_array($options['headers'])) {
358 throw new InvalidArgumentException('headers must be an array');
359 }
360 }
361
362 // Shallow merge defaults underneath options.
363 $result = $options + $defaults;
364
365 // Remove null values.
366 foreach ($result as $k => $v) {
367 if ($v === null) {
368 unset($result[$k]);
369 }
370 }
371
372 self::warnAboutInvalidRequestOptionTypes($result);
373
374 return self::normalizeDeprecatedRequestOptionValues($result);
375 }
376
377 /**
378 * Normalize values that guzzlehttp/guzzle 8.0 rejects only after the
379 * corresponding 7.x deprecation has already been emitted.
380 *
381 * @param array<string, mixed> $options
382 *
383 * @return array<string, mixed>
384 */
385 private static function normalizeDeprecatedRequestOptionValues(array $options): array
386 {
387 self::normalizeDeprecatedAuthOptionValues($options);
388 self::normalizeDeprecatedTlsFileOptionValues($options, 'cert');
389 self::normalizeDeprecatedTlsFileOptionValues($options, 'ssl_key');
390 self::normalizeDeprecatedStringOptionValues($options);
391 self::normalizeDeprecatedNumericOptionValues($options);
392 self::normalizeDeprecatedIntegerOptionValues($options);
393
394 return $options;
395 }
396
397 /**
398 * @param mixed $value
399 */
400 private static function canStringifyDeprecatedValue($value): bool
401 {
402 return $value === null
403 || \is_scalar($value)
404 || (\is_object($value) && \method_exists($value, '__toString'));
405 }
406
407 /**
408 * @param mixed $value
409 */
410 private static function stringifyDeprecatedValue($value): string
411 {
412 if (\is_float($value) && !\is_finite($value)) {
413 return \is_nan($value) ? 'NAN' : ($value > 0 ? 'INF' : '-INF');
414 }
415
416 if ($value === null) {
417 return '';
418 }
419
420 if (\is_scalar($value)) {
421 return (string) $value;
422 }
423
424 if (\is_object($value) && \method_exists($value, '__toString')) {
425 return $value->__toString();
426 }
427
428 throw new \LogicException('Value is not stringable.');
429 }
430
431 /**
432 * @param array<string, mixed> $options
433 */
434 private static function normalizeDeprecatedAuthOptionValues(array &$options): void
435 {
436 if (!isset($options['auth']) || !\is_array($options['auth']) || $options['auth'] === []) {
437 return;
438 }
439
440 foreach ([0, 1] as $index) {
441 if (
442 \array_key_exists($index, $options['auth'])
443 && !\is_string($options['auth'][$index])
444 && self::canStringifyDeprecatedValue($options['auth'][$index])
445 ) {
446 $options['auth'][$index] = self::stringifyDeprecatedValue($options['auth'][$index]);
447 }
448 }
449
450 if (
451 \array_key_exists(2, $options['auth'])
452 && $options['auth'][2] !== null
453 && !\is_string($options['auth'][2])
454 && self::canStringifyDeprecatedValue($options['auth'][2])
455 ) {
456 $options['auth'][2] = self::stringifyDeprecatedValue($options['auth'][2]);
457 }
458 }
459
460 /**
461 * @param array<string, mixed> $options
462 */
463 private static function normalizeDeprecatedTlsFileOptionValues(array &$options, string $option): void
464 {
465 if (!isset($options[$option]) || !\is_array($options[$option])) {
466 return;
467 }
468
469 foreach ([0, 1] as $index) {
470 if (
471 \array_key_exists($index, $options[$option])
472 && $options[$option][$index] !== null
473 && !\is_string($options[$option][$index])
474 && self::canStringifyDeprecatedValue($options[$option][$index])
475 ) {
476 $options[$option][$index] = self::stringifyDeprecatedValue($options[$option][$index]);
477 }
478 }
479 }
480
481 /**
482 * @param array<string, mixed> $options
483 */
484 private static function normalizeDeprecatedStringOptionValues(array &$options): void
485 {
486 foreach (['cert_type', 'force_ip_resolve', 'ssl_key_type'] as $option) {
487 if (
488 \array_key_exists($option, $options)
489 && !\is_string($options[$option])
490 && self::canStringifyDeprecatedValue($options[$option])
491 ) {
492 $options[$option] = self::stringifyDeprecatedValue($options[$option]);
493 }
494 }
495 }
496
497 /**
498 * @param array<string, mixed> $options
499 */
500 private static function normalizeDeprecatedNumericOptionValues(array &$options): void
501 {
502 foreach (['connect_timeout', 'delay', 'read_timeout', 'timeout'] as $option) {
503 if (
504 \array_key_exists($option, $options)
505 && \is_string($options[$option])
506 && \is_numeric($options[$option])
507 ) {
508 $options[$option] = $options[$option] + 0;
509 }
510 }
511 }
512
513 /**
514 * @param array<string, mixed> $options
515 */
516 private static function normalizeDeprecatedIntegerOptionValues(array &$options): void
517 {
518 foreach (['crypto_method', 'crypto_method_max', 'retries'] as $option) {
519 if (!\array_key_exists($option, $options)) {
520 continue;
521 }
522
523 if (\is_string($options[$option]) && \preg_match('/^-?\d+$/D', $options[$option]) === 1) {
524 $options[$option] = (int) $options[$option];
525 } elseif (
526 \is_float($options[$option])
527 && \is_finite($options[$option])
528 && $options[$option] === (float) (int) $options[$option]
529 ) {
530 $options[$option] = (int) $options[$option];
531 }
532 }
533 }
534
535 private static function warnAboutRequestLevelHandler(array $options): void
536 {
537 if (!\array_key_exists('handler', $options)) {
538 return;
539 }
540
541 \trigger_deprecation(
542 'guzzlehttp/guzzle',
543 '7.12',
544 'Passing the "handler" request option is deprecated; guzzlehttp/guzzle 8.0 will ignore request-level handlers. Configure the handler when creating the Client, or use a separate Client instance for requests that need a different handler.'
545 );
546 }
547
548 private static function warnAboutInvalidRequestOptionTypes(array $options): void
549 {
550 if (isset($options['handler']) && !\is_callable($options['handler'])) {
551 self::warnInvalidRequestOptionType('handler', 'callable', $options['handler']);
552 }
553
554 if (isset($options['allow_redirects']) && \is_array($options['allow_redirects'])) {
555 self::warnAboutInvalidAllowRedirectsOptionTypes($options['allow_redirects']);
556 } elseif (isset($options['allow_redirects']) && !\is_bool($options['allow_redirects'])) {
557 self::warnInvalidRequestOptionType('allow_redirects', 'bool|array', $options['allow_redirects'], '7.13');
558 }
559
560 if (isset($options['auth'])) {
561 self::warnAboutInvalidAuthOptionTypes($options['auth']);
562 }
563
564 if (isset($options['body']) && \is_array($options['body'])) {
565 self::warnInvalidRequestOptionType('body', 'resource|string|null|int|float|bool|StreamInterface|(callable&object)|\Iterator|\Stringable', $options['body']);
566 }
567
568 self::warnAboutInvalidTlsFileOptionTypes($options, 'cert');
569 self::warnIfPresentAndNotString($options, 'cert_type');
570 self::warnIfPresentAndNotNumber($options, 'connect_timeout');
571 self::warnIfPresentAndNotInt($options, 'crypto_method');
572 self::warnIfPresentAndNotInt($options, 'crypto_method_max', null, '7.13');
573 self::warnIfPresentAndNotBoolOrResource($options, 'debug');
574 self::warnIfPresentAndNotBoolOrString($options, 'decode_content');
575 self::warnIfPresentAndNotNumber($options, 'delay');
576 if (isset($options['delay']) && \is_numeric($options['delay'])) {
577 $delay = (float) $options['delay'];
578 if (!\is_finite($delay) || $delay < 0.0) {
579 self::warnInvalidRequestOptionType('delay', 'finite int|float greater than or equal to 0', $options['delay'], '7.13');
580 }
581 }
582 self::warnIfPresentAndNotBoolOrInt($options, 'expect');
583
584 if (isset($options['form_params'])) {
585 self::warnAboutInvalidFormParamTypes($options['form_params']);
586 }
587
588 if (isset($options['force_ip_resolve']) && !\is_string($options['force_ip_resolve'])) {
589 self::warnInvalidRequestOptionType('force_ip_resolve', 'string', $options['force_ip_resolve']);
590 }
591
592 if (
593 isset($options['force_ip_resolve'])
594 && \is_string($options['force_ip_resolve'])
595 && $options['force_ip_resolve'] !== 'v4'
596 && $options['force_ip_resolve'] !== 'v6'
597 ) {
598 self::warnInvalidRequestOptionType('force_ip_resolve', '"v4"|"v6"', $options['force_ip_resolve'], '7.13');
599 }
600
601 if (isset($options['headers'])) {
602 self::warnAboutInvalidHeaderOptionTypes($options['headers']);
603 }
604
605 self::warnIfPresentAndNotBool($options, 'http_errors');
606
607 if (isset($options['multipart'])) {
608 self::warnAboutInvalidMultipartOptionTypes($options['multipart']);
609 }
610
611 self::warnIfPresentAndNotCallable($options, 'on_headers');
612 self::warnIfPresentAndNotCallable($options, 'on_stats');
613 self::warnIfPresentAndNotCallable($options, 'progress');
614 self::warnIfPresentAndNotStringArray($options, 'protocols', true);
615 self::warnAboutInvalidProtocolValues($options, 'protocols');
616 self::warnAboutInvalidProxyOptionTypes($options);
617
618 self::warnIfPresentAndNotNumber($options, 'read_timeout');
619 self::warnIfPresentAndNotInt($options, 'retries');
620
621 if (isset($options['sink']) && !\is_bool($options['sink']) && !\is_resource($options['sink']) && !\is_string($options['sink']) && !$options['sink'] instanceof StreamInterface) {
622 self::warnInvalidRequestOptionType('sink', 'resource|string|StreamInterface', $options['sink']);
623 }
624
625 self::warnAboutInvalidTlsFileOptionTypes($options, 'ssl_key');
626 self::warnIfPresentAndNotString($options, 'ssl_key_type');
627 self::warnIfPresentAndNotBool($options, 'stream');
628 self::warnIfPresentAndNotArray($options, 'stream_context', 'array<array-key, mixed>');
629 self::warnIfPresentAndNotBool($options, 'synchronous');
630 self::warnIfPresentAndNotNumber($options, 'timeout');
631 self::warnIfPresentAndNotBoolOrString($options, 'verify');
632 self::warnIfPresentAndNotStringOrNumber($options, 'version');
633 self::warnIfPresentAndNotArray($options, 'curl', 'array<int|string, mixed>');
634
635 if (isset($options['cookies']) && $options['cookies'] === true) {
636 self::warnInvalidRequestOptionType('cookies', 'false|CookieJarInterface', $options['cookies']);
637 }
638
639 if (
640 isset($options['cookies'])
641 && $options['cookies'] !== false
642 && $options['cookies'] !== true
643 && !($options['cookies'] instanceof CookieJarInterface)
644 ) {
645 self::warnInvalidRequestOptionType('cookies', 'false|CookieJarInterface', $options['cookies'], '7.13');
646 }
647 }
648
649 private static function warnAboutInvalidAllowRedirectsOptionTypes(array $allowRedirects): void
650 {
651 self::warnIfPresentAndNotInt($allowRedirects, 'max', 'allow_redirects.max');
652 self::warnIfPresentAndNotBool($allowRedirects, 'strict', 'allow_redirects.strict');
653 self::warnIfPresentAndNotBool($allowRedirects, 'referer', 'allow_redirects.referer');
654 self::warnIfPresentAndNotStringArray($allowRedirects, 'protocols', true, 'allow_redirects.protocols');
655 self::warnAboutInvalidProtocolValues($allowRedirects, 'protocols', 'allow_redirects.protocols');
656 self::warnIfPresentAndNotCallable($allowRedirects, 'on_redirect', 'allow_redirects.on_redirect');
657 self::warnIfPresentAndNotBool($allowRedirects, 'track_redirects', 'allow_redirects.track_redirects');
658 }
659
660 /**
661 * @param mixed $auth
662 */
663 private static function warnAboutInvalidAuthOptionTypes($auth): void
664 {
665 if ($auth === false || \is_string($auth) || $auth === []) {
666 return;
667 }
668
669 if (!\is_array($auth)) {
670 self::warnInvalidRequestOptionType('auth', 'array{0: string, 1: string, 2?: string|null}|string|false|null', $auth);
671
672 return;
673 }
674
675 if (!\array_key_exists(0, $auth) || !\is_string($auth[0])) {
676 self::warnInvalidRequestOptionType('auth.0', 'string', $auth[0] ?? null);
677 }
678
679 if (!\array_key_exists(1, $auth) || !\is_string($auth[1])) {
680 self::warnInvalidRequestOptionType('auth.1', 'string', $auth[1] ?? null);
681 }
682
683 if (\array_key_exists(2, $auth) && $auth[2] !== null && !\is_string($auth[2])) {
684 self::warnInvalidRequestOptionType('auth.2', 'string|null', $auth[2]);
685 }
686 }
687
688 /**
689 * @param mixed $value
690 */
691 private static function warnAboutInvalidFormParamTypes($value): void
692 {
693 if (!\is_array($value)) {
694 self::warnInvalidRequestOptionType('form_params', 'array<array-key, string|int|float|bool|null|array>', $value);
695
696 return;
697 }
698
699 self::warnAboutInvalidFormParamArray($value, 'form_params');
700 }
701
702 private static function warnAboutInvalidFormParamArray(array $values, string $path): bool
703 {
704 foreach ($values as $key => $item) {
705 $itemPath = $path.'.'.(string) $key;
706 if (\is_array($item)) {
707 if (!self::warnAboutInvalidFormParamArray($item, $itemPath)) {
708 return false;
709 }
710
711 continue;
712 }
713
714 if ($item !== null && !\is_scalar($item)) {
715 self::warnInvalidRequestOptionType($itemPath, 'string|int|float|bool|null|array', $item);
716
717 return false;
718 }
719 }
720
721 return true;
722 }
723
724 /**
725 * @param mixed $headers
726 */
727 private static function warnAboutInvalidHeaderOptionTypes($headers): void
728 {
729 if (!\is_array($headers)) {
730 self::warnInvalidRequestOptionType('headers', 'array<array-key, string|non-empty-array<array-key, string>>|null', $headers);
731
732 return;
733 }
734
735 foreach ($headers as $name => $value) {
736 $path = 'headers.'.(string) $name;
737 if (\is_array($value)) {
738 if ($value === []) {
739 self::warnInvalidRequestOptionType($path, 'string|non-empty-array<array-key, string>', $value);
740
741 break;
742 }
743
744 foreach ($value as $index => $item) {
745 if (!\is_string($item)) {
746 self::warnInvalidRequestOptionType($path.'.'.(string) $index, 'string', $item);
747
748 break 2;
749 }
750 }
751 } elseif (!\is_string($value)) {
752 self::warnInvalidRequestOptionType($path, 'string|non-empty-array<array-key, string>', $value);
753
754 break;
755 }
756 }
757 }
758
759 /**
760 * @param mixed $multipart
761 */
762 private static function warnAboutInvalidMultipartOptionTypes($multipart): void
763 {
764 if (!\is_array($multipart)) {
765 self::warnInvalidRequestOptionType('multipart', 'array<array-key, array{name: string|int, contents: mixed, headers?: array<array-key, string>, filename?: string}>', $multipart);
766
767 return;
768 }
769
770 foreach ($multipart as $index => $part) {
771 $path = 'multipart.'.(string) $index;
772 if (!\is_array($part)) {
773 self::warnInvalidRequestOptionType($path, 'array{name: string|int, contents: mixed, headers?: array<array-key, string>, filename?: string}', $part);
774
775 return;
776 }
777
778 if (!\array_key_exists('name', $part) || (!\is_string($part['name']) && !\is_int($part['name']))) {
779 self::warnInvalidRequestOptionType($path.'.name', 'string|int', $part['name'] ?? null);
780 }
781
782 if (!\array_key_exists('contents', $part)) {
783 self::warnInvalidRequestOptionType($path, 'array{name: string|int, contents: mixed, headers?: array<array-key, string>, filename?: string}', $part);
784 }
785
786 if (\array_key_exists('headers', $part)) {
787 if (!\is_array($part['headers'])) {
788 self::warnInvalidRequestOptionType($path.'.headers', 'array<array-key, string>', $part['headers']);
789 } else {
790 foreach ($part['headers'] as $name => $value) {
791 if (!\is_string($value)) {
792 self::warnInvalidRequestOptionType($path.'.headers.'.(string) $name, 'string', $value);
793
794 break 2;
795 }
796 }
797 }
798 }
799
800 if (\array_key_exists('filename', $part) && !\is_string($part['filename'])) {
801 self::warnInvalidRequestOptionType($path.'.filename', 'string', $part['filename']);
802 }
803 }
804 }
805
806 private static function warnAboutInvalidProxyOptionTypes(array $options): void
807 {
808 if (!isset($options['proxy'])) {
809 return;
810 }
811
812 if (!\is_string($options['proxy']) && !\is_array($options['proxy'])) {
813 self::warnInvalidRequestOptionType('proxy', 'string|array{http?: string|null, https?: string|null, no?: string|array<array-key, string>|null}', $options['proxy']);
814
815 return;
816 }
817
818 if (!\is_array($options['proxy'])) {
819 return;
820 }
821
822 foreach (['http', 'https'] as $scheme) {
823 if (\array_key_exists($scheme, $options['proxy']) && $options['proxy'][$scheme] !== null && !\is_string($options['proxy'][$scheme])) {
824 self::warnInvalidRequestOptionType('proxy.'.$scheme, 'string|null', $options['proxy'][$scheme]);
825 }
826 }
827
828 if (!\array_key_exists('no', $options['proxy']) || $options['proxy']['no'] === null) {
829 return;
830 }
831
832 if (\is_string($options['proxy']['no'])) {
833 return;
834 }
835
836 if (!\is_array($options['proxy']['no'])) {
837 self::warnInvalidRequestOptionType('proxy.no', 'string|array<array-key, string>|null', $options['proxy']['no']);
838
839 return;
840 }
841
842 foreach ($options['proxy']['no'] as $index => $noProxy) {
843 if (!\is_string($noProxy)) {
844 self::warnInvalidRequestOptionType('proxy.no.'.(string) $index, 'string', $noProxy);
845
846 return;
847 }
848 }
849 }
850
851 private static function warnAboutInvalidTlsFileOptionTypes(array $options, string $option): void
852 {
853 if (!isset($options[$option])) {
854 return;
855 }
856
857 if (\is_string($options[$option])) {
858 return;
859 }
860
861 if (!\is_array($options[$option])) {
862 self::warnInvalidRequestOptionType($option, 'string|array{0: string, 1?: string}', $options[$option]);
863
864 return;
865 }
866
867 if (!\array_key_exists(0, $options[$option]) || !\is_string($options[$option][0])) {
868 self::warnInvalidRequestOptionType($option.'.0', 'string', $options[$option][0] ?? null);
869 }
870
871 if (\array_key_exists(1, $options[$option]) && $options[$option][1] !== null && !\is_string($options[$option][1])) {
872 self::warnInvalidRequestOptionType($option.'.1', 'string|null', $options[$option][1]);
873 }
874 }
875
876 private static function warnIfPresentAndNotArray(array $options, string $option, string $expected): void
877 {
878 if (\array_key_exists($option, $options) && !\is_array($options[$option])) {
879 self::warnInvalidRequestOptionType($option, $expected, $options[$option]);
880 }
881 }
882
883 private static function warnIfPresentAndNotBool(array $options, string $option, ?string $path = null): void
884 {
885 if (\array_key_exists($option, $options) && !\is_bool($options[$option])) {
886 self::warnInvalidRequestOptionType($path ?? $option, 'bool', $options[$option]);
887 }
888 }
889
890 private static function warnIfPresentAndNotBoolOrInt(array $options, string $option): void
891 {
892 if (\array_key_exists($option, $options) && !\is_bool($options[$option]) && !\is_int($options[$option])) {
893 self::warnInvalidRequestOptionType($option, 'bool|int', $options[$option]);
894 }
895 }
896
897 private static function warnIfPresentAndNotBoolOrResource(array $options, string $option): void
898 {
899 if (\array_key_exists($option, $options) && !\is_bool($options[$option]) && !\is_resource($options[$option])) {
900 self::warnInvalidRequestOptionType($option, 'bool|resource', $options[$option]);
901 }
902 }
903
904 private static function warnIfPresentAndNotBoolOrString(array $options, string $option): void
905 {
906 if (\array_key_exists($option, $options) && !\is_bool($options[$option]) && !\is_string($options[$option])) {
907 self::warnInvalidRequestOptionType($option, 'bool|string', $options[$option]);
908 }
909 }
910
911 private static function warnIfPresentAndNotCallable(array $options, string $option, ?string $path = null): void
912 {
913 if (\array_key_exists($option, $options) && !\is_callable($options[$option])) {
914 self::warnInvalidRequestOptionType($path ?? $option, 'callable', $options[$option]);
915 }
916 }
917
918 private static function warnIfPresentAndNotInt(
919 array $options,
920 string $option,
921 ?string $path = null,
922 string $since = '7.11'
923 ): void {
924 if (\array_key_exists($option, $options) && !\is_int($options[$option])) {
925 self::warnInvalidRequestOptionType($path ?? $option, 'int', $options[$option], $since);
926 }
927 }
928
929 private static function warnIfPresentAndNotNumber(array $options, string $option): void
930 {
931 if (\array_key_exists($option, $options) && !\is_int($options[$option]) && !\is_float($options[$option])) {
932 self::warnInvalidRequestOptionType($option, 'int|float', $options[$option]);
933 }
934 }
935
936 private static function warnIfPresentAndNotString(array $options, string $option): void
937 {
938 if (\array_key_exists($option, $options) && !\is_string($options[$option])) {
939 self::warnInvalidRequestOptionType($option, 'string', $options[$option]);
940 }
941 }
942
943 private static function warnIfPresentAndNotStringArray(array $options, string $option, bool $nonEmpty, ?string $path = null): void
944 {
945 if (!\array_key_exists($option, $options)) {
946 return;
947 }
948
949 $path = $path ?? $option;
950 $expected = ($nonEmpty ? 'non-empty-' : '').'array<array-key, string>';
951
952 if (!\is_array($options[$option]) || ($nonEmpty && $options[$option] === [])) {
953 self::warnInvalidRequestOptionType($path, $expected, $options[$option]);
954
955 return;
956 }
957
958 foreach ($options[$option] as $index => $item) {
959 if (!\is_string($item)) {
960 self::warnInvalidRequestOptionType($path.'.'.(string) $index, 'string', $item);
961
962 return;
963 }
964 }
965 }
966
967 /**
968 * @param array<array-key, mixed> $options
969 */
970 private static function warnAboutInvalidProtocolValues(array $options, string $option, ?string $path = null): void
971 {
972 if (!isset($options[$option]) || !\is_array($options[$option])) {
973 return;
974 }
975
976 $path = $path ?? $option;
977
978 foreach ($options[$option] as $index => $protocol) {
979 if (\is_string($protocol) && $protocol !== 'http' && $protocol !== 'https') {
980 self::warnInvalidRequestOptionType($path.'.'.(string) $index, '"http"|"https"', $protocol, '7.13');
981 }
982 }
983 }
984
985 private static function warnIfPresentAndNotStringOrNumber(array $options, string $option): void
986 {
987 if (
988 \array_key_exists($option, $options)
989 && !\is_string($options[$option])
990 && !\is_int($options[$option])
991 && !\is_float($options[$option])
992 ) {
993 self::warnInvalidRequestOptionType($option, 'string|int|float', $options[$option]);
994 }
995 }
996
997 /**
998 * @param mixed $value
999 */
1000 private static function warnInvalidRequestOptionType(string $option, string $expected, $value, string $since = '7.11'): void
1001 {
1002 \trigger_deprecation(
1003 'guzzlehttp/guzzle',
1004 $since,
1005 'Passing %s to request option "%s" is deprecated; guzzlehttp/guzzle 8.0 requires %s.',
1006 \get_debug_type($value),
1007 $option,
1008 $expected
1009 );
1010 }
1011
1012 /**
1013 * Transfers the given request and applies request options.
1014 *
1015 * The URI of the request is not modified and the request options are used
1016 * as-is without merging in default options.
1017 *
1018 * @param array $options See {@see RequestOptions}.
1019 */
1020 private function transfer(RequestInterface $request, array $options): PromiseInterface
1021 {
1022 $request = $this->applyOptions($request, $options);
1023
1024 $protocolVersion = $request->getProtocolVersion();
1025
1026 if ('' === $protocolVersion) {
1027 \trigger_deprecation('guzzlehttp/guzzle', '7.11', 'Sending a request with an empty protocol version is deprecated; guzzlehttp/guzzle 8.0 will reject empty protocol versions.');
1028
1029 $request = Psr7\Utils::modifyRequest($request, ['version' => '1.1']);
1030 } elseif (!self::isProtocolVersionValid($protocolVersion)) {
1031 \trigger_deprecation('guzzlehttp/guzzle', '7.11', 'Sending a request with a malformed protocol version is deprecated; guzzlehttp/guzzle 8.0 will reject malformed protocol versions.');
1032 }
1033
1034 /** @var HandlerStack $handler */
1035 $handler = $options['handler'];
1036
1037 try {
1038 return P\Create::promiseFor($handler($request, $options));
1039 } catch (\Exception $e) {
1040 return P\Create::rejectionFor($e);
1041 }
1042 }
1043
1044 /**
1045 * Applies the array of request options to a request.
1046 */
1047 private function applyOptions(RequestInterface $request, array &$options): RequestInterface
1048 {
1049 $modify = [
1050 'set_headers' => [],
1051 ];
1052
1053 if (isset($options['headers'])) {
1054 if (array_keys($options['headers']) === range(0, count($options['headers']) - 1)) {
1055 throw new InvalidArgumentException('The headers array must have header name as keys.');
1056 }
1057 $headers = $options['headers'];
1058 $droppedHeaderNames = self::castDeprecatedHeaderOptionValues($headers);
1059 if ($droppedHeaderNames !== [] && isset($options['_conditional'])) {
1060 $options['_conditional'] = Psr7\Utils::caselessRemove($droppedHeaderNames, $options['_conditional']);
1061 }
1062 $modify['set_headers'] = $headers;
1063 unset($options['headers']);
1064 }
1065
1066 if (isset($options['form_params'])) {
1067 if (isset($options['multipart'])) {
1068 throw new InvalidArgumentException('You cannot use '
1069 .'form_params and multipart at the same time. Use the '
1070 .'form_params option if you want to send application/'
1071 .'x-www-form-urlencoded requests, and the multipart '
1072 .'option to send multipart/form-data requests.');
1073 }
1074 $options['body'] = \http_build_query(self::normalizeNonFiniteFloats($options['form_params'], 'form_params'), '', '&');
1075 unset($options['form_params']);
1076 // Ensure that we don't have the header in different case and set the new value.
1077 $options['_conditional'] = Psr7\Utils::caselessRemove(['Content-Type'], $options['_conditional']);
1078 $options['_conditional']['Content-Type'] = 'application/x-www-form-urlencoded';
1079 }
1080
1081 if (isset($options['multipart'])) {
1082 $options['body'] = new Psr7\MultipartStream($options['multipart']);
1083 unset($options['multipart']);
1084 }
1085
1086 if (isset($options['json'])) {
1087 $options['body'] = Utils::jsonEncode($options['json']);
1088 unset($options['json']);
1089 // Ensure that we don't have the header in different case and set the new value.
1090 $options['_conditional'] = Psr7\Utils::caselessRemove(['Content-Type'], $options['_conditional']);
1091 $options['_conditional']['Content-Type'] = 'application/json';
1092 }
1093
1094 if (isset($options['decode_content']) && \is_string($options['decode_content'])) {
1095 // Ensure that we don't have the header in different case and set the new value.
1096 $options['_conditional'] = Psr7\Utils::caselessRemove(['Accept-Encoding'], $options['_conditional']);
1097 $modify['set_headers']['Accept-Encoding'] = (string) $options['decode_content'];
1098 }
1099
1100 if (isset($options['body'])) {
1101 if (\is_array($options['body'])) {
1102 throw $this->invalidBody();
1103 }
1104 $modify['body'] = self::createBodyStream($options['body']);
1105 unset($options['body']);
1106 }
1107
1108 if (!empty($options['auth']) && \is_array($options['auth'])) {
1109 $value = $options['auth'];
1110 $type = isset($value[2]) ? \strtolower($value[2]) : 'basic';
1111 switch ($type) {
1112 case 'basic':
1113 // Ensure that we don't have the header in different case and set the new value.
1114 $modify['set_headers'] = Psr7\Utils::caselessRemove(['Authorization'], $modify['set_headers']);
1115 $modify['set_headers']['Authorization'] = 'Basic '
1116 .\base64_encode("$value[0]:$value[1]");
1117 break;
1118 case 'digest':
1119 // @todo: Do not rely on curl
1120 $options['curl'][\CURLOPT_HTTPAUTH] = \CURLAUTH_DIGEST;
1121 $options['curl'][\CURLOPT_USERPWD] = "$value[0]:$value[1]";
1122 break;
1123 case 'ntlm':
1124 \trigger_deprecation(
1125 'guzzlehttp/guzzle',
1126 '7.12',
1127 'Passing "ntlm" as the built-in auth type is deprecated; guzzlehttp/guzzle 8.0 will no longer apply NTLM through the "auth" request option. Configure NTLM with cURL HTTP authentication options instead.'
1128 );
1129 $options['curl'][\CURLOPT_HTTPAUTH] = \CURLAUTH_NTLM;
1130 $options['curl'][\CURLOPT_USERPWD] = "$value[0]:$value[1]";
1131 break;
1132 }
1133 }
1134
1135 if (isset($options['query'])) {
1136 $value = $options['query'];
1137 if (\is_array($value)) {
1138 $value = \http_build_query(self::normalizeNonFiniteFloats($value, 'query'), '', '&', \PHP_QUERY_RFC3986);
1139 }
1140 if (!\is_string($value)) {
1141 throw new InvalidArgumentException('query must be a string or array');
1142 }
1143 $modify['query'] = $value;
1144 unset($options['query']);
1145 }
1146
1147 // Ensure that sink is not an invalid value.
1148 if (isset($options['sink'])) {
1149 // TODO: Add more sink validation?
1150 if (\is_bool($options['sink'])) {
1151 throw new InvalidArgumentException('sink must not be a boolean');
1152 }
1153 }
1154
1155 if (isset($options['version'])) {
1156 $modify['version'] = self::normalizeProtocolVersion($options['version']);
1157 }
1158
1159 $request = Psr7\Utils::modifyRequest($request, $modify);
1160 if ($request->getBody() instanceof Psr7\MultipartStream) {
1161 // Use a multipart/form-data POST if a Content-Type is not set.
1162 // Ensure that we don't have the header in different case and set the new value.
1163 $options['_conditional'] = Psr7\Utils::caselessRemove(['Content-Type'], $options['_conditional']);
1164 $options['_conditional']['Content-Type'] = 'multipart/form-data; boundary='
1165 .$request->getBody()->getBoundary();
1166 }
1167
1168 // Merge in conditional headers if they are not present.
1169 if (isset($options['_conditional'])) {
1170 // Build up the changes so it's in a single clone of the message.
1171 $modify = [];
1172 foreach ($options['_conditional'] as $k => $v) {
1173 $name = (string) $k;
1174 if (!$request->hasHeader($name)) {
1175 $modify['set_headers'][$name] = $v;
1176 }
1177 }
1178 $request = Psr7\Utils::modifyRequest($request, $modify);
1179 // Don't pass this internal value along to middleware/handlers.
1180 unset($options['_conditional']);
1181 }
1182
1183 return $request;
1184 }
1185
1186 /**
1187 * @param array<array-key, mixed> $headers
1188 *
1189 * @return list<string>
1190 */
1191 private static function castDeprecatedHeaderOptionValues(array &$headers): array
1192 {
1193 $droppedHeaderNames = [];
1194
1195 foreach ($headers as $name => $value) {
1196 if (\is_array($value)) {
1197 if ($value === []) {
1198 $droppedHeaderNames[] = (string) $name;
1199 unset($headers[$name]);
1200
1201 continue;
1202 }
1203
1204 foreach ($value as $index => $item) {
1205 if ($item === null || (!\is_string($item) && \is_scalar($item))) {
1206 if (\is_float($item) && !\is_finite($item)) {
1207 $item = \is_nan($item) ? 'NAN' : ($item > 0 ? 'INF' : '-INF');
1208 }
1209 $value[$index] = (string) $item;
1210 }
1211 }
1212
1213 $headers[$name] = $value;
1214
1215 continue;
1216 }
1217
1218 if ($value === null || (!\is_string($value) && \is_scalar($value))) {
1219 if (\is_float($value) && !\is_finite($value)) {
1220 $value = \is_nan($value) ? 'NAN' : ($value > 0 ? 'INF' : '-INF');
1221 }
1222 $headers[$name] = (string) $value;
1223 }
1224 }
1225
1226 return $droppedHeaderNames;
1227 }
1228
1229 /**
1230 * @param mixed $body
1231 */
1232 private static function createBodyStream($body): StreamInterface
1233 {
1234 if ($body instanceof StreamInterface) {
1235 return $body;
1236 }
1237
1238 if (\is_resource($body) || $body === null || \is_string($body) || $body instanceof \Iterator) {
1239 return Psr7\Utils::streamFor($body);
1240 }
1241
1242 if (\is_scalar($body)) {
1243 \trigger_deprecation('guzzlehttp/guzzle', '7.12', 'Passing a non-string scalar to the "body" request option is deprecated; guzzlehttp/guzzle 8.0 will reject non-string scalar bodies.');
1244
1245 return Psr7\Utils::streamFor(self::stringifyScalar($body));
1246 }
1247
1248 if (\is_object($body) && \method_exists($body, '__toString')) {
1249 return Psr7\Utils::streamFor((string) $body);
1250 }
1251
1252 if (\is_callable($body)) {
1253 return Psr7\Utils::streamFor($body);
1254 }
1255
1256 throw new InvalidArgumentException(\sprintf(
1257 'Passing %s to request option "body" is invalid; expected resource|string|null|int|float|bool|StreamInterface|callable&object|Iterator|Stringable.',
1258 \get_debug_type($body)
1259 ));
1260 }
1261
1262 /**
1263 * @param bool|float|int|string $value
1264 */
1265 private static function stringifyScalar($value): string
1266 {
1267 // Normalize non-finite floats to dodge PHP 8.5's (string) NAN
1268 // coercion warning while the value is still accepted.
1269 if (\is_float($value) && !\is_finite($value)) {
1270 $value = \is_nan($value) ? 'NAN' : ($value > 0 ? 'INF' : '-INF');
1271 }
1272
1273 return (string) $value;
1274 }
1275
1276 /**
1277 * Converts non-finite floats in the array to the strings PHP coerces
1278 * them to, as implicit coercion of NAN emits a warning on PHP 8.5.
1279 */
1280 private static function normalizeNonFiniteFloats(array $values, string $option): array
1281 {
1282 foreach ($values as $key => $value) {
1283 if (\is_array($value)) {
1284 $values[$key] = self::normalizeNonFiniteFloats($value, $option);
1285 } elseif (\is_float($value) && !\is_finite($value)) {
1286 \trigger_deprecation('guzzlehttp/guzzle', '7.12', 'Passing a non-finite float in the "%s" request option is deprecated; guzzlehttp/guzzle 8.0 will reject non-finite floats.', $option);
1287
1288 $values[$key] = \is_nan($value) ? 'NAN' : ($value > 0 ? 'INF' : '-INF');
1289 }
1290 }
1291
1292 return $values;
1293 }
1294
1295 /**
1296 * @param string|int|float $version
1297 */
1298 private static function normalizeProtocolVersion($version): string
1299 {
1300 if ('' === $version) {
1301 \trigger_deprecation('guzzlehttp/guzzle', '7.11', 'Passing an empty "version" request option is deprecated; guzzlehttp/guzzle 8.0 will reject empty protocol versions.');
1302
1303 return '1.1';
1304 }
1305
1306 return \is_float($version) ? \number_format($version, 1, '.', '') : (string) $version;
1307 }
1308
1309 private static function isProtocolVersionValid(string $version): bool
1310 {
1311 return 1 === \preg_match('/^\d+(?:\.\d+)?$/D', $version);
1312 }
1313
1314 /**
1315 * Return an InvalidArgumentException with pre-set message.
1316 */
1317 private function invalidBody(): InvalidArgumentException
1318 {
1319 return new InvalidArgumentException('Passing in the "body" request '
1320 .'option as an array to send a request is not supported. '
1321 .'Please use the "form_params" request option to send a '
1322 .'application/x-www-form-urlencoded request, or the "multipart" '
1323 .'request option to send a multipart/form-data request.');
1324 }
1325 }