Skip to content

Commit

Permalink
fix: normalize default user-agent string
Browse files Browse the repository at this point in the history
Changes the default user-agent from `Laminas\Http\Client` to
`Laminas_Http_Client`, as many servers and clients do not accept escape
characters in the user-agent.

Fixes #38

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
  • Loading branch information
weierophinney committed Jun 23, 2020
1 parent 45c7a17 commit e7d6f46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Client implements DispatchableInterface
protected $config = [
'maxredirects' => 5,
'strictredirects' => false,
'useragent' => Client::class,
'useragent' => 'Laminas_Http_Client',
'timeout' => 10,
'connecttimeout' => null,
'adapter' => Socket::class,
Expand Down
12 changes: 12 additions & 0 deletions test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use LaminasTest\Http\TestAsset\ExtendedClient;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
use ReflectionProperty;

class ClientTest extends TestCase
{
Expand Down Expand Up @@ -638,4 +639,15 @@ public function testStreamCompression(AdapterInterface $adapter)

self::assertSame($response->getBody(), file_get_contents($tmpFile));
}

public function testDefaultUserAgentDoesNotUseEscapeCharacter()
{
$client = new Client();
$r = new ReflectionProperty($client, 'config');
$r->setAccessible(true);
$config = $r->getValue($client);
$this->assertInternalType('array', $config);
$this->assertArrayHasKey('useragent', $config);
$this->assertSame('Laminas_Http_Client', $config['useragent']);
}
}

0 comments on commit e7d6f46

Please sign in to comment.