Skip to content

Allow to configure plugins specifically for a client #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2016

Conversation

dbu
Copy link
Collaborator

@dbu dbu commented Aug 7, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets fixes #110
Documentation php-http/documentation#142
License MIT

What's in this PR?

Add new configuration for plugins specifically to a client. The global plugin configuration is duplicated to allow configuring all plugins with client specific information.

Why?

See #110

Example Usage

httplug:
    plugins:
        logger:
            enabled: true
            logger: 'logger'
            formatter: null
        redirect:
            enabled: true
            preserve_header: true
            use_default_for_multiple: true
        retry:
            enabled: true
            retry: 1
    clients:
        todo:
            factory: "httplug.factory.guzzle6"
            plugins:
                - 'httplug.plugin.logger'
                - 'httplug.plugin.redirect'
                -  add_host:
                     host: http://localhost
                - 'httplug.plugin.retry'
        acme:
            factory: 'httplug.factory.guzzle6'
            plugins: ['httplug.plugin.redirect', 'httplug.plugin.retry']

You can specify the httplug.client.{name}.plugin.add_host in the plugins list if you want the host plugin to come somewhere else than last in the chain.

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
  • Add the other plugins we currently dont support (want feedback first)
    • HeaderSet
    • HeaderRemove
    • HeaderDefaults
    • HeaderAppend
    • -ContentLength- (configured as shared plugin, has no options)
  • Handle custom authentication plugin
  • Fix XML configuration
  • Documentation pull request created => document configuring plugins on client documentation#142

@dbu dbu force-pushed the client-extra-plugins branch 2 times, most recently from 6c98e84 to 70e599e Compare August 7, 2016 10:52
$decoder->canBeEnabled();
} else {
$decoder->canBeDisabled();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this construct is repeated quite a bit, but i can't think of a better solution. the global plugins need to be enabled by default, but on the client, we want to only see plugins that where explicitly configured.

@dbu dbu mentioned this pull request Aug 7, 2016
1 task
@@ -145,7 +158,9 @@ private function configurePluginByName($name, Definition $definition, array $con
$definition->replaceArgument(0, new Reference($config['cookie_jar']));
break;
case 'decoder':
$definition->addArgument($config['use_content_encoding']);
$definition->addArgument([
'use_content_encoding' => $config['use_content_encoding'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

separated the bugfix into #113 and then realized we have other changes in master already, so we won't do a patch release for the fix. but i guess after we merge this we want to tag 1.3 very soon so the bugfix will be released soon.

@sagikazarmark
Copy link
Member

How can you control the order of plugins?

Maybe we can have this within the plugins section: numeric index: look for service, string index: configure extra plugin.

@dbu dbu force-pushed the client-extra-plugins branch from 110f452 to 64a3ebb Compare August 7, 2016 13:00
@dbu dbu changed the title Allow to configure plugins specifically for a client [WIP] Allow to configure plugins specifically for a client Aug 7, 2016
@dbu
Copy link
Collaborator Author

dbu commented Aug 7, 2016

without further information, extra_plugins are appended to the explicitly configured plugins in the order they have been defined. but you can specify each of the extra_plugin in the plugins field of the client. i will document how to know the service name of the extra plugins.

@dbu
Copy link
Collaborator Author

dbu commented Aug 7, 2016 via email

@Nyholm
Copy link
Member

Nyholm commented Aug 8, 2016

I like this approach:

plugins:
    logger:
        ...
client:
    acme:
        plugins:
            - add_host:
                  host: ...
            - httplug.plugin.logger

It makes more sense. But yes, the configuration.php is going to be difficult. But we should try.

@dbu dbu force-pushed the client-extra-plugins branch from 64a3ebb to e101865 Compare August 8, 2016 08:11
@@ -9,6 +9,7 @@

### Added

- You can now configure plugins on each client in `extra_plugins`. Plugins that you previously had to define your own services can be configured on the client.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

needs update

@dbu dbu force-pushed the client-extra-plugins branch from deb2ba2 to 9a1e3a1 Compare August 11, 2016 09:55
->scalarNode('retry')->defaultValue(1)->end()
->end()
->end() // End retry plugin
// TODO add aditional plugins that are only usable on a specific client
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what are the plugins we should allow to configure?

Copy link
Member

Choose a reason for hiding this comment

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

HeaderSet, HeaderRemove, HeaderDefaults, HeaderAppend, ContentLength

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ContentLength is globally available and has no configuration options. did you mean something else?

Copy link
Member

Choose a reason for hiding this comment

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

No, my bad.

@dbu dbu force-pushed the client-extra-plugins branch from 9a1e3a1 to 50a90f9 Compare August 11, 2016 09:59
@Nyholm
Copy link
Member

Nyholm commented Aug 12, 2016

The plugin_journal expects a single dimensional array at https://github.com/php-http/HttplugBundle/pull/112/files#diff-18f3f26a96b967c0a5a3e13086d8367dR256

(Try to open the web profiler page and you will see an error)

$this->configureClients($container, $config);
$this->configureSharedPlugins($container, $config['plugins']); // must be after clients, as the extra_plugins in clients might use plugins as template that will be removed
Copy link
Member

Choose a reason for hiding this comment

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

Update this comment. We cant use (extra_plugins)

@Nyholm
Copy link
Member

Nyholm commented Aug 12, 2016

I've reviewed this. It is a really good improvement. I like the way you add the shared configuration on each client in the Configuration.php.

I made a few comments, It was a bug but otherwise it looks fine.


For the record. Here is a working configuration (we do not use extra_plugins as the first comment says):

httplug:
    plugins:
        logger:
            enabled: true
            logger: 'logger'
            formatter: null
        redirect:
            enabled: true
            preserve_header: true
            use_default_for_multiple: true
        retry:
            enabled: true
            retry: 1
    clients:
        todo:
            factory: "httplug.factory.guzzle6"
            plugins:
                - 'httplug.plugin.logger'
                - 'httplug.plugin.redirect'
                -  add_host:
                     host: http://localhost
                - 'httplug.plugin.retry'
        acme:
            factory: 'httplug.factory.guzzle6'
            plugins: ['httplug.plugin.redirect', 'httplug.plugin.retry']

@dbu
Copy link
Collaborator Author

dbu commented Aug 12, 2016

adding a new test in #118 to prevent the regression you spotted.

@dbu dbu force-pushed the client-extra-plugins branch from 134fc36 to deb4eb3 Compare August 12, 2016 09:49
->arrayNode('clients')
->fixXmlConfig('plugin')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this must go after the ->prototype('array') array line to apply to the things inside the array and not to the array itself (which has numerical keys)

@dbu dbu changed the title [WIP] Allow to configure plugins specifically for a client Allow to configure plugins specifically for a client Aug 12, 2016
@dbu
Copy link
Collaborator Author

dbu commented Aug 12, 2016

yay, this seems to actually work out! trying to get the doc started, then lets merge this.

@dbu
Copy link
Collaborator Author

dbu commented Aug 12, 2016

this is now ready. i quickly tried in a symfony app and it works now fine, including debug toolbar.

@dbu dbu force-pushed the client-extra-plugins branch from ac21608 to c6058e8 Compare August 12, 2016 14:01
@Nyholm
Copy link
Member

Nyholm commented Aug 12, 2016

I've started tested it a little. Found a unrelated bug... (#121)

I'll will try to do a final review tonight if you are happy with the current state of this PR.

@dbu
Copy link
Collaborator Author

dbu commented Aug 12, 2016

great! yes i am happy with it. squashed the commits and it does look right to me. but am sure there are things to improve and i might have missed something.

->arrayNode('plugins')
->info('A list of plugin service ids and client specific plugin definitions. The order is important.')
->prototype('array')
;
Copy link
Member

Choose a reason for hiding this comment

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

You do not call ->end() here and I know that it is on purpose. You should at least add a comment here. Or event better: Create the plugin node and then add it to the tree. (I think that is possible)

@Nyholm
Copy link
Member

Nyholm commented Aug 12, 2016

Im happy to merge when all my comments have been addressed or answered.

Good job 👍

@dbu dbu force-pushed the client-extra-plugins branch from c6058e8 to 80122ec Compare August 15, 2016 06:52
@dbu dbu force-pushed the client-extra-plugins branch from 80122ec to 11eeafc Compare August 15, 2016 06:55
@dbu
Copy link
Collaborator Author

dbu commented Aug 15, 2016

did some more cleanup based on your feedback, @Nyholm

any more suggestions or is this good?

@Nyholm
Copy link
Member

Nyholm commented Aug 15, 2016

Im all good. I'm very happy with this PR. It is an amazing improvement. Thank you

@Nyholm Nyholm merged commit 925fa8e into master Aug 15, 2016
@Nyholm Nyholm deleted the client-extra-plugins branch August 15, 2016 08:08
@sagikazarmark sagikazarmark modified the milestone: v1.3.0 Aug 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

configure base path for a client
3 participants