From 832bac26f31c4c138eaa9cd79f6642b7256facd7 Mon Sep 17 00:00:00 2001 From: sr972 Date: Wed, 6 Apr 2016 12:22:33 +0200 Subject: [PATCH 01/13] Update Abstract.php If in System > Config > Web > Add Store Code to URLs is enabled and a custom admin path is set, then Turpentine will not bypass actions in Magento backend. This PR checks, if the option is set to active and extends the answer by adding the code from store id 0, which is the admin backend store view. --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 86805aea8..253a5e0c7 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -173,7 +173,11 @@ protected function _vcl_call($subroutine) { */ protected function _getAdminFrontname() { if (Mage::getStoreConfig('admin/url/use_custom_path')) { - return Mage::getStoreConfig('admin/url/custom_path'); + if(Mage::getStoreConfig('web/url/use_store')) { + return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path'); + } else { + return Mage::getStoreConfig('admin/url/custom_path'); + } } else { return (string) Mage::getConfig()->getNode( 'admin/routers/adminhtml/args/frontName' ); From 931516c58e357c02547d637d9f6e085e160c8d22 Mon Sep 17 00:00:00 2001 From: Uwe Kleinmann Date: Tue, 3 May 2016 18:48:10 +0200 Subject: [PATCH 02/13] Add varnish-4-compatible load-balancing configuration including separate admin backends. This is based on the proposed fix by @jdmcd12 in nexcess#937. --- .../Model/Varnish/Configurator/Version4.php | 128 ++++++++++++++++++ .../Nexcessnet/Turpentine/misc/version-4.vcl | 9 +- 2 files changed, 136 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 273c09f1a..4320cb65c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -55,6 +55,134 @@ protected function _getTemplateVars() { $vars = parent::_getTemplateVars(); $vars['advanced_session_validation'] = $this->_getAdvancedSessionValidation(); + + if (Mage::getStoreConfig('turpentine_vcl/backend/load_balancing') != 'no') { + $vars['directors'] = $this->_vcl_directors(); + $vars['admin_backend_hint'] = 'vdir_admin.backend()'; + $vars['set_backend_hint'] = 'set req.backend_hint = vdir.backend();'; + } else { + $vars['directors'] = ''; + $vars['admin_backend_hint'] = 'admin'; + $vars['set_backend_hint'] = ''; + } + return $vars; } + + protected function _vcl_directors() + { + $tpl = <<cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin')); + } else { + $adminBackendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); + } + + $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); + + for($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) { + $tpl .= <<_formatTemplate($tpl, $vars); + } + + /** + * Format a VCL director declaration, for load balancing + * + * @param string $name name of the director, also used to select config settings + * @param array $backendOptions options for each backend + * @return string + */ + protected function _vcl_director($name, $backendOptions) { + $tpl = <<cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin')); + $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url_admin'); + $prefix = 'admin'; + } else { + $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); + $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url'); + + if('admin' == $name) { + $prefix = 'admin'; + } else { + $prefix = ''; + } + } + + $backends = ''; + $number = 0; + foreach ($backendNodes as $backendNode) { + $parts = explode(':', $backendNode, 2); + $host = (empty($parts[0])) ? '127.0.0.1' : $parts[0]; + $port = (empty($parts[1])) ? '80' : $parts[1]; + $backends .= $this->_vcl_director_backend($host, $port, $prefix . $number, $probeUrl, $backendOptions); + + $number++; + } + $vars = array( + 'name' => $name, + 'backends' => $backends + ); + return $this->_formatTemplate($tpl, $vars); + } + + /** + * Format a VCL backend declaration to put inside director + * + * @param string $host backend host + * @param string $port backend port + * @param string $descriptor backend descriptor + * @param string $probeUrl URL to check if backend is up + * @param array $options extra options for backend + * @return string + */ + protected function _vcl_director_backend($host, $port, $descriptor, $probeUrl = '', $options = array()) { + $tpl = << $host, + 'port' => $port, + 'probe' => '' + ); + if ( ! empty($probeUrl)) { + $vars['probe'] = $this->_vcl_get_probe($probeUrl); + } + $str = $this->_formatTemplate($tpl, $vars); + foreach ($options as $key => $value) { + $str .= sprintf(' .%s = %s;', $key, $value).PHP_EOL; + } + $str .= << Date: Wed, 4 May 2016 16:10:47 +0200 Subject: [PATCH 04/13] Revert "Add index.php to matching base url prefix." This reverts commit a20bf5ed103631d6b5d84706a40acac28460b05c. --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 1d16eeef0..86805aea8 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -270,7 +270,6 @@ protected function _getBaseUrlPaths() { PHP_URL_PATH); } } - $paths[] = "/index.php/"; $paths = array_unique($paths); usort($paths, create_function('$a, $b', 'return strlen( $b ) - strlen( $a );')); From bec41bc416a0e7b2116ea86d5312eeaa518fab1e Mon Sep 17 00:00:00 2001 From: Jan Fervers Date: Thu, 19 May 2016 20:45:01 +0200 Subject: [PATCH 05/13] version-3.vcl normalization, duplicate cookie fix Fix https://github.com/nexcess/magento-turpentine/pull/1078 Issue collection https://github.com/nexcess/magento-turpentine/issues/1180 --- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 05ac503d2..b29e47e51 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -389,7 +389,7 @@ sub vcl_deliver { "; domain=" + regsub(req.http.Host, ":\d+$", ""); } else { # it's a real user, allow sharing of cookies between stores - if(req.http.Host ~ "{{normalize_cookie_regex}}") { + if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") { set resp.http.Set-Cookie = resp.http.Set-Cookie + "; domain={{normalize_cookie_target}}"; } else { From 660e8ffbb236c57eb57698c435534a6ba768f3b9 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Wed, 8 Jun 2016 12:18:12 -0400 Subject: [PATCH 06/13] Fix for issue #1093 - poll still displaying when module output disabled --- .../Turpentine/Block/Poll/ActivePoll.php | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php index 8322aa069..56343127f 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php @@ -21,11 +21,19 @@ class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll { - public function setTemplate($template) - { - $this->_template = $template; - $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); - $this->setPollTemplate('turpentine/ajax.phtml', 'results'); - return $this; - } + public function setTemplate($template) + { + if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) && + (!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll'))) + { + $this->_template = $template; + $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); + $this->setPollTemplate('turpentine/ajax.phtml', 'results'); + } + else + { + // Mage_Poll is disabled, so do nothing + } + return $this; + } } From 71dc4d66fda0f2681b66d6828a4d9a3778e99cba Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Wed, 22 Jun 2016 18:36:19 +0000 Subject: [PATCH 07/13] Updated to allow custom VCL templats --- .../Model/Varnish/Configurator/Abstract.php | 21 +++++++++++++++++-- .../Model/Varnish/Configurator/Version3.php | 9 +++++++- .../Model/Varnish/Configurator/Version4.php | 9 +++++++- .../Nexcessnet/Turpentine/etc/config.xml | 1 + .../Nexcessnet/Turpentine/etc/system.xml | 9 ++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 86805aea8..d97bf7d26 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -110,8 +110,8 @@ public function save($generatedConfig) { * @return string */ protected function _getVclTemplateFilename($baseFilename) { - $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); - return sprintf('%s/misc/%s', $extensionDir, $baseFilename); + $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); + return sprintf('%s/misc/%s', $extensionDir, $baseFilename); } /** @@ -136,6 +136,23 @@ protected function _getCustomIncludeFilename() { array('root_dir' => Mage::getBaseDir()) ); } + + /** + * Get the custom VCL template, if it exists + * Returns 'null' if the file doesn't exist + * + * @return string + */ + protected function _getCustomTemplateFilename() { + $filePath = $this->_formatTemplate( + Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'), + array('root_dir' => Mage::getBaseDir()) + ); + if (is_file($filePath)) { return $filePath; } + else { return null; } + } + + /** * Format a template string, replacing {{keys}} with the appropriate values * and remove unspecified keys diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index 745ec6076..2247404b0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -31,7 +31,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3 * @return string */ public function generate($doClean = true) { - $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + // first, check if a custom template is set + $customTemplate = $this->_getCustomTemplateFilename(); + if ($customTemplate) { + $tplFile = $customTemplate; + } + else { + $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + } $vcl = $this->_formatTemplate(file_get_contents($tplFile), $this->_getTemplateVars()); return $doClean ? $this->_cleanVcl($vcl) : $vcl; diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 273c09f1a..ba5f42826 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -31,7 +31,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version4 * @return string */ public function generate($doClean = true) { - $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + // first, check if a custom template is set + $customTemplate = $this->_getCustomTemplateFilename(); + if ($customTemplate) { + $tplFile = $customTemplate; + } + else { + $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + } $vcl = $this->_formatTemplate(file_get_contents($tplFile), $this->_getTemplateVars()); return $doClean ? $this->_cleanVcl($vcl) : $vcl; diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 404ca74b5..6bc619ebd 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -47,6 +47,7 @@ 127.0.0.1:6082 {{root_dir}}/var/default.vcl {{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl + diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index a5960bbd0..174c57f54 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -242,6 +242,15 @@ 0 0 + + + text + If defined and present, this template will be used instead of the default VCL template appropriate for the version of Varnish. + 50 + 1 + 0 + 0 + From 2fd128e55de5a522cb0eaab6587d43d6d9ddb40f Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Thu, 23 Jun 2016 15:01:31 +0200 Subject: [PATCH 08/13] Issue #1213: ESI-Blocks are missing "global" blocks like formkey --- .../Nexcessnet/Turpentine/controllers/EsiController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index fb66776ab..45c05d908 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -253,6 +253,15 @@ protected function _getEsiBlock($esiData) { $layout->generateBlocks($node); } } + if ($roots = $layout->getNode()->xpath('//block[@name=\'root\']')) { + foreach (array('formkey') as $globalBlock) { + if ($blocks = $layout->getNode()->xpath(sprintf('//block[@name=\'%s\']', $globalBlock))) { + $dummy = $roots[0]->addChild('reference'); + $dummy->appendChild($blocks[0]); + $layout->generateBlocks($dummy); + } + } + } $block = $layout->getBlock($esiData->getNameInLayout()); if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { From 7f5cc3325fa00316a3330c2267c2073128f337dc Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Thu, 23 Jun 2016 20:02:06 +0000 Subject: [PATCH 09/13] Adds and implements option to log all commands sent to Varnish --- .../Turpentine/Model/Varnish/Admin/Socket.php | 3 +++ .../community/Nexcessnet/Turpentine/etc/system.xml | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php index 4c6e14b48..3df98e393 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -499,6 +499,9 @@ protected function _command($verb, $okCode = 200) { "Got unexpected response code from Varnish: %d\n%s", $response['code'], $response['text'] )); } else { + if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) { + Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data); + } return $response; } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index a5960bbd0..961f9a101 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -82,6 +82,16 @@ 0 0 + + + Log all commands sent to Varnish by Turpentine in the log specified (custom if enabled). Caution - can cause logs to grow quickly! + select + turpentine/config_select_toggle + 45 + 1 + 0 + 0 + Log block names for adding ESI, only enable when needed to avoid performance hit @@ -92,6 +102,8 @@ 0 0 + + Enable fixing the messages block to load via AJAX, disable if you already have an extension that does this From b14b6a9a5e8cec6de8697df4e1d77f144129bfc0 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 28 Jun 2016 20:18:42 -0300 Subject: [PATCH 10/13] Added changelog. --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc646b25f..f58411bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -440,4 +440,11 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#1155] Update TECHNICAL_NOTES.md. (@GLips) ### RELEASE-0.6.9 + * [#1162] Support PHP7. (@allardhoeve) + * [#1173] Fix load balancing for Varnish 4. (@kleinmann) + * [#1182] Update version-3.vcl normalisation. (@gewaechshaus) + +### RELEASE-0.7.0 + + From 959411d26124da9efd0be33db89c01b7861eac70 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Thu, 7 Jul 2016 20:35:42 +0000 Subject: [PATCH 11/13] Adds more information when considering whether to inject a block --- .../Nexcessnet/Turpentine/Model/Observer/Esi.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 0ae107d8c..86d598fc3 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -226,12 +226,19 @@ public function injectEsi($eventObject) { $debugHelper->logInfo( 'Checking ESI block candidate: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); - } + + $debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi()); + $debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template ); + $debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) ); + } if ($esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && $esiOptions = $blockObject->getEsiOptions()) { if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) { + if ($esiHelper->getEsiBlockLogEnabled()) { + $debugHelper->logInfo("-- ESI Injection disabled"); + } return; } From 80bee8dd430150fc7508042eebe7c9c2cb6f9792 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Mon, 11 Jul 2016 17:07:55 +0000 Subject: [PATCH 12/13] Condensed the UA "buckets" down to just "mobile" and "other" for improved cache hitrate --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 86805aea8..8bf76e35d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -769,16 +769,6 @@ protected function _vcl_sub_normalize_user_agent() { $tpl = << Date: Fri, 22 Jul 2016 14:29:12 +0200 Subject: [PATCH 13/13] Fixed Host normalization for certain cases + support X-Forwarded-Host --- .../Model/Config/Select/NormalizeHost.php | 34 +++++++++++++++++++ .../Model/Varnish/Configurator/Abstract.php | 24 +++++++++++-- .../Nexcessnet/Turpentine/etc/system.xml | 4 +-- .../Nexcessnet/Turpentine/misc/version-4.vcl | 3 +- 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 app/code/community/Nexcessnet/Turpentine/Model/Config/Select/NormalizeHost.php diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/NormalizeHost.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/NormalizeHost.php new file mode 100644 index 000000000..010c47d15 --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/NormalizeHost.php @@ -0,0 +1,34 @@ +'yes', 'label'=>Mage::helper('adminhtml')->__('Enable')), + array('value'=>'yes_forwarded_host', 'label'=>$helper->__('Yes, use HTTP X-Forwarded-Host Header')), + array('value'=>'no', 'label'=>Mage::helper('adminhtml')->__('Disable')), + ); + } +} diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 86805aea8..de916901c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -823,6 +823,21 @@ protected function _vcl_sub_normalize_host() { 'normalize_host_target' => $this->_getNormalizeHostTarget() )); } + /** + * Get the Host normalization sub routine + * + * @return string + */ + protected function _vcl_sub_normalize_host_forwarded() { + $tpl = <<_formatTemplate($tpl, array()); + } + /** * Get the hostname for cookie normalization * @@ -990,8 +1005,13 @@ protected function _getTemplateVars() { if (Mage::getStoreConfig('turpentine_vcl/normalization/user_agent')) { $vars['normalize_user_agent'] = $this->_vcl_sub_normalize_user_agent(); } - if (Mage::getStoreConfig('turpentine_vcl/normalization/host')) { - $vars['normalize_host'] = $this->_vcl_sub_normalize_host(); + Mage::log(Mage::getStoreConfig('turpentine_vcl/normalization/host')); + if (Mage::getStoreConfig('turpentine_vcl/normalization/host') && Mage::getStoreConfig('turpentine_vcl/normalization/host') != 'no') { + if (Mage::getStoreConfig('turpentine_vcl/normalization/host') == "yes_forwarded_host") { + $vars['normalize_host'] = $this->_vcl_sub_normalize_host_forwarded(); + } else { + $vars['normalize_host'] = $this->_vcl_sub_normalize_host(); + } } if (Mage::getStoreConfig('turpentine_vcl/normalization/cookie_regex')) { $vars['normalize_cookie_regex'] = $this->_getNormalizeCookieRegex(); diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index a5960bbd0..6c0ebd77e 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -413,7 +413,7 @@ Force requests to be for a specific domain name, will probably break most multi-store setups select - turpentine/config_select_toggle + turpentine/config_select_normalizeHost 30 1 0 @@ -424,7 +424,7 @@ Domain to force requests to, defaults to the domain in the base URL text - 1 + yes 40 1 diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 757601a6f..6ba4018c5 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -110,6 +110,8 @@ sub vcl_recv { } } + {{normalize_host}} + # We only deal with GET and HEAD by default # we test this here instead of inside the url base regex section # so we can disable caching for the entire site if needed @@ -129,7 +131,6 @@ sub vcl_recv { {{normalize_encoding}} {{normalize_user_agent}} - {{normalize_host}} # check if the request is for part of magento if (req.url ~ "{{url_base_regex}}") {