Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use baseURI instead of base_uri #9296

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static function curlrequest(array $options = [], ?ResponseInterface $resp

return new CURLRequest(
$config,
new URI($options['base_uri'] ?? null),
new URI($options['baseURI'] ?? null),
$response,
$options
);
Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/ContentSecurityPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ public function reportOnly(bool $value = true)
}

/**
* 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
*
Expand Down
8 changes: 4 additions & 4 deletions tests/system/HTTP/CURLRequestShareOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -43,7 +43,7 @@ protected function getRequest(array $options = []): MockCURLRequest
public function testHeaderContentLengthNotSharedBetweenRequests(): void
{
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://www.foo.com/api/v1/',
];
$request = $this->getRequest($options);

Expand All @@ -61,8 +61,8 @@ public function testHeaderContentLengthNotSharedBetweenRequests(): void
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');
Expand Down
85 changes: 37 additions & 48 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function setUp(): void
*/
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();
Expand All @@ -64,7 +64,7 @@ public function testPrepareURLIgnoresAppConfig(): void
{
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');

Expand All @@ -76,7 +76,7 @@ public function testPrepareURLIgnoresAppConfig(): 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');

Expand All @@ -90,7 +90,7 @@ public function testGetRemembersBaseURI(): 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');
$this->assertSame('www.foo.com', $uri->getHost());
Expand Down Expand Up @@ -157,28 +157,17 @@ public function testOptionsSetsCorrectMethod(): 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);

$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'));
Expand All @@ -195,8 +184,8 @@ public function testOptionsHeadersNotUsingPopulate(): void
$_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' => '',
],
Expand Down Expand Up @@ -233,7 +222,7 @@ public function testDefaultOptionsAreSharedBetweenRequests(): void
public function testHeaderContentLengthNotSharedBetweenRequests(): void
{
$options = [
'base_uri' => 'http://www.foo.com/api/v1/',
'baseURI' => 'http://www.foo.com/api/v1/',
];
$request = $this->getRequest($options);

Expand All @@ -253,7 +242,7 @@ public function testHeaderContentLengthNotSharedBetweenClients(): void
$_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', [
Expand Down Expand Up @@ -730,8 +719,8 @@ public function testAllowRedirectsArray(): void
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',
],
Expand All @@ -747,8 +736,8 @@ public function testSendWithQuery(): void
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');
Expand All @@ -760,8 +749,8 @@ public function testSendWithDelay(): void
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");
Expand All @@ -775,8 +764,8 @@ public function testSendContinued(): void
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
Expand Down Expand Up @@ -819,8 +808,8 @@ public function testSendContinuedWithManyHeaders(): void
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
Expand All @@ -834,8 +823,8 @@ public function testSendProxied(): void
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
Expand All @@ -852,7 +841,7 @@ public function testSendProxiedWithHTTP10(): void
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
Expand Down Expand Up @@ -905,7 +894,7 @@ public function testResponseHeadersWithMultipleRequests(): void
public function testResponseHeadersWithMultipleSetCookies(): void
{
$request = $this->getRequest([
'base_uri' => 'https://github.com/',
'baseURI' => 'https://github.com/',
]);

$output = "HTTP/2 200
Expand Down Expand Up @@ -937,8 +926,8 @@ public function testResponseHeadersWithMultipleSetCookies(): void
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");
Expand All @@ -949,8 +938,8 @@ public function testSplitResponse(): void
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');
Expand All @@ -964,8 +953,8 @@ public function testApplyBody(): void
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');
Expand All @@ -980,8 +969,8 @@ public function testApplyBodyByOptions(): void
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');
Expand All @@ -995,8 +984,8 @@ public function testBodyIsResetOnSecondRequest(): void
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");
Expand All @@ -1009,8 +998,8 @@ public function testResponseHeaders(): void
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");
Expand Down
Loading