Skip to content

Commit 4531f46

Browse files
committed
Merge branch 'add-user-agent'
2 parents 293ba55 + 308d23b commit 4531f46

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

MAINTAINERS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Maintainers
2+
3+
This file details information that will be useful for the project maintainers.
4+
5+
## Release Process
6+
7+
Put the desired version number into the `VERSION` constant in `src/PHPCouchDB/Server.php`. Then tag the master branch of the repo with the matching tag e.g. "v0.1.2" and push to GitHub.

src/PHPCouchDB/Server.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace PHPCouchDB;
88

9+
const VERSION = "0.1.0";
10+
911
/**
1012
* Server class deals with operations on the server level, rather than specific
1113
* to a particular database
@@ -38,7 +40,10 @@ public function __construct(array $options)
3840
if (isset($options['client']) && $options['client'] instanceof \GuzzleHttp\ClientInterface) {
3941
$client = $options['client'];
4042
} elseif (isset($options['url'])) {
41-
$client = new \GuzzleHttp\Client(["base_uri" => $options['url']]);
43+
// set a descriptive user agent
44+
$user_agent = \GuzzleHttp\default_user_agent();
45+
$client = new \GuzzleHttp\Client(["base_uri" => $options['url'],
46+
"headers" => ["User-Agent" => "PHPCouchDB/" . VERSION . " " . $user_agent]]);
4247
} else {
4348
throw new Exception\ServerException(
4449
'Failed to parse $options, array should contain either a url or a client'

tests/PHPCouchDB/ServerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ public function testCreateWithClient() {
3131
$this->assertAttributeInstanceOf('\GuzzleHttp\ClientInterface', 'client', $server);
3232
}
3333

34+
public function testCreateWithUrl() {
35+
$mock = new MockHandler([ ]);
36+
37+
$handler = HandlerStack::create($mock);
38+
39+
// userland code starts
40+
$server = new \PHPCouchDB\Server(["url" => "http://localhost:5984"]);
41+
42+
$this->assertObjectHasAttribute('client', $server);
43+
$this->assertAttributeInstanceOf('\GuzzleHttp\ClientInterface', 'client', $server);
44+
45+
$config = $server->getClient()->getConfig();
46+
$this->assertArrayHasKey('User-Agent', $config['headers']);
47+
$this->assertStringStartsWith('PHPCouchDB', $config['headers']['User-Agent']);
48+
}
49+
3450
public function testGetVersion() {
3551
$mock = new MockHandler([ $this->db_response ]);
3652

0 commit comments

Comments
 (0)