Skip to content

Commit

Permalink
Merge pull request #1309 from nexcess/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
miguelbalparda authored Nov 15, 2016
2 parents 5317850 + 0d78429 commit e357731
Show file tree
Hide file tree
Showing 19 changed files with 465 additions and 86 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build/*.tgz
build/*.html
app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl
app/code/community/Nexcessnet/Turpentine/misc/custom_include*.vcl
*~
.idea
.DS_Store
nbproject/
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,5 +439,34 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess
* [#1117] Fix #1100. (@GLips)
* [#1155] Update TECHNICAL_NOTES.md. (@GLips)

### RELEASE-0.6.9
### RELEASE-0.6.9 -> 0.7.0
* [#1162] Support PHP7. (@allardhoeve)
* [#1173] Fix load balancing for Varnish 4. (@kleinmann)
* [#1182] Update version-3.vcl normalisation. (@gewaechshaus)

### RELEASE-0.7.1

* [#1189] Custom Admin Path with Add Store Code to URLs (@miguelbalparda)
* [#1195] Fix for issue #1093 - poll still displaying when module output disabled (@aricwatson)
* [#1212] Allows Custom VCL template (@aricwatson)
* [#1214] Generate global blocks like formkey for ESI-Blocks (@possi)
* [#1216] Adds and implements an option to log all commands sent to Varnish (@aricwatson)
* [#1225] Enhanced block logging (@aricwatson)
* [#1226] Condensed the UA "buckets" down to just "mobile" and "other" (@aricwatson)
* [#1232] Adds better logging of hash_data calls in vcl_hash (@aricwatson)
* [#1243] Adds more flexibility/options to warm-cache.sh (@aricwatson)
* [#1254] Add customer_group caching to varnish 4 template feature (@jg-development)
* [#1258] Fix issue with customer name not being removed from header when clearing persistent cookie (@careysizer)
* [#1261] Fixed Crawler UserAgent regexp to match newer Siege versions. (@jeroenvermeulen)
* [#1262] Bugfix in "Normalize Encoding" for visitors who accept "*" (@jeroenvermeulen)
* [#1264] #963 Fix the Nginx 403 issue with urls which are starting with a dot (@andreasemer)
* [#1266] #878 Add onepage checkout progress review for varnish exclude in config (@jg-development)
* [#1271] #1270 Fix: Improve condition to support safari browser Event feature (@AlexanderPok)
* [#1282] Added one more format for configuration regexp bug (@odi-um)
* [#1289] Fix the issue when redirect HTTP to HTTPS feature (@hmphu)
* [#1298] Removed unused code (@nickua)





Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Nexcessnet_Turpentine_Block_Management

public function __construct() {
$this->_controller = 'varnish_management';
// $this->setTemplate( 'turpentine/varnish_management.phtml' );

parent::__construct();
}

Expand Down
22 changes: 15 additions & 7 deletions app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@

class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll {

public function setTemplate($template)
{
$this->_template = $template;
$this->setPollTemplate('turpentine/ajax.phtml', 'poll');
$this->setPollTemplate('turpentine/ajax.phtml', 'results');
return $this;
}
public function setTemplate($template)
{
if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) &&
(!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll')))
{
$this->_template = $template;
$this->setPollTemplate('turpentine/ajax.phtml', 'poll');
$this->setPollTemplate('turpentine/ajax.phtml', 'results');
}
else
{
// Mage_Poll is disabled, so do nothing
}
return $this;
}
}
4 changes: 2 additions & 2 deletions app/code/community/Nexcessnet/Turpentine/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getVersion() {
public function urlBase64Encode($str) {
return str_replace(
array('/', '+'),
array('.', '-'),
array('_', '-'),
base64_encode($str) );
}

Expand All @@ -143,7 +143,7 @@ public function urlBase64Encode($str) {
public function urlBase64Decode($str) {
return base64_decode(
str_replace(
array('.', '-'),
array('_', '-'),
array('/', '+'),
$str ) );
}
Expand Down
11 changes: 10 additions & 1 deletion app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,19 @@ public function injectEsi($eventObject) {
$debugHelper->logInfo(
'Checking ESI block candidate: %s',
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
}

$debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi());
$debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template );
$debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) );
}
if ($esiHelper->shouldResponseUseEsi() &&
$blockObject instanceof Mage_Core_Block_Template &&
$esiOptions = $blockObject->getEsiOptions()) {

if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) {
if ($esiHelper->getEsiBlockLogEnabled()) {
$debugHelper->logInfo("-- ESI Injection disabled");
}
return;
}

Expand Down Expand Up @@ -325,6 +332,8 @@ protected function _getEsiData($blockObject, $esiOptions) {
$methodParam = $esiHelper->getEsiMethodParam();
$esiData = new Varien_Object();
$esiData->setStoreId(Mage::app()->getStore()->getId());
$esiData->setDesignPackage( Mage::getDesign()->getPackageName() );
$esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) );
$esiData->setNameInLayout($blockObject->getNameInLayout());
$esiData->setBlockType(get_class($blockObject));
$esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ protected function _write($data) {
$regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~';
if ($this->getVersion() === '4.0') {
// Varnish4 supports "16k" style notation
$regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g]{1})?\s+\[bytes\]~';
$regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g|b]{1})?\s+\[bytes\]~';
}
if (preg_match($regexp, $cliBufferResponse['text'], $match)) {
$realLimit = (int) $match[1];
if (isset($match[2])) {
$factors = array('k'=>1, 'm'=>2, 'g'=>3);
$factors = array('b'=>0, 'k'=>1, 'm'=>2, 'g'=>3);
$realLimit *= pow(1024, $factors[$match[2]]);
}
} else {
Expand Down Expand Up @@ -499,6 +499,9 @@ protected function _command($verb, $okCode = 200) {
"Got unexpected response code from Varnish: %d\n%s",
$response['code'], $response['text'] ));
} else {
if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) {
Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data);
}
return $response;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public function save($generatedConfig) {
* @return string
*/
protected function _getVclTemplateFilename($baseFilename) {
$extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine');
return sprintf('%s/misc/%s', $extensionDir, $baseFilename);
$extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine');
return sprintf('%s/misc/%s', $extensionDir, $baseFilename);
}

