Skip to content

Configuring redirect plugin on client level modifies the redirect global service #478

Description

@ruudk

We noticed an interesting behavior with the redirect plugin.

The following configuration is accepted:

$configurator->extension(
        'httplug',
        [
            'clients' => [
                'client1' => [
                    'factory' => param('httplug.factory'),
                    'plugins' => [
                        [
                            'header_defaults' => [
                                'headers' => [
                                    'User-Agent' => 'My User Agent',
                                ],
                            ],
                        ],
                        [
                            'redirect' => [
                                'preserve_header' => true,
                            ],
                        ],
                    ],
                ],
                'client2' => [
                    'factory' => param('httplug.factory'),
                    'plugins' => [
                        [
                            'header_defaults' => [
                                'headers' => [
                                    'User-Agent' => 'My User Agent',
                                ],
                            ],
                        ],
                        [
                            'redirect' => [
                                'preserve_header' => true,
                            ],
                        ],
                    ],
                ],
            ],
        ],
    );

As you can see, we configure 2 clients, and configure the redirect plugin. For the first client we set preserve_header to true and for the second to false.

We were surprised by the fact that this didn't work as expected. The reason being that the HTTPlugBundle extension overwrites the same instance httplug.plugin.redirect.

This was a bit of a foot gun for us, that took a lot of time to figure out why it wasn't working.

After reading the docs, it became clear that the redirect plugin can be configured globally. It does not say should.

We solved it by doing it like this:

$configurator->extension(
        'httplug',
        [
            'plugins' => [
                'redirect' => [
                    'preserve_header' => false,
                ],
            ],
            'clients' => [
                'client1' => [
                    'factory' => param('httplug.factory'),
                    'plugins' => [
                        [
                            'header_defaults' => [
                                'headers' => [
                                    'User-Agent' => 'My User Agent',
                                ],
                            ],
                        ],
                        'httplug.plugin.redirect',
                    ],
                ],
                'client2' => [
                    'factory' => param('httplug.factory'),
                    'plugins' => [
                        [
                            'header_defaults' => [
                                'headers' => [
                                    'User-Agent' => 'My User Agent',
                                ],
                            ],
                        ],
                        'httplug.plugin.redirect',
                    ],
                ],
            ],
        ],
    );

It's not 100% the same as before, but since it was a global plugin, we decided it would be best to have a default that is sane.

  • Is there still a reason to have the redirect plugin as a global service? I think the redirect plugin was improved over time taking more configuration. For example, the plugin allows for preserve_header to be a bool or array. But the bundle does not yet accept this.
  • Should we throw a big warning when someone tries to configure the redirect plugin on the client level?
  • Even better: we should remove the global httplug.plugin.redirect service, and make them instances per client (like one would expect).
  • Why does preserve_header default to true on the RedirectPlugin? In my opinion, this is a big mistake and also not what curl and httpie are doing when following redirects. It's could also be a security issue when sending Authorization headers to 3rd parties that you are unaware of.

I can do the work, if I get some direction on what the best solution would be.

/cc @dbu @Nyholm

Activity

  1. dbu commented on Feb 24, 2026

    @dbu
    Collaborator

    the idea is that you can configure a plugin globally to use in each client to share configuration. but as you expect, the idea was that if you configure it inside a client, the configuration should only apply to the plugin in that client. if that is not the case with redirect, that is a bug.

    regarding the default of preserve_header is a security issue, but we did it this way to avoid a BC break. i think the way forward is to raise a deprecation warning if the header is not explicitly set, to tell people that the default will switch in the next major. and then we do the next major and change the default to false and remove the warning.

    i know this issue is a bit older, but do you want to work on this?

  2. ruudk commented on Mar 2, 2026

    @ruudk
    ContributorAuthor

    i know this issue is a bit older, but do you want to work on this?

    Not at this moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions