Skip to content

Commit 78d761e

Browse files
committed
Merge branch 'stevebauman-master'
2 parents 9191d2c + ad32489 commit 78d761e

File tree

3 files changed

+62
-17
lines changed

3 files changed

+62
-17
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@
164164
"symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0)."
165165
},
166166
"config": {
167-
"sort-packages": true
167+
"sort-packages": true,
168+
"allow-plugins": {
169+
"composer/package-versions-deprecated": true
170+
}
168171
},
169172
"minimum-stability": "dev",
170173
"prefer-stable": true

src/Illuminate/Http/Client/PendingRequest.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public function head(string $url, $query = null)
581581
* @param array $data
582582
* @return \Illuminate\Http\Client\Response
583583
*/
584-
public function post(string $url, array $data = [])
584+
public function post(string $url, $data = [])
585585
{
586586
return $this->send('POST', $url, [
587587
$this->bodyFormat => $data,
@@ -663,21 +663,7 @@ public function send(string $method, string $url, array $options = [])
663663
{
664664
$url = ltrim(rtrim($this->baseUrl, '/').'/'.ltrim($url, '/'), '/');
665665

666-
if (isset($options[$this->bodyFormat])) {
667-
if ($this->bodyFormat === 'multipart') {
668-
$options[$this->bodyFormat] = $this->parseMultipartBodyFormat($options[$this->bodyFormat]);
669-
} elseif ($this->bodyFormat === 'body') {
670-
$options[$this->bodyFormat] = $this->pendingBody;
671-
}
672-
673-
if (is_array($options[$this->bodyFormat])) {
674-
$options[$this->bodyFormat] = array_merge(
675-
$options[$this->bodyFormat], $this->pendingFiles
676-
);
677-
}
678-
} else {
679-
$options[$this->bodyFormat] = $this->pendingBody;
680-
}
666+
$options = $this->parseHttpOptions($options);
681667

682668
[$this->pendingBody, $this->pendingFiles] = [null, []];
683669

@@ -704,6 +690,33 @@ public function send(string $method, string $url, array $options = [])
704690
}, $this->retryDelay ?? 100, $this->retryWhenCallback);
705691
}
706692

693+
/**
694+
* Parse the given HTTP options and set the appropriate additional options.
695+
*
696+
* @param array $options
697+
* @return array
698+
*/
699+
protected function parseHttpOptions(array $options)
700+
{
701+
if (isset($options[$this->bodyFormat])) {
702+
if ($this->bodyFormat === 'multipart') {
703+
$options[$this->bodyFormat] = $this->parseMultipartBodyFormat($options[$this->bodyFormat]);
704+
} elseif ($this->bodyFormat === 'body') {
705+
$options[$this->bodyFormat] = $this->pendingBody;
706+
}
707+
708+
if (is_array($options[$this->bodyFormat])) {
709+
$options[$this->bodyFormat] = array_merge(
710+
$options[$this->bodyFormat], $this->pendingFiles
711+
);
712+
}
713+
} else {
714+
$options[$this->bodyFormat] = $this->pendingBody;
715+
}
716+
717+
return collect($options)->toArray();
718+
}
719+
707720
/**
708721
* Parse multi-part form data.
709722
*

tests/Http/HttpClientTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Illuminate\Http\Client\Response;
1616
use Illuminate\Http\Client\ResponseSequence;
1717
use Illuminate\Support\Collection;
18+
use Illuminate\Support\Fluent;
1819
use Illuminate\Support\Str;
1920
use Mockery as m;
2021
use OutOfBoundsException;
@@ -180,6 +181,22 @@ public function testCanSendFormData()
180181
});
181182
}
182183

184+
public function testCanSendArrayableFormData()
185+
{
186+
$this->factory->fake();
187+
188+
$this->factory->asForm()->post('http://foo.com/form', new Fluent([
189+
'name' => 'Taylor',
190+
'title' => 'Laravel Developer',
191+
]));
192+
193+
$this->factory->assertSent(function (Request $request) {
194+
return $request->url() === 'http://foo.com/form' &&
195+
$request->hasHeader('Content-Type', 'application/x-www-form-urlencoded') &&
196+
$request['name'] === 'Taylor';
197+
});
198+
}
199+
183200
public function testSpecificRequestIsNotBeingSent()
184201
{
185202
$this->factory->fake();
@@ -435,6 +452,18 @@ public function testGetWithArrayQueryParam()
435452
});
436453
}
437454

455+
public function testGetWithArrayableQueryParam()
456+
{
457+
$this->factory->fake();
458+
459+
$this->factory->get('http://foo.com/get', new Fluent(['foo' => 'bar']));
460+
461+
$this->factory->assertSent(function (Request $request) {
462+
return $request->url() === 'http://foo.com/get?foo=bar'
463+
&& $request['foo'] === 'bar';
464+
});
465+
}
466+
438467
public function testGetWithStringQueryParam()
439468
{
440469
$this->factory->fake();

0 commit comments

Comments
 (0)