/**
Expand All @@ -130,12 +130,31 @@ protected function _getVclFilename() {
*
* @return string
*/
protected function _getCustomIncludeFilename() {
protected function _getCustomIncludeFilename($position='') {
$key = 'custom_include_file';
$key .= ($position) ? '_'.$position : '';
return $this->_formatTemplate(
Mage::getStoreConfig('turpentine_varnish/servers/custom_include_file'),
Mage::getStoreConfig('turpentine_varnish/servers/'.$key),
array('root_dir' => Mage::getBaseDir()) );
}


/**
* Get the custom VCL template, if it exists
* Returns 'null' if the file doesn't exist
*
* @return string
*/
protected function _getCustomTemplateFilename() {
$filePath = $this->_formatTemplate(
Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'),
array('root_dir' => Mage::getBaseDir())
);
if (is_file($filePath)) { return $filePath; }
else { return null; }
}


/**
* Format a template string, replacing {{keys}} with the appropriate values
* and remove unspecified keys
Expand Down Expand Up @@ -173,7 +192,11 @@ protected function _vcl_call($subroutine) {
*/
protected function _getAdminFrontname() {
if (Mage::getStoreConfig('admin/url/use_custom_path')) {
return Mage::getStoreConfig('admin/url/custom_path');
if(Mage::getStoreConfig('web/url/use_store')) {
return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path');
} else {
return Mage::getStoreConfig('admin/url/custom_path');
}
} else {
return (string) Mage::getConfig()->getNode(
'admin/routers/adminhtml/args/frontName' );
Expand Down Expand Up @@ -769,16 +792,6 @@ protected function _vcl_sub_normalize_user_agent() {
$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 = "mobile";
} else if (req.http.User-Agent ~ "MSIE") {
set req.http.X-Normalized-User-Agent = "msie";
} else if (req.http.User-Agent ~ "Firefox") {
set req.http.X-Normalized-User-Agent = "firefox";
} else if (req.http.User-Agent ~ "Chrome") {
set req.http.X-Normalized-User-Agent = "chrome";
} else if (req.http.User-Agent ~ "Safari") {
set req.http.X-Normalized-User-Agent = "safari";
} else if (req.http.User-Agent ~ "Opera") {
set req.http.X-Normalized-User-Agent = "opera";
} else {
set req.http.X-Normalized-User-Agent = "other";
}
Expand All @@ -795,7 +808,7 @@ protected function _vcl_sub_normalize_user_agent() {
protected function _vcl_sub_normalize_encoding() {
$tpl = <<<EOS
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
if (req.http.Accept-Encoding ~ "\*|gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
Expand Down Expand Up @@ -887,6 +900,24 @@ protected function _vcl_sub_maintenance_allowed_ips() {
'debug_ips' => Mage::getStoreConfig('dev/restrict/allow_ips') ));
}

/**
* 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.
*
* @return string
*/
protected function _vcl_sub_https_redirect_fix() {
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$baseUrl = str_replace(array('http://','https://'), '', $baseUrl);
$baseUrl = rtrim($baseUrl,'/');

$tpl = <<<EOS
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
return (synth(750, ""));
}
EOS;
return $tpl;
}

/**
* Get the allowed IPs when in maintenance mode
*
Expand Down Expand Up @@ -1006,10 +1037,18 @@ protected function _getTemplateVars() {
// set the vcl_error from Magento database
$vars['vcl_synth'] = $this->_vcl_sub_synth();
}

if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) {
$vars['https_redirect'] = $this->_vcl_sub_https_redirect_fix();
}

$customIncludeFile = $this->_getCustomIncludeFilename();
if (is_readable($customIncludeFile)) {
$vars['custom_vcl_include'] = file_get_contents($customIncludeFile);
foreach (array('','top') as $position) {
$customIncludeFile = $this->_getCustomIncludeFilename($position);
if (is_readable($customIncludeFile)) {
$key = 'custom_vcl_include';
$key .= ($position) ? '_'.$position : '';
$vars[$key] = file_get_contents($customIncludeFile);
}
}

return $vars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3
* @return string
*/
public function generate($doClean = true) {
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
// first, check if a custom template is set
$customTemplate = $this->_getCustomTemplateFilename();
if ($customTemplate) {
$tplFile = $customTemplate;
}
else {
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
}
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
$this->_getTemplateVars());
return $doClean ? $this->_cleanVcl($vcl) : $vcl;
Expand Down
Loading

0 comments on commit e357731

Please sign in to comment.