Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
fix(Client): fix format of UserAgent header
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Schulze committed Jun 6, 2016
1 parent 842f99f commit bc37b2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/AbstractHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ abstract protected function getBaseUrl();
protected function getUserAgent()
{
if (is_null($this->userAgent)) {
$agent = 'commercetools-php-sdk ' . static::VERSION;
if (extension_loaded('curl')) {
$agent .= ' curl/' . curl_version()['version'];
$agent = 'commercetools-php-sdk/' . static::VERSION . ' PHP/' . PHP_VERSION;
if (extension_loaded('curl') && function_exists('curl_version')) {
$agent .= ' curl/' . \curl_version()['version'];
}
$agent .= ' PHP/' . PHP_VERSION;
$this->userAgent = $agent;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,12 @@ public function testUserAgent()
if (is_array($userAgent)) {
$userAgent = current($userAgent);
}
$this->assertContains('commercetools-php-sdk ' . AbstractHttpClient::VERSION, $userAgent);
$userAgent = explode(' ', $userAgent);
$this->assertSame('commercetools-php-sdk/' . AbstractHttpClient::VERSION, $userAgent[0]);
$this->assertSame('PHP/' . PHP_VERSION, $userAgent[1]);
if (extension_loaded('curl') && function_exists('curl_version')) {
$this->assertSame('curl/' . \curl_version()['version'], $userAgent[2]);
}
}
}
}

1 comment on commit bc37b2f

@nkuehn
Copy link
Contributor

@nkuehn nkuehn commented on bc37b2f Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) didn't see that one

Please # to comment.