Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Nexcess.net Turpentine Extension for Magento
* Copyright (C) 2012 Nexcess.net L.L.C.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

class Nexcessnet_Turpentine_Model_Config_Select_NormalizeHost {
/**
* @return array
*/
public function toOptionArray() {
$helper = Mage::helper('turpentine');
return array(
array('value'=>'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')),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<EOS
if (req.http.X-Forwarded-Host)
{
set req.http.Host = req.http.X-Forwarded-Host;
}
EOS;
return $this->_formatTemplate($tpl, array());
}

/**
* Get the hostname for cookie normalization
*
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions app/code/community/Nexcessnet/Turpentine/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
<label>Normalize Host</label>
<comment>Force requests to be for a specific domain name, will probably break most multi-store setups</comment>
<frontend_type>select</frontend_type>
<source_model>turpentine/config_select_toggle</source_model>
<source_model>turpentine/config_select_normalizeHost</source_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
Expand All @@ -445,7 +445,7 @@
<comment>Domain to force requests to, defaults to the domain in the base URL</comment>
<frontend_type>text</frontend_type>
<depends>
<host>1</host>
<host>yes</host>
</depends>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
Expand Down
3 changes: 2 additions & 1 deletion app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}}") {
Expand Down