Skip to content

Commit 35d44f5

Browse files
Merge pull request #978 from nexcess/devel
Devel
2 parents f89ae64 + c5e7ba2 commit 35d44f5

File tree

10 files changed

+238
-20
lines changed

10 files changed

+238
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,10 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess
413413

414414
### RELEASE-0.6.5
415415
* Varnish 4 (@aheadley @aricwatson)
416+
417+
### RELEASE-0.6.6
418+
* [#923] DetermineVersion 3.0 to 3.0.3 bugfix (@timmuller)
419+
* [#945] Send unmodified url to the backend server (@thampe)
420+
* [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page (@craigcarnell)
421+
* [#955] Include theme specific handles to ESI data (@LyndonHook)
422+
* [#972] Fixed bug with wrong return value of ->getSkinUrl() (@ceckoslab)

app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ public function injectEsi( $eventObject ) {
230230
if( $esiHelper->shouldResponseUseEsi() &&
231231
$blockObject instanceof Mage_Core_Block_Template &&
232232
$esiOptions = $blockObject->getEsiOptions() ) {
233+
234+
if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) {
235+
return;
236+
}
237+
233238
if( Mage::app()->getStore()->getCode() == 'admin' ) {
234239
// admin blocks are not allowed to be cached for now
235240
$debugHelper->logWarn(
@@ -320,8 +325,6 @@ protected function _getEsiData( $blockObject, $esiOptions ) {
320325
$methodParam = $esiHelper->getEsiMethodParam();
321326
$esiData = new Varien_Object();
322327
$esiData->setStoreId( Mage::app()->getStore()->getId() );
323-
$esiData->setDesignPackage( Mage::getDesign()->getPackageName() );
324-
$esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) );
325328
$esiData->setNameInLayout( $blockObject->getNameInLayout() );
326329
$esiData->setBlockType( get_class( $blockObject ) );
327330
$esiData->setLayoutHandles( $this->_getBlockLayoutHandles( $blockObject ) );
@@ -413,9 +416,9 @@ protected function _getBlockLayoutHandles( $block ) {
413416
// check if this handle has any block or reference tags that
414417
// refer to this block or a child block, unless the handle name
415418
// is blank
416-
if( $handle !== '' &&
419+
if( $handle !== '' && ( strpos($handle, 'THEME') === 0 ||
417420
$layoutXml->xpath( sprintf(
418-
'//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) {
421+
'//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) ) {
419422
$activeHandles[] = $handle;
420423
}
421424
}

app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,13 @@ protected function _determineVersion($bannerText) {
359359
Mage::throwException('Varnish versions before 2.1 are not supported');
360360
}
361361
if ( count($bannerText)<7 ) {
362-
// Varnish before 3.0 does not spit out a version number
362+
// Varnish before 3.0.4 does not spit out a version number
363+
$resp = $this->_write( 'help' )->_read();
364+
if( strpos( $resp['text'], 'ban.url' ) !== false ) {
365+
// Varnish versions 3.0 through 3.0.3 do not return a version banner.
366+
// To differentiate between 2.1 and 3.0, we check the existence of the ban.url command.
367+
return '3.0';
368+
}
363369
return '2.1';
364370
} elseif ( preg_match(self::REGEXP_VARNISH_VERSION, $bannerText[4], $matches)===1 ) {
365371
return $matches['vmajor'] . '.' . $matches['vminor'];

app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ protected function _getIgnoreGetParameters()
379379
return implode( '|', $ignoredParameters);
380380
}
381381

382+
/**
383+
* @return boolean
384+
*/
385+
protected function _sendUnModifiedUrlToBackend()
386+
{
387+
return Mage::getStoreConfigFlag('turpentine_vcl/params/transfer_unmodified_url');
388+
}
389+
382390
/**
383391
* Get the Generate Session
384392
*
@@ -406,8 +414,8 @@ protected function _getGenerateSessionEnd() {
406414
* @return string
407415
*/
408416
protected function _getGenerateSession() {
409-
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
410-
? '# call generate_session' : 'call generate_session;';
417+
return Mage::getStoreConfigFlag( 'turpentine_varnish/general/vcl_fix' )
418+
? 'return (pipe);' : 'call generate_session;';
411419
}
412420

413421

@@ -825,6 +833,92 @@ protected function _getNormalizeCookieRegex() {
825833
'turpentine_vcl/normalization/cookie_regex' ) );
826834
}
827835

836+
/**
837+
* Get the allowed IPs when in maintenance mode
838+
*
839+
* @return string
840+
*/
841+
protected function _vcl_sub_maintenance_allowed_ips() {
842+
if((! $this->_getDebugIps()) || ! Mage::getStoreConfig( 'turpentine_vcl/maintenance/custom_vcl_synth' ) ) {
843+
return false;
844+
}
845+
846+
switch(Mage::getStoreConfig( 'turpentine_varnish/servers/version' )) {
847+
case 4.0:
848+
$tpl = <<<EOS
849+
if (req.http.X-Forwarded-For) {
850+
if (req.http.X-Forwarded-For !~ "{{debug_ips}}") {
851+
return (synth(999, "Maintenance mode"));
852+
}
853+
}
854+
else {
855+
if (client.ip !~ debug_acl) {
856+
return (synth(999, "Maintenance mode"));
857+
}
858+
}
859+
860+
EOS;
861+
break;
862+
default:
863+
$tpl = <<<EOS
864+
if (req.http.X-Forwarded-For) {
865+
if(req.http.X-Forwarded-For !~ "{{debug_ips}}") {
866+
error 503;
867+
}
868+
} else {
869+
if (client.ip !~ debug_acl) {
870+
error 503;
871+
}
872+
}
873+
EOS;
874+
}
875+
876+
return $this->_formatTemplate( $tpl, array(
877+
'debug_ips' => Mage::getStoreConfig( 'dev/restrict/allow_ips' ) ) );
878+
}
879+
880+
/**
881+
* Get the allowed IPs when in maintenance mode
882+
*
883+
* @return string
884+
*/
885+
protected function _vcl_sub_synth()
886+
{
887+
if ((!$this->_getDebugIps()) || !Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')) {
888+
return false;
889+
}
890+
891+
switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
892+
case 4.0:
893+
$tpl = <<<EOS
894+
sub vcl_synth {
895+
if (resp.status == 999) {
896+
set resp.status = 404;
897+
set resp.http.Content-Type = "text/html; charset=utf-8";
898+
synthetic({"{{vcl_synth_content}}"});
899+
return (deliver);
900+
}
901+
return (deliver);
902+
}
903+
904+
EOS;
905+
break;
906+
default:
907+
$tpl = <<<EOS
908+
sub vcl_error {
909+
set obj.http.Content-Type = "text/html; charset=utf-8";
910+
synthetic {"{{vcl_synth_content}}"};
911+
return (deliver);
912+
}
913+
EOS;
914+
}
915+
916+
return $this->_formatTemplate($tpl, array(
917+
'vcl_synth_content' => Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')));
918+
}
919+
920+
921+
828922
/**
829923
* Build the list of template variables to apply to the VCL template
830924
*
@@ -844,6 +938,7 @@ protected function _getTemplateVars() {
844938
'default_ttl' => $this->_getDefaultTtl(),
845939
'enable_get_excludes' => ($this->_getGetParamExcludes() ? 'true' : 'false'),
846940
'enable_get_ignored' => ($this->_getIgnoreGetParameters() ? 'true' : 'false'),
941+
'send_unmodified_url' => ($this->_sendUnModifiedUrlToBackend() ? 'true' : 'false'),
847942
'debug_headers' => $this->_getEnableDebugHeaders(),
848943
'grace_period' => $this->_getGracePeriod(),
849944
'force_cache_static' => $this->_getForceCacheStatic(),
@@ -894,6 +989,13 @@ protected function _getTemplateVars() {
894989
$vars['normalize_cookie_target'] = $this->_getNormalizeCookieTarget();
895990
}
896991

992+
if( Mage::getStoreConfig( 'turpentine_vcl/maintenance/enable' ) ) {
993+
// in vcl_recv set the allowed IPs otherwise load the vcl_error (v3)/vcl_synth (v4)
994+
$vars['maintenance_allowed_ips'] = $this->_vcl_sub_maintenance_allowed_ips();
995+
// set the vcl_error from Magento database
996+
$vars['vcl_synth'] = $this->_vcl_sub_synth();
997+
}
998+
897999
$customIncludeFile = $this->_getCustomIncludeFilename();
8981000
if( is_readable( $customIncludeFile ) ) {
8991001
$vars['custom_vcl_include'] = file_get_contents( $customIncludeFile );

app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ protected function _getEsiBlock( $esiData ) {
183183
}
184184
}
185185
$layout = Mage::getSingleton( 'core/layout' );
186-
Mage::getSingleton( 'core/design_package' )
187-
->setPackageName( $esiData->getDesignPackage() )
188-
->setTheme( $esiData->getDesignTheme() );
189186

190187
// dispatch event for adding handles to layout update
191188
Mage::dispatchEvent(

app/code/community/Nexcessnet/Turpentine/etc/config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<config>
2121
<modules>
2222
<Nexcessnet_Turpentine>
23-
<version>0.6.6</version>
23+
<version>0.6.7</version>
2424
</Nexcessnet_Turpentine>
2525
</modules>
2626
<default>
@@ -80,6 +80,7 @@
8080
<params>
8181
<get_params>__SID,XDEBUG_PROFILE</get_params>
8282
<ignore_get_params>utm_source,utm_medium,utm_campaign,utm_content,utm_term,gclid,cx,ie,cof,siteurl</ignore_get_params>
83+
<transfer_unmodified_url>0</transfer_unmodified_url>
8384
</params>
8485
<static>
8586
<force_static>1</force_static>

app/code/community/Nexcessnet/Turpentine/etc/system.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,20 @@
541541
<show_in_website>0</show_in_website>
542542
<show_in_store>0</show_in_store>
543543
</ignore_get_params>
544+
<transfer_unmodified_url translate="label" module="turpentine">
545+
<label>Transfer unmodified URL to Backend Server</label>
546+
<comment>
547+
By default the backend server (webserver / magento) gets a modified URL (without ignored get parameters).
548+
As a result the ignored parameters can not be used by the backend server for uncachable requests, for example a redirect.
549+
By activating this option the backend server gets the the unmodified url, but the cache still uses the modified url for lookups.
550+
</comment>
551+
<frontend_type>select</frontend_type>
552+
<source_model>adminhtml/system_config_source_yesno</source_model>
553+
<sort_order>21</sort_order>
554+
<show_in_default>1</show_in_default>
555+
<show_in_website>0</show_in_website>
556+
<show_in_store>0</show_in_store>
557+
</transfer_unmodified_url>
544558
</fields>
545559
</params>
546560
<static translate="label" module="turpentine">
@@ -575,6 +589,35 @@
575589
</exts>
576590
</fields>
577591
</static>
592+
<maintenance translate="label" module="turpentine">
593+
<label>Maintenance mode</label>
594+
<frontend_type>text</frontend_type>
595+
<sort_order>46</sort_order>
596+
<show_in_default>1</show_in_default>
597+
<show_in_website>0</show_in_website>
598+
<show_in_store>0</show_in_store>
599+
<fields>
600+
<enable translate="label" module="turpentine">
601+
<label>Enable Maintenance Mode</label>
602+
<frontend_type>select</frontend_type>
603+
<source_model>turpentine/config_select_toggle</source_model>
604+
<comment>If enabled IP's not in 'developer client restrictions' will receive the following error page</comment>
605+
<sort_order>10</sort_order>
606+
<show_in_default>1</show_in_default>
607+
<show_in_website>0</show_in_website>
608+
<show_in_store>0</show_in_store>
609+
</enable>
610+
<custom_vcl_synth translate="label" module="turpentine">
611+
<label>Custom HTML content of vcl synth (error) sub</label>
612+
<frontend_type>textarea</frontend_type>
613+
<comment>Enter full HTML page content</comment>
614+
<sort_order>20</sort_order>
615+
<show_in_default>1</show_in_default>
616+
<show_in_website>0</show_in_website>
617+
<show_in_store>0</show_in_store>
618+
</custom_vcl_synth>
619+
</fields>
620+
</maintenance>
578621
</groups>
579622
</turpentine_vcl>
580623
</sections>

app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ sub vcl_recv {
104104
set req.http.X-Opt-Enable-Caching = "{{enable_caching}}";
105105
set req.http.X-Opt-Force-Static-Caching = "{{force_cache_static}}";
106106
set req.http.X-Opt-Enable-Get-Excludes = "{{enable_get_excludes}}";
107+
set req.http.X-Opt-Send-Unmodified-Url = "{{send_unmodified_url}}";
108+
109+
110+
if(req.http.X-Opt-Send-Unmodified-Url == "true") {
111+
# save unmodified url
112+
set req.http.X-Varnish-Origin-Url = req.url;
113+
}
107114

108115
# Normalize request data before potentially sending things off to the
109116
# backend. This ensures all request types get the same information, most
@@ -200,7 +207,14 @@ sub vcl_recv {
200207
set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1");
201208
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1");
202209
}
203-
210+
211+
212+
if(req.http.X-Opt-Send-Unmodified-Url == "true") {
213+
# change req.url back and save the modified for cache look-ups in a separate variable
214+
set req.http.X-Varnish-Cache-Url = req.url;
215+
set req.url = req.http.X-Varnish-Origin-Url;
216+
unset req.http.X-Varnish-Origin-Url;
217+
}
204218

205219
return (lookup);
206220
}
@@ -220,6 +234,13 @@ sub vcl_pipe {
220234
# }
221235

222236
sub vcl_hash {
237+
238+
if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) {
239+
set req.hash += req.http.X-Varnish-Cache-Url;
240+
} else {
241+
set req.hash += req.url;
242+
}
243+
223244
set req.hash += req.url;
224245
if (req.http.Host) {
225246
set req.hash += req.http.Host;

app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ sub generate_session_expires {
9797
## Varnish Subroutines
9898

9999
sub vcl_recv {
100+
{{maintenance_allowed_ips}}
101+
100102
# this always needs to be done so it's up at the top
101103
if (req.restarts == 0) {
102104
if (req.http.X-Forwarded-For) {
@@ -107,6 +109,11 @@ sub vcl_recv {
107109
}
108110
}
109111

112+
if({{send_unmodified_url}}) {
113+
# save the unmodified url
114+
set req.http.X-Varnish-Origin-Url = req.url;
115+
}
116+
110117
# Normalize request data before potentially sending things off to the
111118
# backend. This ensures all request types get the same information, most
112119
# notably POST requests getting a normalized user agent string to empower
@@ -170,8 +177,7 @@ sub vcl_recv {
170177
set req.http.Cookie = "frontend=crawler-session";
171178
} else {
172179
# it's a real user, make up a new session for them
173-
{{generate_session}}# call generate_session;
174-
return (pipe);
180+
{{generate_session}}
175181
}
176182
}
177183
if ({{force_cache_static}} &&
@@ -202,6 +208,11 @@ sub vcl_recv {
202208
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1");
203209
}
204210

211+
if({{send_unmodified_url}}) {
212+
set req.http.X-Varnish-Cache-Url = req.url;
213+
set req.url = req.http.X-Varnish-Origin-Url;
214+
unset req.http.X-Varnish-Origin-Url;
215+
}
205216

206217
# everything else checks out, try and pull from the cache
207218
return (lookup);
@@ -222,7 +233,12 @@ sub vcl_pipe {
222233
# }
223234

224235
sub vcl_hash {
225-
hash_data(req.url);
236+
237+
if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) {
238+
hash_data(req.http.X-Varnish-Cache-Url);
239+
} else {
240+
hash_data(req.url);
241+
}
226242
if (req.http.Host) {
227243
hash_data(req.http.Host);
228244
} else {
@@ -350,6 +366,8 @@ sub vcl_fetch {
350366
# else it's not part of Magento so use the default Varnish handling
351367
}
352368

369+
{{vcl_synth}}
370+
353371
sub vcl_deliver {
354372
if (req.http.X-Varnish-Faked-Session) {
355373
# need to set the set-cookie header since we just made it out of thin air

0 commit comments

Comments
 (0)