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
Expand Up @@ -808,18 +808,23 @@ protected function _vcl_acl($name, array $hosts) {
* @return string
*/
protected function _vcl_sub_normalize_user_agent() {
/**
* Mobile regex from
* @link http://magebase.com/magento-tutorials/magento-design-exceptions-explained/
*/

$mobileRegexp = $this->_getMobileUserAgentRegex();
$tpl = <<<EOS
if (req.http.User-Agent ~ "iP(?:hone|ad|od)|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera (?:Mini|Mobi)") {
set req.http.X-Normalized-User-Agent = "other";
EOS;
if(!empty($mobileRegexp)){
$tplContent = '
if (req.http.User-Agent ~ "'.$mobileRegexp.'") {
set req.http.X-Normalized-User-Agent = "mobile";
} else {
set req.http.X-Normalized-User-Agent = "other";
}
}';

$tpl .= <<<"EOS"
$tplContent
EOS;

}

return $tpl;
}

Expand Down Expand Up @@ -879,6 +884,16 @@ protected function _getNormalizeCookieRegex() {
'turpentine_vcl/normalization/cookie_regex' ));
}

/**
* Get the regex for mobile user agent
*
* @return string
*/
protected function _getMobileUserAgentRegex() {
return trim(Mage::getStoreConfig(
'turpentine_vcl/normalization/user_agent_mobile_regexp' ));
}

/**
* Get the allowed IPs when in maintenance mode
*
Expand Down Expand Up @@ -1157,7 +1172,7 @@ protected function _getTemplateVars() {
if (Mage::getStoreConfig('turpentine_varnish/general/https_proto_fix')) {
$vars['https_proto_fix'] = $this->_vcl_sub_https_proto_fix();
}

if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) {
$vars['https_redirect'] = $this->_vcl_sub_https_redirect_fix();
if (Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0' || Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.1') {
Expand Down
1 change: 1 addition & 0 deletions app/code/community/Nexcessnet/Turpentine/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<normalization>
<encoding>1</encoding>
<user_agent>0</user_agent>
<user_agent_mobile_regexp><![CDATA[iP(?:hone|ad|od)|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera (?:Mini|Mobi)]]></user_agent_mobile_regexp>
<host>0</host>
</normalization>
<ttls>
Expand Down
12 changes: 12 additions & 0 deletions app/code/community/Nexcessnet/Turpentine/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,18 @@
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</user_agent>
<user_agent_mobile_regexp translate="label" module="turpentine">
<label>Regexp for Mobile User-Agent</label>
<comment><![CDATA[See for example http://magebase.com/magento-tutorials/magento-design-exceptions-explained/]]></comment>
<frontend_type>text</frontend_type>
<sort_order>25</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<depends>
<user_agent>1</user_agent>
</depends>
</user_agent_mobile_regexp>
<host translate="label" module="turpentine">
<label>Normalize Host</label>
<comment>Force requests to be for a specific domain name, will probably break most multi-store setups</comment>
Expand Down