@@ -134,6 +134,52 @@ function ($v) {
134
134
135
135
throw new InvalidConfigurationException ('To enable the user context logout handler, you need to configure a ban capable proxy_client. ' );
136
136
})
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
+ })
137
183
;
138
184
139
185
$ this ->addCacheableResponseSection ($ rootNode );
@@ -150,6 +196,14 @@ function ($v) {
150
196
return $ treeBuilder ;
151
197
}
152
198
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
+
153
207
private function addCacheableResponseSection (ArrayNodeDefinition $ rootNode )
154
208
{
155
209
$ rootNode
@@ -362,7 +416,6 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
362
416
->end ()
363
417
->children ()
364
418
->scalarNode ('tags_header ' )
365
- ->defaultValue (Varnish::DEFAULT_HTTP_HEADER_CACHE_TAGS )
366
419
->info ('HTTP header to use when sending tag invalidation requests to Varnish ' )
367
420
->end ()
368
421
->scalarNode ('header_length ' )
@@ -373,6 +426,11 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode)
373
426
->info ('Map of additional headers to include in each ban request. ' )
374
427
->prototype ('scalar ' )->end ()
375
428
->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 ()
376
434
->append ($ this ->getHttpDispatcherNode ())
377
435
->end ()
378
436
->end ()
@@ -580,8 +638,12 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
580
638
->info ('Service name of a custom ExpressionLanugage to use. ' )
581
639
->end ()
582
640
->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 ' )
585
647
->end ()
586
648
->arrayNode ('rules ' )
587
649
->prototype ('array ' )
@@ -593,8 +655,8 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
593
655
})
594
656
->thenInvalid ('Configured a tag_expression but ExpressionLanugage is not available ' )
595
657
->end ()
596
- ->children ();
597
-
658
+ ->children ()
659
+ ;
598
660
$ this ->addMatch ($ rules );
599
661
600
662
$ rules
0 commit comments