diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73037511..cb76412f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
+## 1.9.0 (unreleased) - 2017-01-12
+- Allow to configure the `BaseUriPlugin` per client, under the `base_uri` configuration key.
+
## 1.8.1 - 2017-12-06
### Fixed
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 227df718..8905895f 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -298,6 +298,22 @@ private function createClientPluginNode()
->end()
->end()
->end()
+ ->arrayNode('base_uri')
+ ->canBeEnabled()
+ ->addDefaultsIfNotSet()
+ ->info('Set a base URI to the request.')
+ ->children()
+ ->scalarNode('uri')
+ ->info('Base Uri including protocol, optionally the port number and prepend path, e.g. https://api.local:8000/api')
+ ->isRequired()
+ ->cannotBeEmpty()
+ ->end()
+ ->scalarNode('replace')
+ ->info('Whether to replace the host if request already specifies one')
+ ->defaultValue(false)
+ ->end()
+ ->end()
+ ->end()
->arrayNode('header_append')
->canBeEnabled()
->info('Append headers to the request. If the header already exists the value will be appended to the current value.')
diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php
index 0b558db5..8901d5be 100644
--- a/DependencyInjection/HttplugExtension.php
+++ b/DependencyInjection/HttplugExtension.php
@@ -199,9 +199,18 @@ private function configurePluginByName($name, Definition $definition, array $con
/* client specific plugins */
case 'add_host':
- $uriService = $serviceId.'.host_uri';
- $this->createUri($container, $uriService, $config['host']);
- $definition->replaceArgument(0, new Reference($uriService));
+ $hostUriService = $serviceId.'.host_uri';
+ $this->createUri($container, $hostUriService, $config['host']);
+ $definition->replaceArgument(0, new Reference($hostUriService));
+ $definition->replaceArgument(1, [
+ 'replace' => $config['replace'],
+ ]);
+
+ break;
+ case 'base_uri':
+ $baseUriService = $serviceId.'.base_uri';
+ $this->createUri($container, $baseUriService, $config['uri']);
+ $definition->replaceArgument(0, new Reference($baseUriService));
$definition->replaceArgument(1, [
'replace' => $config['replace'],
]);
diff --git a/Resources/config/plugins.xml b/Resources/config/plugins.xml
index d921f910..f0bab813 100644
--- a/Resources/config/plugins.xml
+++ b/Resources/config/plugins.xml
@@ -34,6 +34,10 @@
+
+
+
+
diff --git a/Tests/Resources/Fixtures/config/full.php b/Tests/Resources/Fixtures/config/full.php
index 9b273542..b3956aed 100644
--- a/Tests/Resources/Fixtures/config/full.php
+++ b/Tests/Resources/Fixtures/config/full.php
@@ -24,6 +24,11 @@
'host' => 'http://localhost',
],
],
+ [
+ 'base_uri' => [
+ 'uri' => 'http://localhost',
+ ],
+ ],
[
'header_set' => [
'headers' => [
diff --git a/Tests/Resources/Fixtures/config/full.xml b/Tests/Resources/Fixtures/config/full.xml
index 9ef8e756..95287667 100644
--- a/Tests/Resources/Fixtures/config/full.xml
+++ b/Tests/Resources/Fixtures/config/full.xml
@@ -19,6 +19,9 @@
+
+
+
diff --git a/Tests/Resources/Fixtures/config/full.yml b/Tests/Resources/Fixtures/config/full.yml
index 460b472d..a4545541 100644
--- a/Tests/Resources/Fixtures/config/full.yml
+++ b/Tests/Resources/Fixtures/config/full.yml
@@ -18,6 +18,9 @@ httplug:
-
add_host:
host: http://localhost
+ -
+ base_uri:
+ uri: http://localhost
-
header_set:
headers:
diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php
index 91200789..13283ab8 100644
--- a/Tests/Unit/DependencyInjection/ConfigurationTest.php
+++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php
@@ -134,6 +134,13 @@ public function testSupportsAllConfigFormats()
'replace' => false,
],
],
+ [
+ 'base_uri' => [
+ 'enabled' => true,
+ 'uri' => 'http://localhost',
+ 'replace' => false,
+ ],
+ ],
[
'header_set' => [
'enabled' => true,
diff --git a/composer.json b/composer.json
index 7c38a6b3..9df5b982 100644
--- a/composer.json
+++ b/composer.json
@@ -82,7 +82,7 @@
},
"extra": {
"branch-alias": {
- "dev-master": "1.8-dev"
+ "dev-master": "1.9-dev"
}
}
}