Skip to content

Commit 4929b8a

Browse files
Merge pull request #1317 from nexcess/devel
Devel
2 parents f091a08 + 130b166 commit 4929b8a

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

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

+49-1
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,22 @@ protected function _vcl_sub_https_redirect_fix() {
910910
$baseUrl = str_replace(array('http://','https://'), '', $baseUrl);
911911
$baseUrl = rtrim($baseUrl,'/');
912912

913-
$tpl = <<<EOS
913+
switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
914+
case 4.0:
915+
$tpl = <<<EOS
914916
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
915917
return (synth(750, ""));
916918
}
917919
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+
918929
return $tpl;
919930
}
920931

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

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+
9611006

9621007

9631008
/**
@@ -1040,6 +1085,9 @@ protected function _getTemplateVars() {
10401085

10411086
if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) {
10421087
$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+
}
10431091
}
10441092

10451093
foreach (array('','top') as $position) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ sub generate_session_expires {
9696
{{generate_session_end}}
9797
## Varnish Subroutines
9898

99-
sub vcl_synth {
100-
if (resp.status == 750) {
101-
set resp.status = 301;
102-
set resp.http.Location = "https://" + req.http.host + req.url;
99+
sub vcl_error {
100+
if (obj.status == 750) {
101+
set obj.http.Location = obj.response;
102+
set obj.status = 301;
103103
return(deliver);
104104
}
105105
}

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

-8
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ sub generate_session_expires {
102102
{{generate_session_end}}
103103
## Varnish Subroutines
104104

105-
sub vcl_synth {
106-
if (resp.status == 750) {
107-
set resp.status = 301;
108-
set resp.http.Location = "https://" + req.http.host + req.url;
109-
return(deliver);
110-
}
111-
}
112-
113105
sub vcl_init {
114106
{{directors}}
115107
}

0 commit comments

Comments
 (0)