Skip to content

Commit

Permalink
Use Guzzle to resolve the URL against the base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
joke2k committed Jun 13, 2024
1 parent 83e28d0 commit 95c1501
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,10 +886,6 @@ public function pool(callable $callback)
*/
public function send(string $method, string $url, array $options = [])
{
if (! Str::startsWith($url, ['http://', 'https://'])) {
$url = ltrim(rtrim($this->baseUrl, '/').'/'.ltrim($url, '/'), '/');
}

$url = $this->expandUrlParameters($url);

$options = $this->parseHttpOptions($options);
Expand Down Expand Up @@ -966,6 +962,10 @@ protected function expandUrlParameters(string $url)
*/
protected function parseHttpOptions(array $options)
{
if ($this->baseUrl && ! isset($options['base_uri'])) {
$options['base_uri'] = $this->baseUrl;
}

if (isset($options[$this->bodyFormat])) {
if ($this->bodyFormat === 'multipart') {
$options[$this->bodyFormat] = $this->parseMultipartBodyFormat($options[$this->bodyFormat]);
Expand Down
61 changes: 50 additions & 11 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,23 +985,62 @@ public function testGetWithArrayQueryParamEncodes()
});
}

public function testWithBaseUrl()
/**
* @dataProvider baseUriWithRefProvider
*/
public function testWithBaseUrl(string $baseUri, string $ref, string $expectedResolvedUri)
{
$this->factory->fake();

$this->factory->baseUrl('http://foo.com/')->get('get');
$this->factory->baseUrl($baseUri)->get($ref);

$this->factory->assertSent(function (Request $request) {
return $request->url() === 'http://foo.com/get';
$this->factory->assertSent(function (Request $request) use ($expectedResolvedUri) {
return $request->url() === $expectedResolvedUri;
});
}

$this->factory->fake();

$this->factory->baseUrl('http://foo.com/')->get('http://bar.com/get');

$this->factory->assertSent(function (Request $request) {
return $request->url() === 'http://bar.com/get';
});
/**
* @return array
*/
public static function baseUriWithRefProvider()
{
return [
[
'',
'bar',
'bar'
],
[
'http://foo.com',
'/bar',
'http://foo.com/bar'
],
[
'http://foo.com/foo',
'/bar',
'http://foo.com/bar'
],
[
'http://foo.com/foo',
'bar',
'http://foo.com/bar'
],
[
'http://foo.com/foo/',
'bar',
'http://foo.com/foo/bar'
],
[
'http://foo.com',
'http://baz.com',
'http://baz.com'
],
[
'http://foo.com/?bar',
'bar',
'http://foo.com/bar'
],
];
}

public function testCanConfirmManyHeaders()
Expand Down

0 comments on commit 95c1501

Please sign in to comment.