mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #9296 from paulbalandan/curl-base-uri
refactor: use `baseURI` instead of `base_uri`
This commit is contained in:
commit
4c8b78215e
@ -211,7 +211,7 @@ class Services extends BaseService
|
|||||||
|
|
||||||
return new CURLRequest(
|
return new CURLRequest(
|
||||||
$config,
|
$config,
|
||||||
new URI($options['base_uri'] ?? null),
|
new URI($options['baseURI'] ?? null),
|
||||||
$response,
|
$response,
|
||||||
$options
|
$options
|
||||||
);
|
);
|
||||||
|
@ -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
|
* @see http://www.w3.org/TR/CSP/#directive-base-uri
|
||||||
*
|
*
|
||||||
|
@ -30,7 +30,7 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
|
|||||||
{
|
{
|
||||||
protected function getRequest(array $options = []): MockCURLRequest
|
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();
|
$app = new App();
|
||||||
|
|
||||||
$config = new ConfigCURLRequest();
|
$config = new ConfigCURLRequest();
|
||||||
@ -43,7 +43,7 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
|
|||||||
public function testHeaderContentLengthNotSharedBetweenRequests(): void
|
public function testHeaderContentLengthNotSharedBetweenRequests(): void
|
||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
];
|
];
|
||||||
$request = $this->getRequest($options);
|
$request = $this->getRequest($options);
|
||||||
|
|
||||||
@ -61,8 +61,8 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest
|
|||||||
public function testBodyIsResetOnSecondRequest(): void
|
public function testBodyIsResetOnSecondRequest(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
$request->setBody('name=George');
|
$request->setBody('name=George');
|
||||||
$request->setOutput('Hi there');
|
$request->setOutput('Hi there');
|
||||||
|
@ -47,7 +47,7 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
*/
|
*/
|
||||||
protected function getRequest(array $options = []): MockCURLRequest
|
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();
|
$app = new App();
|
||||||
|
|
||||||
$config = new ConfigCURLRequest();
|
$config = new ConfigCURLRequest();
|
||||||
@ -64,7 +64,7 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
{
|
{
|
||||||
config('App')->baseURL = 'http://example.com/fruit/';
|
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');
|
$method = $this->getPrivateMethodInvoker($request, 'prepareURL');
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetRemembersBaseURI(): void
|
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');
|
$request->get('products');
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetRemembersBaseURIWithHelperMethod(): void
|
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');
|
$uri = $this->getPrivateProperty($request, 'baseURI');
|
||||||
$this->assertSame('www.foo.com', $uri->getHost());
|
$this->assertSame('www.foo.com', $uri->getHost());
|
||||||
@ -157,28 +157,17 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
|
|
||||||
public function testOptionsBaseURIOption(): void
|
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);
|
$request = $this->getRequest($options);
|
||||||
|
|
||||||
$this->assertSame('http://www.foo.com/api/v1/', $request->getBaseURI()->__toString());
|
$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
|
public function testOptionsHeaders(): void
|
||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'headers' => ['fruit' => 'apple'],
|
'headers' => ['fruit' => 'apple'],
|
||||||
];
|
];
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$this->assertNull($request->header('fruit'));
|
$this->assertNull($request->header('fruit'));
|
||||||
@ -195,8 +184,8 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, br';
|
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, br';
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Host' => 'www.foo.com',
|
'Host' => 'www.foo.com',
|
||||||
'Accept-Encoding' => '',
|
'Accept-Encoding' => '',
|
||||||
],
|
],
|
||||||
@ -233,7 +222,7 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
public function testHeaderContentLengthNotSharedBetweenRequests(): void
|
public function testHeaderContentLengthNotSharedBetweenRequests(): void
|
||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
];
|
];
|
||||||
$request = $this->getRequest($options);
|
$request = $this->getRequest($options);
|
||||||
|
|
||||||
@ -253,7 +242,7 @@ class CURLRequestTest extends CIUnitTestCase
|
|||||||
$_SERVER['HTTP_CONTENT_LENGTH'] = '10';
|
$_SERVER['HTTP_CONTENT_LENGTH'] = '10';
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
];
|
];
|
||||||
$request = $this->getRequest($options);
|
$request = $this->getRequest($options);
|
||||||
$request->post('example', [
|
$request->post('example', [
|
||||||
@ -730,8 +719,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
|
|||||||
public function testSendWithQuery(): void
|
public function testSendWithQuery(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'query' => [
|
'query' => [
|
||||||
'name' => 'Henry',
|
'name' => 'Henry',
|
||||||
'd.t' => 'value',
|
'd.t' => 'value',
|
||||||
],
|
],
|
||||||
@ -747,8 +736,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
|
|||||||
public function testSendWithDelay(): void
|
public function testSendWithDelay(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->get('products');
|
$request->get('products');
|
||||||
@ -760,8 +749,8 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>"
|
|||||||
public function testSendContinued(): void
|
public function testSendContinued(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->setOutput("HTTP/1.1 100 Continue\x0d\x0a\x0d\x0aHi there");
|
$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
|
public function testSendContinuedWithManyHeaders(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$output = "HTTP/1.1 100 Continue
|
$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
|
public function testSendProxied(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$output = "HTTP/1.1 200 Connection established
|
$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
|
public function testSendProxiedWithHTTP10(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$output = "HTTP/1.0 200 Connection established
|
$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
|
public function testResponseHeadersWithMultipleRequests(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$output = "HTTP/2.0 200 OK
|
$output = "HTTP/2.0 200 OK
|
||||||
@ -905,7 +894,7 @@ Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Hello2</title>";
|
|||||||
public function testResponseHeadersWithMultipleSetCookies(): void
|
public function testResponseHeadersWithMultipleSetCookies(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'https://github.com/',
|
'baseURI' => 'https://github.com/',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$output = "HTTP/2 200
|
$output = "HTTP/2 200
|
||||||
@ -937,8 +926,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
|
|||||||
public function testSplitResponse(): void
|
public function testSplitResponse(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->setOutput("Accept: text/html\x0d\x0a\x0d\x0aHi there");
|
$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
|
public function testApplyBody(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->setBody('name=George');
|
$request->setBody('name=George');
|
||||||
@ -964,8 +953,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
|
|||||||
public function testApplyBodyByOptions(): void
|
public function testApplyBodyByOptions(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->setOutput('Hi there');
|
$request->setOutput('Hi there');
|
||||||
@ -980,8 +969,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
|
|||||||
public function testBodyIsResetOnSecondRequest(): void
|
public function testBodyIsResetOnSecondRequest(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
$request->setBody('name=George');
|
$request->setBody('name=George');
|
||||||
$request->setOutput('Hi there');
|
$request->setOutput('Hi there');
|
||||||
@ -995,8 +984,8 @@ accept-ranges: bytes\x0d\x0a\x0d\x0a";
|
|||||||
public function testResponseHeaders(): void
|
public function testResponseHeaders(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->setOutput("HTTP/2.0 234 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there");
|
$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
|
public function testResponseHeadersShortProtocol(): void
|
||||||
{
|
{
|
||||||
$request = $this->getRequest([
|
$request = $this->getRequest([
|
||||||
'base_uri' => 'http://www.foo.com/api/v1/',
|
'baseURI' => 'http://www.foo.com/api/v1/',
|
||||||
'delay' => 100,
|
'delay' => 100,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$request->setOutput("HTTP/2 235 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there shortie");
|
$request->setOutput("HTTP/2 235 Ohoh\x0d\x0aAccept: text/html\x0d\x0a\x0d\x0aHi there shortie");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user