Version Notes
Supports Magento v1.6 and later
Download this release
Release Info
Developer | Chris Wells |
Extension | Nexcessnet_Turpentine |
Version | 0.7.1 |
Comparing to | |
See all releases |
Code changes from version 0.7.0 to 0.7.1
- app/code/community/Nexcessnet/Turpentine/Block/Management.php +1 -1
- app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +15 -7
- app/code/community/Nexcessnet/Turpentine/Helper/Data.php +2 -2
- app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +10 -1
- app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +5 -2
- app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +106 -19
- app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +8 -1
- app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +136 -1
- app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +12 -0
- app/code/community/Nexcessnet/Turpentine/etc/config.xml +4 -2
- app/code/community/Nexcessnet/Turpentine/etc/system.xml +44 -4
- app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +6 -2
- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +16 -2
- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +37 -2
- app/design/frontend/base/default/layout/turpentine_esi.xml +6 -1
- app/design/frontend/base/default/template/turpentine/ajax.phtml +3 -1
- package.xml +1 -1
app/code/community/Nexcessnet/Turpentine/Block/Management.php
CHANGED
@@ -24,7 +24,7 @@ class Nexcessnet_Turpentine_Block_Management
|
|
24 |
|
25 |
public function __construct() {
|
26 |
$this->_controller = 'varnish_management';
|
27 |
-
|
28 |
parent::__construct();
|
29 |
}
|
30 |
|
24 |
|
25 |
public function __construct() {
|
26 |
$this->_controller = 'varnish_management';
|
27 |
+
|
28 |
parent::__construct();
|
29 |
}
|
30 |
|
app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php
CHANGED
@@ -21,11 +21,19 @@
|
|
21 |
|
22 |
class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll {
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
21 |
|
22 |
class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll {
|
23 |
|
24 |
+
public function setTemplate($template)
|
25 |
+
{
|
26 |
+
if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) &&
|
27 |
+
(!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll')))
|
28 |
+
{
|
29 |
+
$this->_template = $template;
|
30 |
+
$this->setPollTemplate('turpentine/ajax.phtml', 'poll');
|
31 |
+
$this->setPollTemplate('turpentine/ajax.phtml', 'results');
|
32 |
+
}
|
33 |
+
else
|
34 |
+
{
|
35 |
+
// Mage_Poll is disabled, so do nothing
|
36 |
+
}
|
37 |
+
return $this;
|
38 |
+
}
|
39 |
}
|
app/code/community/Nexcessnet/Turpentine/Helper/Data.php
CHANGED
@@ -130,7 +130,7 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
130 |
public function urlBase64Encode($str) {
|
131 |
return str_replace(
|
132 |
array('/', '+'),
|
133 |
-
array('
|
134 |
base64_encode($str) );
|
135 |
}
|
136 |
|
@@ -143,7 +143,7 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
143 |
public function urlBase64Decode($str) {
|
144 |
return base64_decode(
|
145 |
str_replace(
|
146 |
-
array('
|
147 |
array('/', '+'),
|
148 |
$str ) );
|
149 |
}
|
130 |
public function urlBase64Encode($str) {
|
131 |
return str_replace(
|
132 |
array('/', '+'),
|
133 |
+
array('_', '-'),
|
134 |
base64_encode($str) );
|
135 |
}
|
136 |
|
143 |
public function urlBase64Decode($str) {
|
144 |
return base64_decode(
|
145 |
str_replace(
|
146 |
+
array('_', '-'),
|
147 |
array('/', '+'),
|
148 |
$str ) );
|
149 |
}
|
app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php
CHANGED
@@ -226,12 +226,19 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
226 |
$debugHelper->logInfo(
|
227 |
'Checking ESI block candidate: %s',
|
228 |
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
|
229 |
-
|
|
|
|
|
|
|
|
|
230 |
if ($esiHelper->shouldResponseUseEsi() &&
|
231 |
$blockObject instanceof Mage_Core_Block_Template &&
|
232 |
$esiOptions = $blockObject->getEsiOptions()) {
|
233 |
|
234 |
if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) {
|
|
|
|
|
|
|
235 |
return;
|
236 |
}
|
237 |
|
@@ -325,6 +332,8 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
325 |
$methodParam = $esiHelper->getEsiMethodParam();
|
326 |
$esiData = new Varien_Object();
|
327 |
$esiData->setStoreId(Mage::app()->getStore()->getId());
|
|
|
|
|
328 |
$esiData->setNameInLayout($blockObject->getNameInLayout());
|
329 |
$esiData->setBlockType(get_class($blockObject));
|
330 |
$esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject));
|
226 |
$debugHelper->logInfo(
|
227 |
'Checking ESI block candidate: %s',
|
228 |
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
|
229 |
+
|
230 |
+
$debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi());
|
231 |
+
$debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template );
|
232 |
+
$debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) );
|
233 |
+
}
|
234 |
if ($esiHelper->shouldResponseUseEsi() &&
|
235 |
$blockObject instanceof Mage_Core_Block_Template &&
|
236 |
$esiOptions = $blockObject->getEsiOptions()) {
|
237 |
|
238 |
if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) {
|
239 |
+
if ($esiHelper->getEsiBlockLogEnabled()) {
|
240 |
+
$debugHelper->logInfo("-- ESI Injection disabled");
|
241 |
+
}
|
242 |
return;
|
243 |
}
|
244 |
|
332 |
$methodParam = $esiHelper->getEsiMethodParam();
|
333 |
$esiData = new Varien_Object();
|
334 |
$esiData->setStoreId(Mage::app()->getStore()->getId());
|
335 |
+
$esiData->setDesignPackage( Mage::getDesign()->getPackageName() );
|
336 |
+
$esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) );
|
337 |
$esiData->setNameInLayout($blockObject->getNameInLayout());
|
338 |
$esiData->setBlockType(get_class($blockObject));
|
339 |
$esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject));
|
app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php
CHANGED
@@ -407,12 +407,12 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket {
|
|
407 |
$regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~';
|
408 |
if ($this->getVersion() === '4.0') {
|
409 |
// Varnish4 supports "16k" style notation
|
410 |
-
$regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g]{1})?\s+\[bytes\]~';
|
411 |
}
|
412 |
if (preg_match($regexp, $cliBufferResponse['text'], $match)) {
|
413 |
$realLimit = (int) $match[1];
|
414 |
if (isset($match[2])) {
|
415 |
-
$factors = array('k'=>1, 'm'=>2, 'g'=>3);
|
416 |
$realLimit *= pow(1024, $factors[$match[2]]);
|
417 |
}
|
418 |
} else {
|
@@ -499,6 +499,9 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket {
|
|
499 |
"Got unexpected response code from Varnish: %d\n%s",
|
500 |
$response['code'], $response['text'] ));
|
501 |
} else {
|
|
|
|
|
|
|
502 |
return $response;
|
503 |
}
|
504 |
}
|
407 |
$regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~';
|
408 |
if ($this->getVersion() === '4.0') {
|
409 |
// Varnish4 supports "16k" style notation
|
410 |
+
$regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g|b]{1})?\s+\[bytes\]~';
|
411 |
}
|
412 |
if (preg_match($regexp, $cliBufferResponse['text'], $match)) {
|
413 |
$realLimit = (int) $match[1];
|
414 |
if (isset($match[2])) {
|
415 |
+
$factors = array('b'=>0, 'k'=>1, 'm'=>2, 'g'=>3);
|
416 |
$realLimit *= pow(1024, $factors[$match[2]]);
|
417 |
}
|
418 |
} else {
|
499 |
"Got unexpected response code from Varnish: %d\n%s",
|
500 |
$response['code'], $response['text'] ));
|
501 |
} else {
|
502 |
+
if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) {
|
503 |
+
Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data);
|
504 |
+
}
|
505 |
return $response;
|
506 |
}
|
507 |
}
|
app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php
CHANGED
@@ -110,8 +110,8 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract {
|
|
110 |
* @return string
|
111 |
*/
|
112 |
protected function _getVclTemplateFilename($baseFilename) {
|
113 |
-
|
114 |
-
|
115 |
}
|
116 |
|
117 |
/**
|
@@ -130,12 +130,31 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract {
|
|
130 |
*
|
131 |
* @return string
|
132 |
*/
|
133 |
-
protected function _getCustomIncludeFilename() {
|
|
|
|
|
134 |
return $this->_formatTemplate(
|
135 |
-
Mage::getStoreConfig('turpentine_varnish/servers/
|
136 |
array('root_dir' => Mage::getBaseDir()) );
|
137 |
}
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
/**
|
140 |
* Format a template string, replacing {{keys}} with the appropriate values
|
141 |
* and remove unspecified keys
|
@@ -173,7 +192,11 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract {
|
|
173 |
*/
|
174 |
protected function _getAdminFrontname() {
|
175 |
if (Mage::getStoreConfig('admin/url/use_custom_path')) {
|
176 |
-
|
|
|
|
|
|
|
|
|
177 |
} else {
|
178 |
return (string) Mage::getConfig()->getNode(
|
179 |
'admin/routers/adminhtml/args/frontName' );
|
@@ -769,16 +792,6 @@ EOS;
|
|
769 |
$tpl = <<<EOS
|
770 |
if (req.http.User-Agent ~ "iP(?:hone|ad|od)|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera (?:Mini|Mobi)") {
|
771 |
set req.http.X-Normalized-User-Agent = "mobile";
|
772 |
-
} else if (req.http.User-Agent ~ "MSIE") {
|
773 |
-
set req.http.X-Normalized-User-Agent = "msie";
|
774 |
-
} else if (req.http.User-Agent ~ "Firefox") {
|
775 |
-
set req.http.X-Normalized-User-Agent = "firefox";
|
776 |
-
} else if (req.http.User-Agent ~ "Chrome") {
|
777 |
-
set req.http.X-Normalized-User-Agent = "chrome";
|
778 |
-
} else if (req.http.User-Agent ~ "Safari") {
|
779 |
-
set req.http.X-Normalized-User-Agent = "safari";
|
780 |
-
} else if (req.http.User-Agent ~ "Opera") {
|
781 |
-
set req.http.X-Normalized-User-Agent = "opera";
|
782 |
} else {
|
783 |
set req.http.X-Normalized-User-Agent = "other";
|
784 |
}
|
@@ -795,7 +808,7 @@ EOS;
|
|
795 |
protected function _vcl_sub_normalize_encoding() {
|
796 |
$tpl = <<<EOS
|
797 |
if (req.http.Accept-Encoding) {
|
798 |
-
if (req.http.Accept-Encoding ~ "gzip") {
|
799 |
set req.http.Accept-Encoding = "gzip";
|
800 |
} else if (req.http.Accept-Encoding ~ "deflate") {
|
801 |
set req.http.Accept-Encoding = "deflate";
|
@@ -887,6 +900,35 @@ EOS;
|
|
887 |
'debug_ips' => Mage::getStoreConfig('dev/restrict/allow_ips') ));
|
888 |
}
|
889 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
890 |
/**
|
891 |
* Get the allowed IPs when in maintenance mode
|
892 |
*
|
@@ -927,6 +969,40 @@ EOS;
|
|
927 |
'vcl_synth_content' => Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')));
|
928 |
}
|
929 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
930 |
|
931 |
|
932 |
/**
|
@@ -1006,10 +1082,21 @@ EOS;
|
|
1006 |
// set the vcl_error from Magento database
|
1007 |
$vars['vcl_synth'] = $this->_vcl_sub_synth();
|
1008 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1009 |
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
|
|
|
|
|
|
|
|
1013 |
}
|
1014 |
|
1015 |
return $vars;
|
110 |
* @return string
|
111 |
*/
|
112 |
protected function _getVclTemplateFilename($baseFilename) {
|
113 |
+
$extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine');
|
114 |
+
return sprintf('%s/misc/%s', $extensionDir, $baseFilename);
|
115 |
}
|
116 |
|
117 |
/**
|
130 |
*
|
131 |
* @return string
|
132 |
*/
|
133 |
+
protected function _getCustomIncludeFilename($position='') {
|
134 |
+
$key = 'custom_include_file';
|
135 |
+
$key .= ($position) ? '_'.$position : '';
|
136 |
return $this->_formatTemplate(
|
137 |
+
Mage::getStoreConfig('turpentine_varnish/servers/'.$key),
|
138 |
array('root_dir' => Mage::getBaseDir()) );
|
139 |
}
|
140 |
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Get the custom VCL template, if it exists
|
144 |
+
* Returns 'null' if the file doesn't exist
|
145 |
+
*
|
146 |
+
* @return string
|
147 |
+
*/
|
148 |
+
protected function _getCustomTemplateFilename() {
|
149 |
+
$filePath = $this->_formatTemplate(
|
150 |
+
Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'),
|
151 |
+
array('root_dir' => Mage::getBaseDir())
|
152 |
+
);
|
153 |
+
if (is_file($filePath)) { return $filePath; }
|
154 |
+
else { return null; }
|
155 |
+
}
|
156 |
+
|
157 |
+
|
158 |
/**
|
159 |
* Format a template string, replacing {{keys}} with the appropriate values
|
160 |
* and remove unspecified keys
|
192 |
*/
|
193 |
protected function _getAdminFrontname() {
|
194 |
if (Mage::getStoreConfig('admin/url/use_custom_path')) {
|
195 |
+
if(Mage::getStoreConfig('web/url/use_store')) {
|
196 |
+
return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path');
|
197 |
+
} else {
|
198 |
+
return Mage::getStoreConfig('admin/url/custom_path');
|
199 |
+
}
|
200 |
} else {
|
201 |
return (string) Mage::getConfig()->getNode(
|
202 |
'admin/routers/adminhtml/args/frontName' );
|
792 |
$tpl = <<<EOS
|
793 |
if (req.http.User-Agent ~ "iP(?:hone|ad|od)|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera (?:Mini|Mobi)") {
|
794 |
set req.http.X-Normalized-User-Agent = "mobile";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
795 |
} else {
|
796 |
set req.http.X-Normalized-User-Agent = "other";
|
797 |
}
|
808 |
protected function _vcl_sub_normalize_encoding() {
|
809 |
$tpl = <<<EOS
|
810 |
if (req.http.Accept-Encoding) {
|
811 |
+
if (req.http.Accept-Encoding ~ "\*|gzip") {
|
812 |
set req.http.Accept-Encoding = "gzip";
|
813 |
} else if (req.http.Accept-Encoding ~ "deflate") {
|
814 |
set req.http.Accept-Encoding = "deflate";
|
900 |
'debug_ips' => Mage::getStoreConfig('dev/restrict/allow_ips') ));
|
901 |
}
|
902 |
|
903 |
+
/**
|
904 |
+
* When using Varnish as front door listen on port 80 and Nginx/Apache listen on port 443 for HTTPS, the fix will keep the url parameters when redirect from HTTP to HTTPS.
|
905 |
+
*
|
906 |
+
* @return string
|
907 |
+
*/
|
908 |
+
protected function _vcl_sub_https_redirect_fix() {
|
909 |
+
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
910 |
+
$baseUrl = str_replace(array('http://','https://'), '', $baseUrl);
|
911 |
+
$baseUrl = rtrim($baseUrl,'/');
|
912 |
+
|
913 |
+
switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
|
914 |
+
case 4.0:
|
915 |
+
$tpl = <<<EOS
|
916 |
+
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
|
917 |
+
return (synth(750, ""));
|
918 |
+
}
|
919 |
+
EOS;
|
920 |
+
break;
|
921 |
+
default:
|
922 |
+
$tpl = <<<EOS
|
923 |
+
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
|
924 |
+
error 750 "https://" + req.http.host + req.url;
|
925 |
+
}
|
926 |
+
EOS;
|
927 |
+
}
|
928 |
+
|
929 |
+
return $tpl;
|
930 |
+
}
|
931 |
+
|
932 |
/**
|
933 |
* Get the allowed IPs when in maintenance mode
|
934 |
*
|
969 |
'vcl_synth_content' => Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')));
|
970 |
}
|
971 |
|
972 |
+
/**
|
973 |
+
* vcl_synth for fixing https
|
974 |
+
*
|
975 |
+
* @return string
|
976 |
+
*/
|
977 |
+
protected function _vcl_sub_synth_https_fix()
|
978 |
+
{
|
979 |
+
$tpl = $this->_vcl_sub_synth();
|
980 |
+
|
981 |
+
if(!$tpl){
|
982 |
+
$tpl = <<<EOS
|
983 |
+
sub vcl_synth {
|
984 |
+
if (resp.status == 750) {
|
985 |
+
set resp.status = 301;
|
986 |
+
set resp.http.Location = "https://" + req.http.host + req.url;
|
987 |
+
return(deliver);
|
988 |
+
}
|
989 |
+
}
|
990 |
+
EOS;
|
991 |
+
}else{
|
992 |
+
$tpl_750 = '
|
993 |
+
sub vcl_synth {
|
994 |
+
if (resp.status == 750) {
|
995 |
+
set resp.status = 301;
|
996 |
+
set resp.http.Location = "https://" + req.http.host + req.url;
|
997 |
+
return(deliver);
|
998 |
+
}';
|
999 |
+
|
1000 |
+
$tpl = str_ireplace('sub vcl_synth {', $tpl_750, $tpl);
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
return $tpl;
|
1004 |
+
}
|
1005 |
+
|
1006 |
|
1007 |
|
1008 |
/**
|
1082 |
// set the vcl_error from Magento database
|
1083 |
$vars['vcl_synth'] = $this->_vcl_sub_synth();
|
1084 |
}
|
1085 |
+
|
1086 |
+
if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) {
|
1087 |
+
$vars['https_redirect'] = $this->_vcl_sub_https_redirect_fix();
|
1088 |
+
if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0'){
|
1089 |
+
$vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix();
|
1090 |
+
}
|
1091 |
+
}
|
1092 |
|
1093 |
+
foreach (array('','top') as $position) {
|
1094 |
+
$customIncludeFile = $this->_getCustomIncludeFilename($position);
|
1095 |
+
if (is_readable($customIncludeFile)) {
|
1096 |
+
$key = 'custom_vcl_include';
|
1097 |
+
$key .= ($position) ? '_'.$position : '';
|
1098 |
+
$vars[$key] = file_get_contents($customIncludeFile);
|
1099 |
+
}
|
1100 |
}
|
1101 |
|
1102 |
return $vars;
|
app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php
CHANGED
@@ -31,7 +31,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3
|
|
31 |
* @return string
|
32 |
*/
|
33 |
public function generate($doClean = true) {
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
|
36 |
$this->_getTemplateVars());
|
37 |
return $doClean ? $this->_cleanVcl($vcl) : $vcl;
|
31 |
* @return string
|
32 |
*/
|
33 |
public function generate($doClean = true) {
|
34 |
+
// first, check if a custom template is set
|
35 |
+
$customTemplate = $this->_getCustomTemplateFilename();
|
36 |
+
if ($customTemplate) {
|
37 |
+
$tplFile = $customTemplate;
|
38 |
+
}
|
39 |
+
else {
|
40 |
+
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
|
41 |
+
}
|
42 |
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
|
43 |
$this->_getTemplateVars());
|
44 |
return $doClean ? $this->_cleanVcl($vcl) : $vcl;
|
app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php
CHANGED
@@ -31,7 +31,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version4
|
|
31 |
* @return string
|
32 |
*/
|
33 |
public function generate($doClean = true) {
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
|
36 |
$this->_getTemplateVars());
|
37 |
return $doClean ? $this->_cleanVcl($vcl) : $vcl;
|
@@ -55,6 +62,134 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version4
|
|
55 |
$vars = parent::_getTemplateVars();
|
56 |
$vars['advanced_session_validation'] =
|
57 |
$this->_getAdvancedSessionValidation();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
return $vars;
|
59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
31 |
* @return string
|
32 |
*/
|
33 |
public function generate($doClean = true) {
|
34 |
+
// first, check if a custom template is set
|
35 |
+
$customTemplate = $this->_getCustomTemplateFilename();
|
36 |
+
if ($customTemplate) {
|
37 |
+
$tplFile = $customTemplate;
|
38 |
+
}
|
39 |
+
else {
|
40 |
+
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
|
41 |
+
}
|
42 |
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
|
43 |
$this->_getTemplateVars());
|
44 |
return $doClean ? $this->_cleanVcl($vcl) : $vcl;
|
62 |
$vars = parent::_getTemplateVars();
|
63 |
$vars['advanced_session_validation'] =
|
64 |
$this->_getAdvancedSessionValidation();
|
65 |
+
|
66 |
+
if (Mage::getStoreConfig('turpentine_vcl/backend/load_balancing') != 'no') {
|
67 |
+
$vars['directors'] = $this->_vcl_directors();
|
68 |
+
$vars['admin_backend_hint'] = 'vdir_admin.backend()';
|
69 |
+
$vars['set_backend_hint'] = 'set req.backend_hint = vdir.backend();';
|
70 |
+
} else {
|
71 |
+
$vars['directors'] = '';
|
72 |
+
$vars['admin_backend_hint'] = 'admin';
|
73 |
+
$vars['set_backend_hint'] = '';
|
74 |
+
}
|
75 |
+
|
76 |
return $vars;
|
77 |
}
|
78 |
+
|
79 |
+
protected function _vcl_directors()
|
80 |
+
{
|
81 |
+
$tpl = <<<EOS
|
82 |
+
new vdir = directors.round_robin();
|
83 |
+
new vdir_admin = directors.round_robin();
|
84 |
+
EOS;
|
85 |
+
|
86 |
+
if ('yes_admin' == Mage::getStoreConfig('turpentine_vcl/backend/load_balancing')) {
|
87 |
+
$adminBackendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
|
88 |
+
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin'));
|
89 |
+
} else {
|
90 |
+
$adminBackendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
|
91 |
+
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes'));
|
92 |
+
}
|
93 |
+
|
94 |
+
$backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
|
95 |
+
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes'));
|
96 |
+
|
97 |
+
for($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) {
|
98 |
+
$tpl .= <<<EOS
|
99 |
+
vdir.add_backend(web{$i});
|
100 |
+
EOS;
|
101 |
+
}
|
102 |
+
|
103 |
+
for($i = 0, $iMax = count($adminBackendNodes); $i < $iMax; $i++) {
|
104 |
+
$tpl .= <<<EOS
|
105 |
+
vdir_admin.add_backend(webadmin{$i});
|
106 |
+
EOS;
|
107 |
+
}
|
108 |
+
|
109 |
+
$vars = array();
|
110 |
+
|
111 |
+
return $this->_formatTemplate($tpl, $vars);
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Format a VCL director declaration, for load balancing
|
116 |
+
*
|
117 |
+
* @param string $name name of the director, also used to select config settings
|
118 |
+
* @param array $backendOptions options for each backend
|
119 |
+
* @return string
|
120 |
+
*/
|
121 |
+
protected function _vcl_director($name, $backendOptions) {
|
122 |
+
$tpl = <<<EOS
|
123 |
+
{{backends}}
|
124 |
+
EOS;
|
125 |
+
if ('admin' == $name && 'yes_admin' == Mage::getStoreConfig('turpentine_vcl/backend/load_balancing')) {
|
126 |
+
$backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
|
127 |
+
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin'));
|
128 |
+
$probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url_admin');
|
129 |
+
$prefix = 'admin';
|
130 |
+
} else {
|
131 |
+
$backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
|
132 |
+
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes'));
|
133 |
+
$probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url');
|
134 |
+
|
135 |
+
if('admin' == $name) {
|
136 |
+
$prefix = 'admin';
|
137 |
+
} else {
|
138 |
+
$prefix = '';
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
$backends = '';
|
143 |
+
$number = 0;
|
144 |
+
foreach ($backendNodes as $backendNode) {
|
145 |
+
$parts = explode(':', $backendNode, 2);
|
146 |
+
$host = (empty($parts[0])) ? '127.0.0.1' : $parts[0];
|
147 |
+
$port = (empty($parts[1])) ? '80' : $parts[1];
|
148 |
+
$backends .= $this->_vcl_director_backend($host, $port, $prefix . $number, $probeUrl, $backendOptions);
|
149 |
+
|
150 |
+
$number++;
|
151 |
+
}
|
152 |
+
$vars = array(
|
153 |
+
'name' => $name,
|
154 |
+
'backends' => $backends
|
155 |
+
);
|
156 |
+
return $this->_formatTemplate($tpl, $vars);
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Format a VCL backend declaration to put inside director
|
161 |
+
*
|
162 |
+
* @param string $host backend host
|
163 |
+
* @param string $port backend port
|
164 |
+
* @param string $descriptor backend descriptor
|
165 |
+
* @param string $probeUrl URL to check if backend is up
|
166 |
+
* @param array $options extra options for backend
|
167 |
+
* @return string
|
168 |
+
*/
|
169 |
+
protected function _vcl_director_backend($host, $port, $descriptor, $probeUrl = '', $options = array()) {
|
170 |
+
$tpl = <<<EOS
|
171 |
+
backend web{$descriptor} {
|
172 |
+
.host = "{{host}}";
|
173 |
+
.port = "{{port}}";
|
174 |
+
{{probe}}
|
175 |
+
|
176 |
+
EOS;
|
177 |
+
$vars = array(
|
178 |
+
'host' => $host,
|
179 |
+
'port' => $port,
|
180 |
+
'probe' => ''
|
181 |
+
);
|
182 |
+
if ( ! empty($probeUrl)) {
|
183 |
+
$vars['probe'] = $this->_vcl_get_probe($probeUrl);
|
184 |
+
}
|
185 |
+
$str = $this->_formatTemplate($tpl, $vars);
|
186 |
+
foreach ($options as $key => $value) {
|
187 |
+
$str .= sprintf(' .%s = %s;', $key, $value).PHP_EOL;
|
188 |
+
}
|
189 |
+
$str .= <<<EOS
|
190 |
+
}
|
191 |
+
|
192 |
+
EOS;
|
193 |
+
return $str;
|
194 |
+
}
|
195 |
}
|
app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php
CHANGED
@@ -183,6 +183,9 @@ class Nexcessnet_Turpentine_EsiController extends Mage_Core_Controller_Front_Act
|
|
183 |
}
|
184 |
}
|
185 |
$layout = Mage::getSingleton('core/layout');
|
|
|
|
|
|
|
186 |
|
187 |
// dispatch event for adding handles to layout update
|
188 |
Mage::dispatchEvent(
|
@@ -253,6 +256,15 @@ class Nexcessnet_Turpentine_EsiController extends Mage_Core_Controller_Front_Act
|
|
253 |
$layout->generateBlocks($node);
|
254 |
}
|
255 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
$block = $layout->getBlock($esiData->getNameInLayout());
|
257 |
|
258 |
if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) {
|
183 |
}
|
184 |
}
|
185 |
$layout = Mage::getSingleton('core/layout');
|
186 |
+
Mage::getSingleton( 'core/design_package' )
|
187 |
+
->setPackageName( $esiData->getDesignPackage() )
|
188 |
+
->setTheme( $esiData->getDesignTheme() );
|
189 |
|
190 |
// dispatch event for adding handles to layout update
|
191 |
Mage::dispatchEvent(
|
256 |
$layout->generateBlocks($node);
|
257 |
}
|
258 |
}
|
259 |
+
if ($roots = $layout->getNode()->xpath('//block[@name=\'root\']')) {
|
260 |
+
foreach (array('formkey') as $globalBlock) {
|
261 |
+
if ($blocks = $layout->getNode()->xpath(sprintf('//block[@name=\'%s\']', $globalBlock))) {
|
262 |
+
$dummy = $roots[0]->addChild('reference');
|
263 |
+
$dummy->appendChild($blocks[0]);
|
264 |
+
$layout->generateBlocks($dummy);
|
265 |
+
}
|
266 |
+
}
|
267 |
+
}
|
268 |
$block = $layout->getBlock($esiData->getNameInLayout());
|
269 |
|
270 |
if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) {
|
app/code/community/Nexcessnet/Turpentine/etc/config.xml
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
<config>
|
21 |
<modules>
|
22 |
<Nexcessnet_Turpentine>
|
23 |
-
<version>0.7.
|
24 |
</Nexcessnet_Turpentine>
|
25 |
</modules>
|
26 |
<default>
|
@@ -47,6 +47,8 @@
|
|
47 |
<server_list>127.0.0.1:6082</server_list>
|
48 |
<config_file>{{root_dir}}/var/default.vcl</config_file>
|
49 |
<custom_include_file>{{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl</custom_include_file>
|
|
|
|
|
50 |
</servers>
|
51 |
</turpentine_varnish>
|
52 |
<turpentine_vcl>
|
@@ -61,7 +63,7 @@
|
|
61 |
<frontend_timeout>300</frontend_timeout>
|
62 |
<admin_timeout>21600</admin_timeout>
|
63 |
<crawlers>127.0.0.1</crawlers>
|
64 |
-
<crawler_user_agents><![CDATA[ApacheBench/.*,.*Googlebot.*,JoeDog
|
65 |
</backend>
|
66 |
<normalization>
|
67 |
<encoding>1</encoding>
|
20 |
<config>
|
21 |
<modules>
|
22 |
<Nexcessnet_Turpentine>
|
23 |
+
<version>0.7.1</version>
|
24 |
</Nexcessnet_Turpentine>
|
25 |
</modules>
|
26 |
<default>
|
47 |
<server_list>127.0.0.1:6082</server_list>
|
48 |
<config_file>{{root_dir}}/var/default.vcl</config_file>
|
49 |
<custom_include_file>{{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl</custom_include_file>
|
50 |
+
<custom_include_file_top>{{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include_top.vcl</custom_include_file_top>
|
51 |
+
<custom_vcl_template></custom_vcl_template>
|
52 |
</servers>
|
53 |
</turpentine_varnish>
|
54 |
<turpentine_vcl>
|
63 |
<frontend_timeout>300</frontend_timeout>
|
64 |
<admin_timeout>21600</admin_timeout>
|
65 |
<crawlers>127.0.0.1</crawlers>
|
66 |
+
<crawler_user_agents><![CDATA[ApacheBench/.*,.*Googlebot.*,JoeDog/.*,.*Siege/.*,magespeedtest\.com,Nexcessnet_Turpentine/.*,.*PTST.*]]></crawler_user_agents>
|
67 |
</backend>
|
68 |
<normalization>
|
69 |
<encoding>1</encoding>
|
app/code/community/Nexcessnet/Turpentine/etc/system.xml
CHANGED
@@ -66,12 +66,22 @@
|
|
66 |
<label>Use VCL fix</label>
|
67 |
<comment>When Enable is selected, a VCL fix will be used to prevent formKey issues. If Disable is selected, an observer will be used.</comment>
|
68 |
<frontend_type>select</frontend_type>
|
69 |
-
<sort_order>
|
70 |
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
71 |
<show_in_default>1</show_in_default>
|
72 |
<show_in_website>1</show_in_website>
|
73 |
<show_in_store>1</show_in_store>
|
74 |
</vcl_fix>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
<varnish_debug translate="label" module="turpentine">
|
76 |
<label>Enable Debug Info</label>
|
77 |
<comment>It is a major security vulnerability, to leave this enabled on production sites</comment>
|
@@ -82,6 +92,16 @@
|
|
82 |
<show_in_website>0</show_in_website>
|
83 |
<show_in_store>0</show_in_store>
|
84 |
</varnish_debug>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
<block_debug translate="label" module="turpentine">
|
86 |
<label>Enable Block Logging</label>
|
87 |
<comment>Log block names for adding ESI, only enable when needed to avoid performance hit</comment>
|
@@ -92,6 +112,8 @@
|
|
92 |
<show_in_website>0</show_in_website>
|
93 |
<show_in_store>0</show_in_store>
|
94 |
</block_debug>
|
|
|
|
|
95 |
<ajax_messages translate="label" module="turpentine">
|
96 |
<label>Enable AJAX Flash Messages</label>
|
97 |
<comment>Enable fixing the messages block to load via AJAX, disable if you already have an extension that does this</comment>
|
@@ -233,15 +255,33 @@
|
|
233 |
<show_in_website>0</show_in_website>
|
234 |
<show_in_store>0</show_in_store>
|
235 |
</config_file>
|
236 |
-
<
|
237 |
-
<label>Custom VCL File
|
238 |
<frontend_type>text</frontend_type>
|
239 |
-
<comment>
|
240 |
<sort_order>40</sort_order>
|
241 |
<show_in_default>1</show_in_default>
|
242 |
<show_in_website>0</show_in_website>
|
243 |
<show_in_store>0</show_in_store>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
</custom_include_file>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
</fields>
|
246 |
</servers>
|
247 |
</groups>
|
66 |
<label>Use VCL fix</label>
|
67 |
<comment>When Enable is selected, a VCL fix will be used to prevent formKey issues. If Disable is selected, an observer will be used.</comment>
|
68 |
<frontend_type>select</frontend_type>
|
69 |
+
<sort_order>26</sort_order>
|
70 |
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
71 |
<show_in_default>1</show_in_default>
|
72 |
<show_in_website>1</show_in_website>
|
73 |
<show_in_store>1</show_in_store>
|
74 |
</vcl_fix>
|
75 |
+
<https_redirect_fix translate="label comment">
|
76 |
+
<label>Fix HTTPS redirect</label>
|
77 |
+
<comment>When using Varnish as front door listen on port 80 and Nginx/Apache listen on port 443 for HTTPS, the fix will keep the url parameters when redirect from HTTP to HTTPS.</comment>
|
78 |
+
<frontend_type>select</frontend_type>
|
79 |
+
<sort_order>28</sort_order>
|
80 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
81 |
+
<show_in_default>1</show_in_default>
|
82 |
+
<show_in_website>1</show_in_website>
|
83 |
+
<show_in_store>1</show_in_store>
|
84 |
+
</https_redirect_fix>
|
85 |
<varnish_debug translate="label" module="turpentine">
|
86 |
<label>Enable Debug Info</label>
|
87 |
<comment>It is a major security vulnerability, to leave this enabled on production sites</comment>
|
92 |
<show_in_website>0</show_in_website>
|
93 |
<show_in_store>0</show_in_store>
|
94 |
</varnish_debug>
|
95 |
+
<varnish_log_commands translate="label" module="turpentine">
|
96 |
+
<label>Enable Varnish Command Logging</label>
|
97 |
+
<comment>Log all commands sent to Varnish by Turpentine in the log specified (custom if enabled). Caution - can cause logs to grow quickly!</comment>
|
98 |
+
<frontend_type>select</frontend_type>
|
99 |
+
<source_model>turpentine/config_select_toggle</source_model>
|
100 |
+
<sort_order>45</sort_order>
|
101 |
+
<show_in_default>1</show_in_default>
|
102 |
+
<show_in_website>0</show_in_website>
|
103 |
+
<show_in_store>0</show_in_store>
|
104 |
+
</varnish_log_commands>
|
105 |
<block_debug translate="label" module="turpentine">
|
106 |
<label>Enable Block Logging</label>
|
107 |
<comment>Log block names for adding ESI, only enable when needed to avoid performance hit</comment>
|
112 |
<show_in_website>0</show_in_website>
|
113 |
<show_in_store>0</show_in_store>
|
114 |
</block_debug>
|
115 |
+
|
116 |
+
|
117 |
<ajax_messages translate="label" module="turpentine">
|
118 |
<label>Enable AJAX Flash Messages</label>
|
119 |
<comment>Enable fixing the messages block to load via AJAX, disable if you already have an extension that does this</comment>
|
255 |
<show_in_website>0</show_in_website>
|
256 |
<show_in_store>0</show_in_store>
|
257 |
</config_file>
|
258 |
+
<custom_include_file_top translate="label" module="turpentine">
|
259 |
+
<label>Custom VCL File - Top</label>
|
260 |
<frontend_type>text</frontend_type>
|
261 |
+
<comment>If this file exists, its content will be prepended to the VCL.</comment>
|
262 |
<sort_order>40</sort_order>
|
263 |
<show_in_default>1</show_in_default>
|
264 |
<show_in_website>0</show_in_website>
|
265 |
<show_in_store>0</show_in_store>
|
266 |
+
</custom_include_file_top>
|
267 |
+
<custom_include_file translate="label" module="turpentine">
|
268 |
+
<label>Custom VCL File - Bottom</label>
|
269 |
+
<frontend_type>text</frontend_type>
|
270 |
+
<comment>If this file exists, its content will be appended to the VCL.</comment>
|
271 |
+
<sort_order>41</sort_order>
|
272 |
+
<show_in_default>1</show_in_default>
|
273 |
+
<show_in_website>0</show_in_website>
|
274 |
+
<show_in_store>0</show_in_store>
|
275 |
</custom_include_file>
|
276 |
+
<custom_vcl_template>
|
277 |
+
<label>Custom VCL Template</label>
|
278 |
+
<frontend_type>text</frontend_type>
|
279 |
+
<comment>If defined and present, this template will be used instead of the default VCL template appropriate for the version of Varnish.</comment>
|
280 |
+
<sort_order>50</sort_order>
|
281 |
+
<show_in_default>1</show_in_default>
|
282 |
+
<show_in_website>0</show_in_website>
|
283 |
+
<show_in_store>0</show_in_store>
|
284 |
+
</custom_vcl_template>
|
285 |
</fields>
|
286 |
</servers>
|
287 |
</groups>
|
app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl
CHANGED
@@ -24,9 +24,9 @@ C{
|
|
24 |
{{custom_c_code}}
|
25 |
}C
|
26 |
|
27 |
-
## Custom VCL Logic
|
28 |
|
29 |
-
{{
|
30 |
|
31 |
## Backends
|
32 |
|
@@ -426,3 +426,7 @@ sub vcl_deliver {
|
|
426 |
}
|
427 |
remove resp.http.X-Opt-Debug-Headers;
|
428 |
}
|
|
|
|
|
|
|
|
24 |
{{custom_c_code}}
|
25 |
}C
|
26 |
|
27 |
+
## Custom VCL Logic - Top
|
28 |
|
29 |
+
{{custom_vcl_include_top}}
|
30 |
|
31 |
## Backends
|
32 |
|
426 |
}
|
427 |
remove resp.http.X-Opt-Debug-Headers;
|
428 |
}
|
429 |
+
|
430 |
+
## Custom VCL Logic - Bottom
|
431 |
+
|
432 |
+
{{custom_vcl_include}}
|
app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl
CHANGED
@@ -28,6 +28,10 @@ C{
|
|
28 |
|
29 |
import std;
|
30 |
|
|
|
|
|
|
|
|
|
31 |
## Backends
|
32 |
|
33 |
{{default_backend}}
|
@@ -92,9 +96,19 @@ sub generate_session_expires {
|
|
92 |
{{generate_session_end}}
|
93 |
## Varnish Subroutines
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
sub vcl_recv {
|
96 |
{{maintenance_allowed_ips}}
|
97 |
|
|
|
|
|
98 |
# this always needs to be done so it's up at the top
|
99 |
if (req.restarts == 0) {
|
100 |
if (req.http.X-Forwarded-For) {
|
@@ -389,7 +403,7 @@ sub vcl_deliver {
|
|
389 |
"; domain=" + regsub(req.http.Host, ":\d+$", "");
|
390 |
} else {
|
391 |
# it's a real user, allow sharing of cookies between stores
|
392 |
-
|
393 |
set resp.http.Set-Cookie = resp.http.Set-Cookie +
|
394 |
"; domain={{normalize_cookie_target}}";
|
395 |
} else {
|
@@ -431,7 +445,7 @@ sub vcl_deliver {
|
|
431 |
}
|
432 |
}
|
433 |
|
434 |
-
## Custom VCL Logic
|
435 |
|
436 |
{{custom_vcl_include}}
|
437 |
|
28 |
|
29 |
import std;
|
30 |
|
31 |
+
## Custom VCL Logic - Top
|
32 |
+
|
33 |
+
{{custom_vcl_include_top}}
|
34 |
+
|
35 |
## Backends
|
36 |
|
37 |
{{default_backend}}
|
96 |
{{generate_session_end}}
|
97 |
## Varnish Subroutines
|
98 |
|
99 |
+
sub vcl_error {
|
100 |
+
if (obj.status == 750) {
|
101 |
+
set obj.http.Location = obj.response;
|
102 |
+
set obj.status = 301;
|
103 |
+
return(deliver);
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
sub vcl_recv {
|
108 |
{{maintenance_allowed_ips}}
|
109 |
|
110 |
+
{{https_redirect}}
|
111 |
+
|
112 |
# this always needs to be done so it's up at the top
|
113 |
if (req.restarts == 0) {
|
114 |
if (req.http.X-Forwarded-For) {
|
403 |
"; domain=" + regsub(req.http.Host, ":\d+$", "");
|
404 |
} else {
|
405 |
# it's a real user, allow sharing of cookies between stores
|
406 |
+
if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") {
|
407 |
set resp.http.Set-Cookie = resp.http.Set-Cookie +
|
408 |
"; domain={{normalize_cookie_target}}";
|
409 |
} else {
|
445 |
}
|
446 |
}
|
447 |
|
448 |
+
## Custom VCL Logic - Bottom
|
449 |
|
450 |
{{custom_vcl_include}}
|
451 |
|
app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl
CHANGED
@@ -28,6 +28,11 @@ C{
|
|
28 |
## Imports
|
29 |
|
30 |
import std;
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
## Backends
|
33 |
|
@@ -97,9 +102,15 @@ sub generate_session_expires {
|
|
97 |
{{generate_session_end}}
|
98 |
## Varnish Subroutines
|
99 |
|
|
|
|
|
|
|
|
|
100 |
sub vcl_recv {
|
101 |
{{maintenance_allowed_ips}}
|
102 |
|
|
|
|
|
103 |
# this always needs to be done so it's up at the top
|
104 |
if (req.restarts == 0) {
|
105 |
if (req.http.X-Forwarded-For) {
|
@@ -137,8 +148,10 @@ sub vcl_recv {
|
|
137 |
set req.http.X-Turpentine-Secret-Handshake = "{{secret_handshake}}";
|
138 |
# use the special admin backend and pipe if it's for the admin section
|
139 |
if (req.url ~ "{{url_base_regex}}{{admin_frontname}}") {
|
140 |
-
set req.backend_hint =
|
141 |
return (pipe);
|
|
|
|
|
142 |
}
|
143 |
if (req.http.Cookie ~ "\bcurrency=") {
|
144 |
set req.http.X-Varnish-Currency = regsub(
|
@@ -234,48 +247,70 @@ sub vcl_pipe {
|
|
234 |
# }
|
235 |
|
236 |
sub vcl_hash {
|
|
|
|
|
237 |
# For static files we keep the hash simple and don't add the domain.
|
238 |
# This saves memory when a static file is used on multiple domains.
|
239 |
if ({{simple_hash_static}} && req.http.X-Varnish-Static) {
|
|
|
240 |
hash_data(req.url);
|
241 |
if (req.http.Accept-Encoding) {
|
242 |
# make sure we give back the right encoding
|
|
|
243 |
hash_data(req.http.Accept-Encoding);
|
244 |
}
|
|
|
245 |
return (lookup);
|
246 |
}
|
247 |
|
|
|
248 |
if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) {
|
249 |
hash_data(req.http.X-Varnish-Cache-Url);
|
|
|
250 |
} else {
|
251 |
hash_data(req.url);
|
|
|
252 |
}
|
253 |
|
254 |
if (req.http.Host) {
|
255 |
hash_data(req.http.Host);
|
|
|
256 |
} else {
|
257 |
hash_data(server.ip);
|
258 |
}
|
|
|
|
|
259 |
hash_data(req.http.Ssl-Offloaded);
|
|
|
260 |
if (req.http.X-Normalized-User-Agent) {
|
261 |
hash_data(req.http.X-Normalized-User-Agent);
|
|
|
262 |
}
|
263 |
if (req.http.Accept-Encoding) {
|
264 |
# make sure we give back the right encoding
|
265 |
hash_data(req.http.Accept-Encoding);
|
|
|
266 |
}
|
267 |
if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) {
|
268 |
# make sure data is for the right store and currency based on the *store*
|
269 |
# and *currency* cookies
|
270 |
hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
|
|
|
271 |
}
|
272 |
|
273 |
if (req.http.X-Varnish-Esi-Access == "private" &&
|
274 |
req.http.Cookie ~ "frontend=") {
|
|
|
275 |
hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1"));
|
276 |
{{advanced_session_validation}}
|
277 |
|
278 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
return (lookup);
|
280 |
}
|
281 |
|
@@ -432,6 +467,6 @@ sub vcl_deliver {
|
|
432 |
}
|
433 |
}
|
434 |
|
435 |
-
## Custom VCL Logic
|
436 |
|
437 |
{{custom_vcl_include}}
|
28 |
## Imports
|
29 |
|
30 |
import std;
|
31 |
+
import directors;
|
32 |
+
|
33 |
+
## Custom VCL Logic - Top
|
34 |
+
|
35 |
+
{{custom_vcl_include_top}}
|
36 |
|
37 |
## Backends
|
38 |
|
102 |
{{generate_session_end}}
|
103 |
## Varnish Subroutines
|
104 |
|
105 |
+
sub vcl_init {
|
106 |
+
{{directors}}
|
107 |
+
}
|
108 |
+
|
109 |
sub vcl_recv {
|
110 |
{{maintenance_allowed_ips}}
|
111 |
|
112 |
+
{{https_redirect}}
|
113 |
+
|
114 |
# this always needs to be done so it's up at the top
|
115 |
if (req.restarts == 0) {
|
116 |
if (req.http.X-Forwarded-For) {
|
148 |
set req.http.X-Turpentine-Secret-Handshake = "{{secret_handshake}}";
|
149 |
# use the special admin backend and pipe if it's for the admin section
|
150 |
if (req.url ~ "{{url_base_regex}}{{admin_frontname}}") {
|
151 |
+
set req.backend_hint = {{admin_backend_hint}};
|
152 |
return (pipe);
|
153 |
+
} else {
|
154 |
+
{{set_backend_hint}}
|
155 |
}
|
156 |
if (req.http.Cookie ~ "\bcurrency=") {
|
157 |
set req.http.X-Varnish-Currency = regsub(
|
247 |
# }
|
248 |
|
249 |
sub vcl_hash {
|
250 |
+
std.log("vcl_hash start");
|
251 |
+
|
252 |
# For static files we keep the hash simple and don't add the domain.
|
253 |
# This saves memory when a static file is used on multiple domains.
|
254 |
if ({{simple_hash_static}} && req.http.X-Varnish-Static) {
|
255 |
+
std.log("hash_data static file - req.url: " + req.url);
|
256 |
hash_data(req.url);
|
257 |
if (req.http.Accept-Encoding) {
|
258 |
# make sure we give back the right encoding
|
259 |
+
std.log("hash_data static file - Accept-Encoding: " + req.http.Accept-Encoding);
|
260 |
hash_data(req.http.Accept-Encoding);
|
261 |
}
|
262 |
+
std.log("vcl_hash end return lookup");
|
263 |
return (lookup);
|
264 |
}
|
265 |
|
266 |
+
|
267 |
if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) {
|
268 |
hash_data(req.http.X-Varnish-Cache-Url);
|
269 |
+
std.log("hash_data - X-Varnish-Cache-Url: " + req.http.X-Varnish-Cache-Url);
|
270 |
} else {
|
271 |
hash_data(req.url);
|
272 |
+
std.log("hash_data - req.url: " + req.url );
|
273 |
}
|
274 |
|
275 |
if (req.http.Host) {
|
276 |
hash_data(req.http.Host);
|
277 |
+
std.log("hash_data - req.http.Host: " + req.http.Host);
|
278 |
} else {
|
279 |
hash_data(server.ip);
|
280 |
}
|
281 |
+
|
282 |
+
std.log("hash_data - req.http.Ssl-Offloaded: " + req.http.Ssl-Offloaded);
|
283 |
hash_data(req.http.Ssl-Offloaded);
|
284 |
+
|
285 |
if (req.http.X-Normalized-User-Agent) {
|
286 |
hash_data(req.http.X-Normalized-User-Agent);
|
287 |
+
std.log("hash_data - req.http.X-Normalized-User-Agent: " + req.http.X-Normalized-User-Agent);
|
288 |
}
|
289 |
if (req.http.Accept-Encoding) {
|
290 |
# make sure we give back the right encoding
|
291 |
hash_data(req.http.Accept-Encoding);
|
292 |
+
std.log("hash_data - req.http.Accept-Encoding: " + req.http.Accept-Encoding);
|
293 |
}
|
294 |
if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) {
|
295 |
# make sure data is for the right store and currency based on the *store*
|
296 |
# and *currency* cookies
|
297 |
hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
|
298 |
+
std.log("hash_data - Store and Currency: " + "s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
|
299 |
}
|
300 |
|
301 |
if (req.http.X-Varnish-Esi-Access == "private" &&
|
302 |
req.http.Cookie ~ "frontend=") {
|
303 |
+
std.log("hash_data - frontned cookie: " + regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1"));
|
304 |
hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1"));
|
305 |
{{advanced_session_validation}}
|
306 |
|
307 |
}
|
308 |
+
|
309 |
+
if (req.http.X-Varnish-Esi-Access == "customer_group" &&
|
310 |
+
req.http.Cookie ~ "customer_group=") {
|
311 |
+
hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1"));
|
312 |
+
}
|
313 |
+
std.log("vcl_hash end return lookup");
|
314 |
return (lookup);
|
315 |
}
|
316 |
|
467 |
}
|
468 |
}
|
469 |
|
470 |
+
## Custom VCL Logic - Bottom
|
471 |
|
472 |
{{custom_vcl_include}}
|
app/design/frontend/base/default/layout/turpentine_esi.xml
CHANGED
@@ -44,7 +44,8 @@
|
|
44 |
<wishlist_item_save_after/>
|
45 |
<wishlist_item_delete_after/>
|
46 |
<sales_quote_save_after/>
|
47 |
-
|
|
|
48 |
</flush_events>
|
49 |
</params>
|
50 |
</action>
|
@@ -269,6 +270,10 @@
|
|
269 |
<turpentine_cache_flag value="0"/>
|
270 |
</checkout_onepage_progress_payment>
|
271 |
|
|
|
|
|
|
|
|
|
272 |
<checkout_onepage_paymentmethod>
|
273 |
<turpentine_cache_flag value="0"/>
|
274 |
</checkout_onepage_paymentmethod>
|
44 |
<wishlist_item_save_after/>
|
45 |
<wishlist_item_delete_after/>
|
46 |
<sales_quote_save_after/>
|
47 |
+
<controller_action_layout_render_before_catalogsearch_result_index />
|
48 |
+
<persistent_session_expired/>
|
49 |
</flush_events>
|
50 |
</params>
|
51 |
</action>
|
270 |
<turpentine_cache_flag value="0"/>
|
271 |
</checkout_onepage_progress_payment>
|
272 |
|
273 |
+
<checkout_onepage_progress_review>
|
274 |
+
<turpentine_cache_flag value="0"/>
|
275 |
+
</checkout_onepage_progress_review>
|
276 |
+
|
277 |
<checkout_onepage_paymentmethod>
|
278 |
<turpentine_cache_flag value="0"/>
|
279 |
</checkout_onepage_paymentmethod>
|
app/design/frontend/base/default/template/turpentine/ajax.phtml
CHANGED
@@ -50,7 +50,9 @@ echo <<<HTML
|
|
50 |
<script type="text/javascript">
|
51 |
(function() {
|
52 |
var blockTag = {$this->helper('core')->jsonEncode($blockTag)}, esiUrl = {$this->helper('core')->jsonEncode($this->getEsiUrl())};
|
53 |
-
if (typeof Ajax === 'object' && typeof Ajax.Updater === 'function'
|
|
|
|
|
54 |
Event.observe( window, "load", function() { setTimeout( function() {
|
55 |
new Ajax.Updater(
|
56 |
blockTag,
|
50 |
<script type="text/javascript">
|
51 |
(function() {
|
52 |
var blockTag = {$this->helper('core')->jsonEncode($blockTag)}, esiUrl = {$this->helper('core')->jsonEncode($this->getEsiUrl())};
|
53 |
+
if (typeof Ajax === 'object' && typeof Ajax.Updater === 'function'
|
54 |
+
&& (typeof Event === 'function' || (typeof Event === 'object' && typeof Event.observe === 'function'))
|
55 |
+
) {
|
56 |
Event.observe( window, "load", function() { setTimeout( function() {
|
57 |
new Ajax.Updater(
|
58 |
blockTag,
|
package.xml
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?xml version='1.0' encoding='utf-8'?>
|
2 |
-
<package><name>Nexcessnet_Turpentine</name><license uri="http://opensource.org/licenses/GPL-2.0">GPLv2</license><notes>Supports Magento v1.6 and later</notes><time>10:
|
1 |
<?xml version='1.0' encoding='utf-8'?>
|
2 |
+
<package><name>Nexcessnet_Turpentine</name><license uri="http://opensource.org/licenses/GPL-2.0">GPLv2</license><notes>Supports Magento v1.6 and later</notes><time>10:18:44</time><__packager>build_package.py v0.0.3</__packager><summary>Improves Magento support for Varnish caching and generates 2.1 and 3.0 compatible VCLs.</summary><stability>stable</stability><__commit_hash>4929b8a5cbd4e62f254a42dae881eda28b0a7dec</__commit_hash><version>0.7.1</version><extends /><contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file hash="a0bd4a5632b369b058c0ec5262e0cc49" name="turpentine.xml" /></dir><dir name="template"><dir name="turpentine"><file hash="b564606032d111537d02c8da63470c39" name="varnish_management.phtml" /></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file hash="c77b5ace7bf2300de8cab000c5ccb127" name="turpentine_esi.xml" /></dir><dir name="template"><dir name="turpentine"><file hash="4369ad60461aaf69a17a3357c8fe16c6" name="ajax.phtml" /><file hash="b268c48251ccfccf5c775d3e85513584" name="esi.phtml" /><file hash="50798888953fd1550e4347c39e395d0a" name="notices.phtml" /></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file hash="58848d4d90973bfd63b466ea181352a5" name="Nexcessnet_Turpentine.xml" /></dir></target><target name="magecommunity"><dir name="Nexcessnet"><dir name="Turpentine"><dir name="Block"><file hash="65b7bc93cb512a208e0f48615996a7e2" name="Management.php" /><file hash="390cf75d04b1b098cad562229b649c2d" name="Notices.php" /><dir name="Catalog"><dir name="Product"><dir name="List"><file hash="ce9fca4c273987759f284fe31c1597f5" name="Toolbar.php" /></dir></dir></dir><dir name="Adminhtml"><dir name="Cache"><file hash="8265061356f8096fc82c88334b4effc9" name="Grid.php" /></dir></dir><dir name="Core"><file hash="2b4c814c8aa426fa586459716d7c2659" name="Messages.php" /></dir><dir name="Poll"><file hash="77a2469841c71b1c45d90947e2855ba7" name="ActivePoll.php" /></dir><dir name="Product"><file hash="c86f7e0571583011932b8bad37aa5acd" name="Viewed.php" /><file hash="e907d4de82aba5be25272127674a10e3" name="Compared.php" /></dir></dir><dir name="etc"><file hash="51c355170c834bd198d8435fb44e4900" name="config.xml" /><file hash="80c694720f82ed6c756621b9d5bdce7d" name="system.xml" /><file hash="3b608fbcca3d307833d10604dff23966" name="cache.xml" /></dir><dir name="controllers"><file hash="441c60671b8cdd249dadc05fcdf0373b" name="EsiController.php" /><dir name="Adminhtml"><file hash="9ed581279364b21ead6ad07ff951d90e" name="CacheController.php" /></dir><dir name="Varnish"><file hash="36ed74dba513b500b7a25175d43a4d71" name="ManagementController.php" /></dir></dir><dir name="Helper"><file hash="99ec12c46fd42fbfabdb191c4af7fbe6" name="Varnish.php" /><file hash="66399790e7dda35e709b346889a21b1b" name="Debug.php" /><file hash="a1a0b6aa02aff34f995d3df15c993978" name="Cron.php" /><file hash="c6068752ae71f7fbf58208263d94880d" name="Ban.php" /><file hash="193775458c5fa27cde724aae8b54f489" name="Data.php" /><file hash="7f156b5d3f3aafd56f8ec67f4d70d436" name="Esi.php" /></dir><dir name="misc"><file hash="57b57d1363b8024390c6f0a92e237e91" name="version-3.vcl" /><file hash="ba5d5c7263cd90eea3785953e3549041" name="uuid.c" /><file hash="e032877a7ca037dd8fae4bbb4b49999c" name="version-4.vcl" /><file hash="8bdb8b25b777e19745ec42b251083a8d" name="version-2.vcl" /></dir><dir name="Model"><file hash="ffd2af1c58782a2086422b2077f00282" name="Session.php" /><dir name="Config"><dir name="Select"><file hash="403dcea1f19b377f30af5f89297d9a69" name="Version.php" /><file hash="9348c5e58037fd97d89b84ccab4ef2d0" name="Toggle.php" /><file hash="2a4648995fc87472b2ac33b35a7d69e5" name="LoadBalancing.php" /><file hash="f411ae6da3c2154e78e0f7e845212166" name="StripWhitespace.php" /></dir></dir><dir name="Observer"><file hash="16e4975274e8c3454bf2226d5a0558e6" name="Varnish.php" /><file hash="4f67e6d7c35891451391b13a0eec9847" name="Debug.php" /><file hash="acdb0304a8b89ae5f072d523be63d9c0" name="Cron.php" /><file hash="bdf76e0eb3b31341ae0d80beba83d85b" name="Ban.php" /><file hash="cfa236bb8cceb0accc0f8c3bc74efbf3" name="Esi.php" /></dir><dir name="Core"><file hash="8f512da6e6da419acc07710b079e3ca9" name="Session.php" /></dir><dir name="Shim"><dir name="Mage"><dir name="Core"><file hash="ee6924c626916a8edd49b6037809204a" name="Layout.php" /><file hash="85e9e378b8fd0ab504c751a69d0b28a6" name="App.php" /><file hash="5912fa8ef25346f2a21316d8ea5de867" name="Config.php" /></dir></dir></dir><dir name="PageCache"><dir name="Container"><file hash="6e3b54ae5968af644952b00cd96a3f32" name="Notices.php" /></dir></dir><dir name="Varnish"><file hash="b264dc1982cef539b8dc2c86aa34c5c3" name="Admin.php" /><dir name="Configurator"><file hash="a0f098ef4e538fb9ee671e2e49378796" name="Abstract.php" /><file hash="8ee23e5993ecd7a0d880221fbda74ecf" name="Version4.php" /><file hash="fa8b92a14b7b608dfe0af030b6a78a77" name="Version3.php" /><file hash="d4d66168e43a62ceab30226b44b9e98b" name="Version2.php" /></dir><dir name="Admin"><file hash="add6be96edabcb62a9003dad8d18d808" name="Socket.php" /></dir></dir><dir name="Dummy"><file hash="07e4db6d82110e523d1400dcfec60830" name="Request.php" /></dir></dir></dir></dir></target></contents><dependencies><required><php><min>5.2.13</min><max>7.1.0</max></php></required></dependencies><authors><author><name>Chris Wells</name><user>nexcess_net</user><email>clwells@nexcess.net</email></author><author><name>Alex Headley</name><user>aheadley_nex</user><email>aheadley@nexcess.net</email></author></authors><date>2017-01-03</date><compatibile /><channel>community</channel><description>Turpentine is a Magento extension to improve Magento's compatibility with Varnish, a very-fast caching reverse-proxy. By default, Varnish doesn't cache requests with cookies and Magento sends the frontend cookie with every request causing a (near) zero hit-rate for Varnish's cache. Turpentine provides Varnish configuration files (VCLs) to work with Magento and modifies Magento's behaviour to significantly improve the cache hit rate.</description></package>
|