Skip to content

Commit

Permalink
Merge pull request #1317 from nexcess/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
miguelbalparda authored Nov 18, 2016
2 parents f091a08 + 130b166 commit 4929b8a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,22 @@ protected function _vcl_sub_https_redirect_fix() {
$baseUrl = str_replace(array('http://','https://'), '', $baseUrl);
$baseUrl = rtrim($baseUrl,'/');

$tpl = <<<EOS
switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
case 4.0:
$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;
break;
default:
$tpl = <<<EOS
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
error 750 "https://" + req.http.host + req.url;
}
EOS;
}

return $tpl;
}

Expand Down Expand Up @@ -958,6 +969,40 @@ protected function _vcl_sub_synth()
'vcl_synth_content' => Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')));
}

/**
* vcl_synth for fixing https
*
* @return string
*/
protected function _vcl_sub_synth_https_fix()
{
$tpl = $this->_vcl_sub_synth();

if(!$tpl){
$tpl = <<<EOS
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = "https://" + req.http.host + req.url;
return(deliver);
}
}
EOS;
}else{
$tpl_750 = '
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = "https://" + req.http.host + req.url;
return(deliver);
}';

$tpl = str_ireplace('sub vcl_synth {', $tpl_750, $tpl);
}

return $tpl;
}



/**
Expand Down Expand Up @@ -1040,6 +1085,9 @@ protected function _getTemplateVars() {

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'){
$vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix();
}
}

foreach (array('','top') as $position) {
Expand Down
8 changes: 4 additions & 4 deletions app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ sub generate_session_expires {
{{generate_session_end}}
## Varnish Subroutines

sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = "https://" + req.http.host + req.url;
sub vcl_error {
if (obj.status == 750) {
set obj.http.Location = obj.response;
set obj.status = 301;
return(deliver);
}
}
Expand Down
8 changes: 0 additions & 8 deletions app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ sub generate_session_expires {
{{generate_session_end}}
## Varnish Subroutines

sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = "https://" + req.http.host + req.url;
return(deliver);
}
}

sub vcl_init {
{{directors}}
}
Expand Down

0 comments on commit 4929b8a

Please sign in to comment.