[HttpClient] throw clearer error when no scheme is provided
This commit is contained in:
parent
7882c4a0b1
commit
4d821d6c34
@ -377,6 +377,10 @@ trait HttpClientTrait
|
|||||||
throw new InvalidArgumentException(sprintf('Invalid "base_uri" option: host or scheme is missing in "%s".', implode('', $base)));
|
throw new InvalidArgumentException(sprintf('Invalid "base_uri" option: host or scheme is missing in "%s".', implode('', $base)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null === $url['scheme'] && (null === $base || null === $base['scheme'])) {
|
||||||
|
throw new InvalidArgumentException(sprintf('Invalid URL: scheme is missing in "%s". Did you forget to add "http(s)://"?', implode('', $base ?? $url)));
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $base && '' === $url['scheme'].$url['authority']) {
|
if (null === $base && '' === $url['scheme'].$url['authority']) {
|
||||||
throw new InvalidArgumentException(sprintf('Invalid URL: no "base_uri" option was provided and host or scheme is missing in "%s".', implode('', $url)));
|
throw new InvalidArgumentException(sprintf('Invalid URL: no "base_uri" option was provided and host or scheme is missing in "%s".', implode('', $url)));
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\HttpClient\Tests;
|
namespace Symfony\Component\HttpClient\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\HttpClient\HttpClientTrait;
|
use Symfony\Component\HttpClient\HttpClientTrait;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
@ -120,6 +121,20 @@ class HttpClientTraitTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResolveUrlWithoutScheme()
|
||||||
|
{
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('Invalid URL: scheme is missing in "//localhost:8080". Did you forget to add "http(s)://"?');
|
||||||
|
self::resolveUrl(self::parseUrl('localhost:8080'), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testResolveBaseUrlWitoutScheme()
|
||||||
|
{
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('Invalid URL: scheme is missing in "//localhost:8081". Did you forget to add "http(s)://"?');
|
||||||
|
self::resolveUrl(self::parseUrl('/foo'), self::parseUrl('localhost:8081'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideParseUrl
|
* @dataProvider provideParseUrl
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user