@@ -39,10 +39,10 @@ static public function getFromSocket( $socket ) {
39
39
return null ;
40
40
}
41
41
switch ( $ version ) {
42
- case '4.0 ' :
43
- return Mage::getModel (
44
- 'turpentine/varnish_configurator_version4 ' ,
45
- array ( 'socket ' => $ socket ) );
42
+ case '4.0 ' :
43
+ return Mage::getModel (
44
+ 'turpentine/varnish_configurator_version4 ' ,
45
+ array ( 'socket ' => $ socket ) );
46
46
47
47
case '3.0 ' :
48
48
return Mage::getModel (
@@ -209,17 +209,33 @@ protected function _getNormalizeHostTarget() {
209
209
* @return string
210
210
*/
211
211
public function getAllowedHostsRegex () {
212
- $ hosts = array ();
213
- foreach ( Mage::app ()->getStores () as $ store ) {
214
- $ hosts [] = parse_url ( $ store ->getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST );
215
- }
216
-
217
- $ hosts = array_values (array_unique ( $ hosts ));
218
-
212
+ $ hosts = array ();
213
+ foreach ( Mage::app ()->getStores () as $ store ) {
214
+ $ hosts [] = parse_url ( $ store ->getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST );
215
+ }
216
+
217
+ $ hosts = array_values (array_unique ( $ hosts ));
218
+
219
219
$ pattern = '( ' .implode ('| ' , array_map ("preg_quote " , $ hosts )).') ' ;
220
- return $ pattern ;
220
+ return $ pattern ;
221
221
}
222
-
222
+
223
+ /**
224
+ * Get the Host normalization sub routine
225
+ *
226
+ * @return string
227
+ */
228
+ protected function _vcl_sub_allowed_hosts_regex () {
229
+ $ tpl = <<<EOS
230
+ # if host is not allowed in magento pass to backend
231
+ if (req.http.host !~ "{{allowed_hosts_regex}}") {
232
+ return (pass);
233
+ }
234
+ EOS ;
235
+ return $ this ->_formatTemplate ( $ tpl , array (
236
+ 'allowed_hosts_regex ' => $ this ->getAllowedHostsRegex () ) );
237
+ }
238
+
223
239
/**
224
240
* Get the base url path regex
225
241
*
@@ -292,7 +308,7 @@ protected function _getDefaultBackend() {
292
308
'first_byte_timeout ' => $ timeout . 's ' ,
293
309
'between_bytes_timeout ' => $ timeout . 's ' ,
294
310
);
295
- if ( Mage::getStoreConfigFlag ( 'turpentine_vcl/backend/load_balancing ' ) ) {
311
+ if ( Mage::getStoreConfig ( 'turpentine_vcl/backend/load_balancing ' ) != ' no ' ) {
296
312
return $ this ->_vcl_director ( 'default ' , $ default_options );
297
313
} else {
298
314
return $ this ->_vcl_backend ( 'default ' ,
@@ -313,7 +329,7 @@ protected function _getAdminBackend() {
313
329
'first_byte_timeout ' => $ timeout . 's ' ,
314
330
'between_bytes_timeout ' => $ timeout . 's ' ,
315
331
);
316
- if ( Mage::getStoreConfigFlag ( 'turpentine_vcl/backend/load_balancing ' ) ) {
332
+ if ( Mage::getStoreConfig ( 'turpentine_vcl/backend/load_balancing ' ) != ' no ' ) {
317
333
return $ this ->_vcl_director ( 'admin ' , $ admin_options );
318
334
} else {
319
335
return $ this ->_vcl_backend ( 'admin ' ,
@@ -821,7 +837,7 @@ protected function _getTemplateVars() {
821
837
'admin_frontname ' => $ this ->_getAdminFrontname (),
822
838
'normalize_host_target ' => $ this ->_getNormalizeHostTarget (),
823
839
'url_base_regex ' => $ this ->getBaseUrlPathRegex (),
824
- 'allowed_hosts_regex ' => $ this ->getAllowedHostsRegex (),
840
+ 'allowed_hosts_regex ' => $ this ->getAllowedHostsRegex (),
825
841
'url_excludes ' => $ this ->_getUrlExcludes (),
826
842
'get_param_excludes ' => $ this ->_getGetParamExcludes (),
827
843
'get_param_ignored ' => $ this ->_getIgnoreGetParameters (),
@@ -857,6 +873,11 @@ protected function _getTemplateVars() {
857
873
'esi_private_ttl ' => Mage::helper ( 'turpentine/esi ' )
858
874
->getDefaultEsiTtl (),
859
875
);
876
+
877
+ if ( (bool )Mage::getStoreConfig ( 'turpentine_vcl/urls/bypass_cache_store_url ' ) ) {
878
+ $ vars ['allowed_hosts ' ] = $ this ->_vcl_sub_allowed_hosts_regex ();
879
+ }
880
+
860
881
if ( Mage::getStoreConfig ( 'turpentine_vcl/normalization/encoding ' ) ) {
861
882
$ vars ['normalize_encoding ' ] = $ this ->_vcl_sub_normalize_encoding ();
862
883
}
@@ -872,7 +893,7 @@ protected function _getTemplateVars() {
872
893
if ( Mage::getStoreConfig ( 'turpentine_vcl/normalization/cookie_target ' ) ) {
873
894
$ vars ['normalize_cookie_target ' ] = $ this ->_getNormalizeCookieTarget ();
874
895
}
875
-
896
+
876
897
$ customIncludeFile = $ this ->_getCustomIncludeFilename ();
877
898
if ( is_readable ( $ customIncludeFile ) ) {
878
899
$ vars ['custom_vcl_include ' ] = file_get_contents ( $ customIncludeFile );
0 commit comments