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 7d1fb8c99..88fb04b75 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -834,6 +834,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 * @@ -1001,8 +1016,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 ee2348f09..29776d6ad 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -434,7 +434,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 @@ -445,7 +445,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 8fd775961..329dabb6f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -115,6 +115,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 @@ -134,7 +136,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}}") {