|
11 | 11 | use Illuminate\Http\Client\Events\ConnectionFailed;
|
12 | 12 | use Illuminate\Http\Client\Events\RequestSending;
|
13 | 13 | use Illuminate\Http\Client\Events\ResponseReceived;
|
| 14 | +use Illuminate\Support\Arr; |
14 | 15 | use Illuminate\Support\Collection;
|
15 | 16 | use Illuminate\Support\Str;
|
16 | 17 | use Illuminate\Support\Traits\Conditionable;
|
@@ -148,6 +149,20 @@ class PendingRequest
|
148 | 149 | */
|
149 | 150 | protected $request;
|
150 | 151 |
|
| 152 | + /** |
| 153 | + * The Guzzle request options that are mergable via array_merge_recursive. |
| 154 | + * |
| 155 | + * @var array |
| 156 | + */ |
| 157 | + protected $mergableOptions = [ |
| 158 | + 'cookies', |
| 159 | + 'form_params', |
| 160 | + 'headers', |
| 161 | + 'json', |
| 162 | + 'multipart', |
| 163 | + 'query', |
| 164 | + ]; |
| 165 | + |
151 | 166 | /**
|
152 | 167 | * Create a new HTTP Client instance.
|
153 | 168 | *
|
@@ -472,7 +487,10 @@ public function retry(int $times, int $sleep = 0, ?callable $when = null)
|
472 | 487 | public function withOptions(array $options)
|
473 | 488 | {
|
474 | 489 | return tap($this, function ($request) use ($options) {
|
475 |
| - return $this->options = array_replace_recursive($this->options, $options); |
| 490 | + return $this->options = array_replace_recursive( |
| 491 | + array_merge_recursive($this->options, Arr::only($options, $this->mergableOptions)), |
| 492 | + $options |
| 493 | + ); |
476 | 494 | });
|
477 | 495 | }
|
478 | 496 |
|
@@ -987,7 +1005,10 @@ public function runBeforeSendingCallbacks($request, array $options)
|
987 | 1005 | */
|
988 | 1006 | public function mergeOptions(...$options)
|
989 | 1007 | {
|
990 |
| - return array_replace_recursive($this->options, ...$options); |
| 1008 | + return array_replace_recursive( |
| 1009 | + array_merge_recursive($this->options, Arr::only($options, $this->mergableOptions)), |
| 1010 | + ...$options |
| 1011 | + ); |
991 | 1012 | }
|
992 | 1013 |
|
993 | 1014 | /**
|
|
0 commit comments