Skip to content

Commit

Permalink
attempt to merge smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 12, 2022
1 parent 5a8585a commit 30e341b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Http\Client\Events\ConnectionFailed;
use Illuminate\Http\Client\Events\RequestSending;
use Illuminate\Http\Client\Events\ResponseReceived;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Conditionable;
Expand Down Expand Up @@ -148,6 +149,20 @@ class PendingRequest
*/
protected $request;

/**
* The Guzzle request options that are mergable via array_merge_recursive.
*
* @var array
*/
protected $mergableOptions = [
'cookies',
'form_params',
'headers',
'json',
'multipart',
'query',
];

/**
* Create a new HTTP Client instance.
*
Expand Down Expand Up @@ -472,7 +487,10 @@ public function retry(int $times, int $sleep = 0, ?callable $when = null)
public function withOptions(array $options)
{
return tap($this, function ($request) use ($options) {
return $this->options = array_replace_recursive($this->options, $options);
return $this->options = array_replace_recursive(
array_merge_recursive($this->options, Arr::only($options, $this->mergableOptions)),
$options
);
});
}

Expand Down Expand Up @@ -987,7 +1005,10 @@ public function runBeforeSendingCallbacks($request, array $options)
*/
public function mergeOptions(...$options)
{
return array_replace_recursive($this->options, ...$options);
return array_replace_recursive(
array_merge_recursive($this->options, Arr::only($options, $this->mergableOptions)),
...$options
);
}

/**
Expand Down

1 comment on commit 30e341b

@mohammadsaleh
Copy link

@mohammadsaleh mohammadsaleh commented on 30e341b Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this changes caused problem when using withOptions with Get method.
https://laravel.com/docs/9.x/http-client#guzzle-options

json data doesn't send

Please sign in to comment.