Skip to content

Commit 30e341b

Browse files
committed
attempt to merge smarter
1 parent 5a8585a commit 30e341b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Illuminate/Http/Client/PendingRequest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Http\Client\Events\ConnectionFailed;
1212
use Illuminate\Http\Client\Events\RequestSending;
1313
use Illuminate\Http\Client\Events\ResponseReceived;
14+
use Illuminate\Support\Arr;
1415
use Illuminate\Support\Collection;
1516
use Illuminate\Support\Str;
1617
use Illuminate\Support\Traits\Conditionable;
@@ -148,6 +149,20 @@ class PendingRequest
148149
*/
149150
protected $request;
150151

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+
151166
/**
152167
* Create a new HTTP Client instance.
153168
*
@@ -472,7 +487,10 @@ public function retry(int $times, int $sleep = 0, ?callable $when = null)
472487
public function withOptions(array $options)
473488
{
474489
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+
);
476494
});
477495
}
478496

@@ -987,7 +1005,10 @@ public function runBeforeSendingCallbacks($request, array $options)
9871005
*/
9881006
public function mergeOptions(...$options)
9891007
{
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+
);
9911012
}
9921013

9931014
/**

0 commit comments

Comments
 (0)