Merge pull request #9296 from paulbalandan/curl-base-uri

refactor: use `baseURI` instead of `base_uri`
This commit is contained in:
John Paul E. Balandan, CPA 2024-12-02 00:20:03 +08:00 committed by GitHub
commit 4c8b78215e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 55 deletions

View File

@ -211,7 +211,7 @@ class Services extends BaseService
return new CURLRequest(
$config,
new URI($options['base_uri'] ?? null),
new URI($options['baseURI'] ?? null),
$response,
$options
);

View File

@ -356,9 +356,9 @@ class ContentSecurityPolicy
}
/**
* Adds a new base_uri value. Can be either a URI class or a simple string.
* Adds a new baseURI value. Can be either a URI class or a simple string.
*
* base_uri restricts the URLs that can appear in a page's <base> element.
* baseURI restricts the URLs that can appear in a page's <base> element.
*
* @see http://www.w3.org/TR/CSP/#directive-base-uri
*

View File

@ -30,7 +30,7 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
{
protected function getRequest(array $options = []): MockCURLRequest
{
$uri = isset($options['base_uri']) ? new URI($options['base_uri']) : new URI();
$uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI();
$app = new App();
$config = new ConfigCURLRequest();
@ -43,7 +43,7 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
public function testHeaderContentLengthNotSharedBetweenRequests(): void
{
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://www.foo.com/api/v1/',
];
$request = $this->getRequest($options);
@ -61,8 +61,8 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
public function testBodyIsResetOnSecondRequest(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setBody('name=George');
$request->setOutput('Hi there');

View File

@ -47,7 +47,7 @@ class CURLRequestTest extends CIUnitTestCase
*/
protected function getRequest(array $options = []): MockCURLRequest
{
$uri = isset($options['base_uri']) ? new URI($options['base_uri']) : new URI();
$uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI();
$app = new App();
$config = new ConfigCURLRequest();
@ -64,7 +64,7 @@ class CURLRequestTest extends CIUnitTestCase
{
config('App')->baseURL = 'http://example.com/fruit/';
$request = $this->getRequest(['base_uri' => 'http://example.com/v1/']);
$request = $this->getRequest(['baseURI' => 'http://example.com/v1/']);
$method = $this->getPrivateMethodInvoker($request, 'prepareURL');
@ -76,7 +76,7 @@ class CURLRequestTest extends CIUnitTestCase
*/
public function testGetRemembersBaseURI(): void
{
$request = $this->getRequest(['base_uri' => 'http://www.foo.com/api/v1/']);
$request = $this->getRequest(['baseURI' => 'http://www.foo.com/api/v1/']);
$request->get('products');
@ -90,7 +90,7 @@ class CURLRequestTest extends CIUnitTestCase
*/
public function testGetRemembersBaseURIWithHelperMethod(): void
{
$request = Services::curlrequest(['base_uri' => 'http://www.foo.com/api/v1/']);
$request = Services::curlrequest(['baseURI' => 'http://www.foo.com/api/v1/']);
$uri = $this->getPrivateProperty($request, 'baseURI');
$this->assertSame('www.foo.com', $uri->getHost());
@ -157,28 +157,17 @@ class CURLRequestTest extends CIUnitTestCase
public function testOptionsBaseURIOption(): void
{
$options = ['base_uri' => 'http://www.foo.com/api/v1/'];
$options = ['baseURI' => 'http://www.foo.com/api/v1/'];
$request = $this->getRequest($options);
$this->assertSame('http://www.foo.com/api/v1/', $request->getBaseURI()->__toString());
}
public function testOptionsBaseURIOverride(): void
{
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://bogus/com',
];
$request = $this->getRequest($options);
$this->assertSame('http://bogus/com', $request->getBaseURI()->__toString());
}
public function testOptionsHeaders(): void
{
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'headers' => ['fruit' => 'apple'],
'baseURI' => 'http://www.foo.com/api/v1/',
'headers' => ['fruit' => 'apple'],
];
$request = $this->getRequest();
$this->assertNull($request->header('fruit'));
@ -195,8 +184,8 @@ class CURLRequestTest extends CIUnitTestCase
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, br';
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'headers' => [
'baseURI' => 'http://www.foo.com/api/v1/',
'headers' => [
'Host' => 'www.foo.com',
'Accept-Encoding' => '',
],
@ -233,7 +222,7 @@ class CURLRequestTest extends CIUnitTestCase
public function testHeaderContentLengthNotSharedBetweenRequests(): void
{
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://www.foo.com/api/v1/',
];
$request = $this->getRequest($options);
@ -253,7 +242,7 @@ class CURLRequestTest extends CIUnitTestCase
$_SERVER['HTTP_CONTENT_LENGTH'] = '10';
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://www.foo.com/api/v1/',
];
$request = $this->getRequest($options);
$request->post('example', [
@ -730,8 +719,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
public function testSendWithQuery(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'query' => [
'baseURI' => 'http://www.foo.com/api/v1/',
'query' => [
'name' => 'Henry',
'd.t' => 'value',
],
@ -747,8 +736,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
public function testSendWithDelay(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->get('products');
@ -760,8 +749,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
public function testSendContinued(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setOutput("HTTP/1.1 100 Continue\x0d\x0a\x0d\x0aHi there");
@ -775,8 +764,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
public function testSendContinuedWithManyHeaders(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$output = "HTTP/1.1 100 Continue
@ -819,8 +808,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
public function testSendProxied(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$output = "HTTP/1.1 200 Connection established
@ -834,8 +823,8 @@ Proxy-Agent: Fortinet-Proxy/1.0\x0d\x0a\x0d\x0aHTTP/1.1 200 OK\x0d\x0a\x0d\x0aHi
public function testSendProxiedWithHTTP10(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$output = "HTTP/1.0 200 Connection established
@ -852,7 +841,7 @@ Proxy-Agent: Fortinet-Proxy/1.0\x0d\x0a\x0d\x0aHTTP/1.1 200 OK\x0d\x0a\x0d\x0aHi
public function testResponseHeadersWithMultipleRequests(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://www.foo.com/api/v1/',
]);
$output = "HTTP/2.0 200 OK
@ -905,7 +894,7 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Hello2</title>";
public function testResponseHeadersWithMultipleSetCookies(): void
{
$request = $this->getRequest([
'base_uri' => 'https://github.com/',
'baseURI' => 'https://github.com/',
]);
$output = "HTTP/2 200
@ -937,8 +926,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
public function testSplitResponse(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setOutput("Accept: text/html\x0d\x0a\x0d\x0aHi there");
@ -949,8 +938,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
public function testApplyBody(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setBody('name=George');
@ -964,8 +953,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
public function testApplyBodyByOptions(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setOutput('Hi there');
@ -980,8 +969,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
public function testBodyIsResetOnSecondRequest(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setBody('name=George');
$request->setOutput('Hi there');
@ -995,8 +984,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
public function testResponseHeaders(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setOutput("HTTP/2.0 234 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there");
@ -1009,8 +998,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
public function testResponseHeadersShortProtocol(): void
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 100,
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setOutput("HTTP/2 235 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there shortie");