Skip to content

[BrowserKit][HttpClient] [BrowserKit, HttpClient] Minor updates in the default user agents #50106

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

Merged
merged 1 commit into from
Apr 21, 2023
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
10 changes: 2 additions & 8 deletions UPGRADE-6.3.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
UPGRADE FROM 6.2 to 6.3
=======================

BrowserKit
----------

* The default user agent has been renamed from `Symfony BrowserKit` to `SymfonyBrowserKit`
to comply with the RFC 9110 specification

Console
-------

Expand Down Expand Up @@ -75,8 +69,8 @@ HttpClient
----------

* The default user agents have been renamed from `Symfony HttpClient/Amp`, `Symfony HttpClient/Curl`
and `Symfony HttpClient/Native` to `SymfonyHttpClient (Amp)`, `SymfonyHttpClient (Curl)`
and `SymfonyHttpClient (Native)` respectively to comply with the RFC 9110 specification
and `Symfony HttpClient/Native` to `Symfony HttpClient (Amp)`, `Symfony HttpClient (Curl)`
and `Symfony HttpClient (Native)` respectively to comply with the RFC 9110 specification

HttpFoundation
--------------
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function insulate(bool $insulated = true)
public function setServerParameters(array $server)
{
$this->server = array_merge([
'HTTP_USER_AGENT' => 'SymfonyBrowserKit',
'HTTP_USER_AGENT' => 'Symfony BrowserKit',
], $server);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public function testFollowRedirectWithHeaders()
{
$headers = [
'HTTP_HOST' => 'www.example.com',
'HTTP_USER_AGENT' => 'SymfonyBrowserKit',
'HTTP_USER_AGENT' => 'Symfony BrowserKit',
'CONTENT_TYPE' => 'application/vnd.custom+xml',
'HTTPS' => false,
];
Expand All @@ -535,7 +535,7 @@ public function testFollowRedirectWithPort()
{
$headers = [
'HTTP_HOST' => 'www.example.com:8080',
'HTTP_USER_AGENT' => 'SymfonyBrowserKit',
'HTTP_USER_AGENT' => 'Symfony BrowserKit',
'HTTPS' => false,
'HTTP_REFERER' => 'http://www.example.com:8080/',
];
Expand Down Expand Up @@ -755,7 +755,7 @@ public function testGetServerParameter()
{
$client = $this->getBrowser();
$this->assertSame('', $client->getServerParameter('HTTP_HOST'));
$this->assertSame('SymfonyBrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertSame('Symfony BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertSame('testvalue', $client->getServerParameter('testkey', 'testvalue'));
}

Expand All @@ -764,7 +764,7 @@ public function testSetServerParameter()
$client = $this->getBrowser();

$this->assertSame('', $client->getServerParameter('HTTP_HOST'));
$this->assertSame('SymfonyBrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertSame('Symfony BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));

$client->setServerParameter('HTTP_HOST', 'testhost');
$this->assertSame('testhost', $client->getServerParameter('HTTP_HOST'));
Expand All @@ -778,7 +778,7 @@ public function testSetServerParameterInRequest()
$client = $this->getBrowser();

$this->assertSame('', $client->getServerParameter('HTTP_HOST'));
$this->assertSame('SymfonyBrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertSame('Symfony BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));

$client->request('GET', 'https://www.example.com/https/www.example.com', [], [], [
'HTTP_HOST' => 'testhost',
Expand All @@ -788,7 +788,7 @@ public function testSetServerParameterInRequest()
]);

$this->assertSame('', $client->getServerParameter('HTTP_HOST'));
$this->assertSame('SymfonyBrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
$this->assertSame('Symfony BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));

$this->assertSame('https://www.example.com/https/www.example.com', $client->getRequest()->getUri());

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testRequestHeaders(array $requestArguments, array $expectedArgum

public static function validContentTypes()
{
$defaultHeaders = ['user-agent' => 'SymfonyBrowserKit', 'host' => 'example.com'];
$defaultHeaders = ['user-agent' => 'Symfony BrowserKit', 'host' => 'example.com'];
yield 'GET/HEAD' => [
['GET', 'http://example.com/', ['key' => 'value']],
['GET', 'http://example.com/', ['headers' => $defaultHeaders, 'body' => '', 'max_redirects' => 0]],
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/AmpHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function request(string $method, string $url, array $options = []): Respo
}

if (!isset($options['normalized_headers']['user-agent'])) {
$options['headers'][] = 'User-Agent: SymfonyHttpClient (Amp)';
$options['headers'][] = 'User-Agent: Symfony HttpClient (Amp)';
}

if (0 < $options['max_duration']) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function request(string $method, string $url, array $options = []): Respo
$url = implode('', $url);

if (!isset($options['normalized_headers']['user-agent'])) {
$options['headers'][] = 'User-Agent: SymfonyHttpClient (Curl)';
$options['headers'][] = 'User-Agent: Symfony HttpClient (Curl)';
}

$curlopts = [
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/NativeHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function request(string $method, string $url, array $options = []): Respo
$this->logger?->info(sprintf('Request: "%s %s"', $method, implode('', $url)));

if (!isset($options['normalized_headers']['user-agent'])) {
$options['headers'][] = 'User-Agent: SymfonyHttpClient (Native)';
$options['headers'][] = 'User-Agent: Symfony HttpClient (Native)';
}

if (0 < $options['max_duration']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static function provideCurlRequests(): iterable
--url %1$shttp://localhost:8057/json%1$s \\
--header %1$sAccept: */*%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s',
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s',
];
yield 'GET with base uri' => [
[
Expand All @@ -209,7 +209,7 @@ public static function provideCurlRequests(): iterable
--url %1$shttp://localhost:8057/json/1%1$s \\
--header %1$sAccept: */*%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s',
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s',
];
yield 'GET with resolve' => [
[
Expand All @@ -229,7 +229,7 @@ public static function provideCurlRequests(): iterable
--url %1$shttp://localhost:8057/json%1$s \\
--header %1$sAccept: */*%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s',
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s',
];
yield 'POST with string body' => [
[
Expand All @@ -247,7 +247,7 @@ public static function provideCurlRequests(): iterable
--header %1$sContent-Length: 9%1$s \\
--header %1$sContent-Type: application/x-www-form-urlencoded%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s \\
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s \\
--data %1$sfoobarbaz%1$s',
];
yield 'POST with array body' => [
Expand Down Expand Up @@ -285,7 +285,7 @@ public function __toString(): string
--header %1$sContent-Type: application/x-www-form-urlencoded%1$s \\
--header %1$sContent-Length: 211%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s \\
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s \\
--data %1$sfoo=fooval%1$s --data %1$sbar=barval%1$s --data %1$sbaz=bazval%1$s --data %1$sfoobar[baz]=bazval%1$s --data %1$sfoobar[qux]=quxval%1$s --data %1$sbazqux[0]=bazquxval1%1$s --data %1$sbazqux[1]=bazquxval2%1$s --data %1$sobject[fooprop]=foopropval%1$s --data %1$sobject[barprop]=barpropval%1$s --data %1$stostring=tostringval%1$s',
];

Expand All @@ -312,7 +312,7 @@ public function __toString(): string
--url %1$shttp://localhost:8057/?foo=fooval&bar=newbarval&foobar[baz]=bazval&foobar[qux]=quxval&bazqux[0]=bazquxval1&bazqux[1]=bazquxval2%1$s \\
--header %1$sAccept: */*%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s',
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s',
];
yield 'POST with json' => [
[
Expand All @@ -336,7 +336,7 @@ public function __toString(): string
--header %1$sAccept: */*%1$s \\
--header %1$sContent-Length: 120%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s \\
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s \\
--data %1$s{"foo":{"bar":"baz","qux":[1.1,1.0],"fred":["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026"]}}%1$s',
];
}
Expand Down Expand Up @@ -368,7 +368,7 @@ public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands()
--header %1$sAccept: */*%1$s \\
--header %1$sAuthorization: Basic Zm9vOmJhcg==%1$s \\
--header %1$sAccept-Encoding: gzip%1$s \\
--header %1$sUser-Agent: SymfonyHttpClient (Native)%1$s', '\\' === \DIRECTORY_SEPARATOR ? '"' : "'"), $curlCommand
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s', '\\' === \DIRECTORY_SEPARATOR ? '"' : "'"), $curlCommand
);
}

Expand Down