From e4d320310853497153b78158b43d6c3d2d32c9ae Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 21 Apr 2023 17:26:16 +0200 Subject: [PATCH] [BrowserKit, HttpClient] Minor updates in the default user agents --- UPGRADE-6.3.md | 10 ++-------- .../Component/BrowserKit/AbstractBrowser.php | 2 +- .../BrowserKit/Tests/AbstractBrowserTest.php | 12 ++++++------ .../BrowserKit/Tests/HttpBrowserTest.php | 2 +- .../Component/HttpClient/AmpHttpClient.php | 2 +- .../Component/HttpClient/CurlHttpClient.php | 2 +- .../Component/HttpClient/NativeHttpClient.php | 2 +- .../HttpClientDataCollectorTest.php | 16 ++++++++-------- 8 files changed, 21 insertions(+), 27 deletions(-) diff --git a/UPGRADE-6.3.md b/UPGRADE-6.3.md index a05514396074c..9e56453437888 100644 --- a/UPGRADE-6.3.md +++ b/UPGRADE-6.3.md @@ -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 ------- @@ -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 -------------- diff --git a/src/Symfony/Component/BrowserKit/AbstractBrowser.php b/src/Symfony/Component/BrowserKit/AbstractBrowser.php index 3725a107d246f..c6014ca81eeac 100644 --- a/src/Symfony/Component/BrowserKit/AbstractBrowser.php +++ b/src/Symfony/Component/BrowserKit/AbstractBrowser.php @@ -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); } diff --git a/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php b/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php index 1948f8c0a555d..dd449bea5e428 100644 --- a/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php @@ -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, ]; @@ -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/', ]; @@ -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')); } @@ -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')); @@ -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', @@ -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()); diff --git a/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php b/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php index c9f548fafd2a8..44f61289d8d6a 100644 --- a/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php @@ -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]], diff --git a/src/Symfony/Component/HttpClient/AmpHttpClient.php b/src/Symfony/Component/HttpClient/AmpHttpClient.php index 29ee315637e87..94d8fa414ee45 100644 --- a/src/Symfony/Component/HttpClient/AmpHttpClient.php +++ b/src/Symfony/Component/HttpClient/AmpHttpClient.php @@ -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']) { diff --git a/src/Symfony/Component/HttpClient/CurlHttpClient.php b/src/Symfony/Component/HttpClient/CurlHttpClient.php index df8c6c886ce2b..5c19ed0bf1e69 100644 --- a/src/Symfony/Component/HttpClient/CurlHttpClient.php +++ b/src/Symfony/Component/HttpClient/CurlHttpClient.php @@ -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 = [ diff --git a/src/Symfony/Component/HttpClient/NativeHttpClient.php b/src/Symfony/Component/HttpClient/NativeHttpClient.php index 6999ae7406d23..e4a2b0c28c67e 100644 --- a/src/Symfony/Component/HttpClient/NativeHttpClient.php +++ b/src/Symfony/Component/HttpClient/NativeHttpClient.php @@ -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']) { diff --git a/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php b/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php index 99c93c14def3a..7a9f22cab1e9e 100755 --- a/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php +++ b/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php @@ -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' => [ [ @@ -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' => [ [ @@ -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' => [ [ @@ -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' => [ @@ -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', ]; @@ -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' => [ [ @@ -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', ]; } @@ -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 ); }