FriendsOfSymfony / FOSHttpCache

Integrate your PHP application with your HTTP caching proxy

Home Page:https://foshttpcache.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SymfonyResponseTagger::tagSymfonyResponse() uses hardcoded glue.

das-peter opened this issue · comments

SymfonyResponseTagger::tagSymfonyResponse() uses a comma as the hardcoded glue in order to split n merge tags onto a request:

$this->addTags(explode(',', $response->headers->get($this->getTagsHeaderName())));

Unfortunately this collides with the fact that glue is easily configurable CommaSeparatedTagHeaderFormatter and the bundle even automatically changes the glue to space in case varnish xkey is used for purging Configuration:

            // Determine the default separator for the tags header, depending on whether we use BAN or xkey
            ->validate()
                ->ifTrue(
                    function ($v) {
                        return empty($v['tags']['separator']);
                    }
                )
                ->then(function ($v) {
                    $v['tags']['separator'] = $this->isVarnishXkey($v) ? ' ' : ',';

                    return $v;
                })

Unfortunately I don't think there's a quick solution to this since the TagHeaderFormatter Interface currently doesn't provide any way to determine the glue.
The cleanest solution I can think of would be to expand the TagHeaderFormatter Inteface with a method that splits a header line. This should be fully transparent for consumers and quite trivial to implement since the implementing class should be very much aware how it is configured and how it has to split a tag header it essentially produced.

So I'd propose a counterpart to TagHeaderFormatter::getTagsHeaderValue()

    /**
     * Get the tag array from an HTTP tag header.
     *
     * This extracts all tags from a HTTP tag header and ensures correct encoding.
     *
     * @return string[]
     */
    public function getTagsHeaderArray(string $header): array;

I'm aware this is a upstream change and would need to be handled there, I'd like to get feedback from a "consumer" first though.

hi @das-peter , busy times... i now had a look at this, and i think the problem is that the SymfonyResponseTagger has not been updated when we refactored ResponseTagger. that was a refactoring for FOSHttpCache 2.0, so it is available.

imho the fix is to use the getTagsHeaderValue method of the base class in SymfonyResponseTagger.

i would consider that a bugfix - it would only create problems if somebody configured a different separator and then relies on still getting the default separator...

@Toflar do you see any issue with using that? i think it should be alright.

oh wait, its not about generating the header, that is already correct. the problem is with how we merge tags. i will have a look.

this is my current state. i realized we have the same problem with the symfony built-in http cache... #541

@dbu Thank you very much for your time - very much appreciated! Let me know if I can help with anything.
#541 Looks pretty great to me.