@@ -134,6 +134,52 @@ function ($v) {
134134
135135 throw new InvalidConfigurationException ('To enable the user context logout handler, you need to configure a ban capable proxy_client. ' );
136136 })
137+ ->end ()
138+ // Determine the default tags header for the varnish client, depending on whether we use BAN or xkey
139+ ->validate ()
140+ ->ifTrue (
141+ function ($ v ) {
142+ return
143+ array_key_exists ('proxy_client ' , $ v )
144+ && array_key_exists ('varnish ' , $ v ['proxy_client ' ])
145+ && empty ($ v ['proxy_client ' ]['varnish ' ]['tags_header ' ])
146+ ;
147+ }
148+ )
149+ ->then (function ($ v ) {
150+ $ v ['proxy_client ' ]['varnish ' ]['tags_header ' ] =
151+ (Varnish::TAG_XKEY === $ v ['proxy_client ' ]['varnish ' ]['tag_mode ' ])
152+ ? Varnish::DEFAULT_HTTP_HEADER_CACHE_XKEY
153+ : Varnish::DEFAULT_HTTP_HEADER_CACHE_TAGS ;
154+
155+ return $ v ;
156+ })
157+ ->end ()
158+ // Determine the default tag response header, depending on whether we use BAN or xkey
159+ ->validate ()
160+ ->ifTrue (
161+ function ($ v ) {
162+ return empty ($ v ['tags ' ]['response_header ' ]);
163+ }
164+ )
165+ ->then (function ($ v ) {
166+ $ v ['tags ' ]['response_header ' ] = $ this ->isVarnishXkey ($ v ) ? 'xkey ' : TagHeaderFormatter::DEFAULT_HEADER_NAME ;
167+
168+ return $ v ;
169+ })
170+ ->end ()
171+ // Determine the default separator for the tags header, depending on whether we use BAN or xkey
172+ ->validate ()
173+ ->ifTrue (
174+ function ($ v ) {
175+ return empty ($ v ['tags ' ]['separator ' ]);
176+ }
177+ )
178+ ->then (function ($ v ) {
179+ $ v ['tags ' ]['separator ' ] = $ this ->isVarnishXkey ($ v ) ? ' ' : ', ' ;
180+
181+ return $ v ;
182+ })
137183 ;
138184
139185 $ this ->addCacheableResponseSection ($ rootNode );
@@ -150,6 +196,14 @@ function ($v) {
150196 return $ treeBuilder ;
151197 }
152198
199+ private function isVarnishXkey (array $ v ): bool
200+ {
201+ return array_key_exists ('proxy_client ' , $ v )
202+ && array_key_exists ('varnish ' , $ v ['proxy_client ' ])
203+ && Varnish::TAG_XKEY === $ v ['proxy_client ' ]['varnish ' ]['tag_mode ' ]
204+ ;
205+ }
206+
153207 private function addCacheableResponseSection (ArrayNodeDefinition $ rootNode )
154208 {
155209 $ rootNode
@@ -362,7 +416,6 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
362416 ->end ()
363417 ->children ()
364418 ->scalarNode ('tags_header ' )
365- ->defaultValue (Varnish::DEFAULT_HTTP_HEADER_CACHE_TAGS )
366419 ->info ('HTTP header to use when sending tag invalidation requests to Varnish ' )
367420 ->end ()
368421 ->scalarNode ('header_length ' )
@@ -373,6 +426,11 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
373426 ->info ('Map of additional headers to include in each ban request. ' )
374427 ->prototype ('scalar ' )->end ()
375428 ->end ()
429+ ->enumNode ('tag_mode ' )
430+ ->info ('If you can enable the xkey module in Varnish, use the purgekeys mode for more efficient tag handling ' )
431+ ->values (['ban ' , 'purgekeys ' ])
432+ ->defaultValue ('ban ' )
433+ ->end ()
376434 ->append ($ this ->getHttpDispatcherNode ())
377435 ->end ()
378436 ->end ()
@@ -580,8 +638,12 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
580638 ->info ('Service name of a custom ExpressionLanugage to use. ' )
581639 ->end ()
582640 ->scalarNode ('response_header ' )
583- ->defaultValue (TagHeaderFormatter::DEFAULT_HEADER_NAME )
584- ->info ('HTTP header that contains cache tags ' )
641+ ->defaultNull ()
642+ ->info ('HTTP header that contains cache tags. Defaults to xkey-softpurge for Varnish xkey or X-Cache-Tags otherwise ' )
643+ ->end ()
644+ ->scalarNode ('separator ' )
645+ ->defaultNull ()
646+ ->info ('Character(s) to use to separate multiple tags. Defaults to " " for Varnish xkey or "," otherwise ' )
585647 ->end ()
586648 ->arrayNode ('rules ' )
587649 ->prototype ('array ' )
@@ -593,8 +655,8 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
593655 })
594656 ->thenInvalid ('Configured a tag_expression but ExpressionLanugage is not available ' )
595657 ->end ()
596- ->children ();
597-
658+ ->children ()
659+ ;
598660 $ this ->addMatch ($ rules );
599661
600662 $ rules
0 commit comments