Skip to content

Commit

Permalink
allow override User Agent from request options
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Jul 21, 2017
1 parent 5b2171a commit 8d049bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Service/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public function __construct(Client $client, $host, $app_client)
public function get($path, array $options = [])
{
if ($this->app_client) {
$options['headers'] = isset($options['headers']) ? $options['headers'] : [];
$options['headers']['User-Agent'] = $this->app_client;
$options['headers'] = array_merge(
['User-Agent' => $this->app_client],
isset($options['headers']) ? $options['headers'] : []
);
}

$response = $this->client->request('GET', $this->host.$path, $options);
Expand Down
24 changes: 23 additions & 1 deletion tests/Service/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,23 @@ protected function setUp()
$this->browser = new Browser($this->client, $this->host, $this->app_client);
}

public function testGet()
/**
* @return array
*/
public function appClients()
{
return [
[''],
['Override User Agent'],
];
}

/**
* @dataProvider appClients
*
* @param string $app_client
*/
public function testGet($app_client)
{
$path = '/foo';
$params = ['bar' => 'baz'];
Expand All @@ -65,6 +81,12 @@ public function testGet()
'User-Agent' => $this->app_client,
],
];

if ($app_client) {
$options['headers']['User-Agent'] = $app_client;
$params['headers']['User-Agent'] = $app_client;
}

$content = 'Hello, world!';

$this->stream
Expand Down

0 comments on commit 8d049bc

Please sign in to comment.