Commit 9ff5859cc607ca8e41d943fa523eef23da4a93e0
1 parent
dc115f26
Exists in
master
and in
19 other branches
Upgrade varnish configuration to Varnish 4
Based on https://www.varnish-cache.org/docs/4.0/whats-new/upgrading.html The autogenerated part of varnish-accept-language.vcs was refreshed using the 4.0 branch of https://github.com/cosimo/varnish-accept-language and the following command line: ./gen_vcl.pl en cs de eo es fr hy it pt ru < accept-language.c > new.vcl
Showing
2 changed files
with
16 additions
and
14 deletions
Show diff stats
etc/noosfero/varnish-accept-language.vcl
@@ -23,7 +23,7 @@ C{ | @@ -23,7 +23,7 @@ C{ | ||
23 | #include <string.h> | 23 | #include <string.h> |
24 | 24 | ||
25 | #define DEFAULT_LANGUAGE "en" | 25 | #define DEFAULT_LANGUAGE "en" |
26 | -#define SUPPORTED_LANGUAGES ":de:eo:es:fr:hy:it:pt:ru:" | 26 | +#define SUPPORTED_LANGUAGES ":en:cs:de:eo:es:fr:hy:it:pt:ru:" |
27 | 27 | ||
28 | #define vcl_string char | 28 | #define vcl_string char |
29 | #define LANG_LIST_SIZE 16 | 29 | #define LANG_LIST_SIZE 16 |
@@ -162,20 +162,21 @@ void select_language(const vcl_string *incoming_header, char *lang) { | @@ -162,20 +162,21 @@ void select_language(const vcl_string *incoming_header, char *lang) { | ||
162 | } | 162 | } |
163 | 163 | ||
164 | /* Reads req.http.Accept-Language and writes X-Varnish-Accept-Language */ | 164 | /* Reads req.http.Accept-Language and writes X-Varnish-Accept-Language */ |
165 | -void vcl_rewrite_accept_language(const struct sess *sp) { | 165 | +void vcl_rewrite_accept_language(const struct vrt_ctx *ctx) { |
166 | vcl_string *in_hdr; | 166 | vcl_string *in_hdr; |
167 | vcl_string lang[LANG_MAXLEN]; | 167 | vcl_string lang[LANG_MAXLEN]; |
168 | + const struct gethdr_s hdr = { HDR_REQ, "\020Accept-Language:" }; | ||
169 | + const struct gethdr_s hdrUpd = { HDR_REQ, "\032X-Varnish-Accept-Language:"}; | ||
168 | 170 | ||
169 | /* Get Accept-Language header from client */ | 171 | /* Get Accept-Language header from client */ |
170 | - in_hdr = VRT_GetHdr(sp, HDR_REQ, "\020Accept-Language:"); | 172 | + in_hdr = VRT_GetHdr(ctx, &hdr); |
171 | 173 | ||
172 | /* Normalize and filter out by list of supported languages */ | 174 | /* Normalize and filter out by list of supported languages */ |
173 | memset(lang, 0, sizeof(lang)); | 175 | memset(lang, 0, sizeof(lang)); |
174 | select_language(in_hdr, lang); | 176 | select_language(in_hdr, lang); |
175 | 177 | ||
176 | /* By default, use a different header name: don't mess with backend logic */ | 178 | /* By default, use a different header name: don't mess with backend logic */ |
177 | - VRT_SetHdr(sp, HDR_REQ, "\032X-Varnish-Accept-Language:", lang, vrt_magic_string_end); | ||
178 | - | 179 | + VRT_SetHdr(ctx, &hdrUpd, lang, vrt_magic_string_end); |
179 | return; | 180 | return; |
180 | } | 181 | } |
181 | 182 | ||
@@ -188,15 +189,14 @@ void vcl_rewrite_accept_language(const struct sess *sp) { | @@ -188,15 +189,14 @@ void vcl_rewrite_accept_language(const struct sess *sp) { | ||
188 | 189 | ||
189 | sub vcl_recv { | 190 | sub vcl_recv { |
190 | C{ | 191 | C{ |
191 | - vcl_rewrite_accept_language(sp); | 192 | + vcl_rewrite_accept_language(ctx); |
192 | }C | 193 | }C |
193 | } | 194 | } |
194 | 195 | ||
195 | -sub vcl_fetch { | 196 | +sub vcl_backend_response { |
196 | if (beresp.http.Vary) { | 197 | if (beresp.http.Vary) { |
197 | set beresp.http.Vary = beresp.http.Vary + ", X-Varnish-Accept-Language"; | 198 | set beresp.http.Vary = beresp.http.Vary + ", X-Varnish-Accept-Language"; |
198 | } else { | 199 | } else { |
199 | set beresp.http.Vary = "X-Varnish-Accept-Language"; | 200 | set beresp.http.Vary = "X-Varnish-Accept-Language"; |
200 | } | 201 | } |
201 | } | 202 | } |
202 | - |
etc/noosfero/varnish-noosfero.vcl
1 | +vcl 4.0; | ||
2 | + | ||
1 | sub vcl_recv { | 3 | sub vcl_recv { |
2 | - if (req.request == "GET" || req.request == "HEAD") { | 4 | + if (req.method == "GET" || req.method == "HEAD") { |
3 | if (req.http.Cookie) { | 5 | if (req.http.Cookie) { |
4 | # We only care about the "_noosfero_.*" cookies, used by Noosfero | 6 | # We only care about the "_noosfero_.*" cookies, used by Noosfero |
5 | if (req.http.Cookie !~ "_noosfero_.*" ) { | 7 | if (req.http.Cookie !~ "_noosfero_.*" ) { |
@@ -17,10 +19,10 @@ sub vcl_deliver { | @@ -17,10 +19,10 @@ sub vcl_deliver { | ||
17 | } | 19 | } |
18 | } | 20 | } |
19 | 21 | ||
20 | -sub vcl_error { | ||
21 | - set obj.http.Content-Type = "text/html; charset=utf-8"; | 22 | +sub vcl_backend_error { |
23 | + set beresp.http.Content-Type = "text/html; charset=utf-8"; | ||
22 | 24 | ||
23 | - synthetic {" | 25 | + synthetic({" |
24 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | 26 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
25 | <html xmlns="http://www.w3.org/1999/xhtml"> | 27 | <html xmlns="http://www.w3.org/1999/xhtml"> |
26 | <head> | 28 | <head> |
@@ -52,7 +54,7 @@ sub vcl_error { | @@ -52,7 +54,7 @@ sub vcl_error { | ||
52 | <div id='wrap'> | 54 | <div id='wrap'> |
53 | <div id='header'> | 55 | <div id='header'> |
54 | <div id='logo'> </div> | 56 | <div id='logo'> </div> |
55 | - <div id='details'><b>"} + obj.status + "</b> - " + obj.response + {"</div> | 57 | + <div id='details'><b>"} + beresp.status + "</b> - " + beresp.reason + {"</div> |
56 | </div> | 58 | </div> |
57 | 59 | ||
58 | <div id='de' style='display: none' class='message'> | 60 | <div id='de' style='display: none' class='message'> |
@@ -145,6 +147,6 @@ sub vcl_error { | @@ -145,6 +147,6 @@ sub vcl_error { | ||
145 | </div> | 147 | </div> |
146 | </body> | 148 | </body> |
147 | </html> | 149 | </html> |
148 | - "}; | 150 | + "}); |
149 | return(deliver); | 151 | return(deliver); |
150 | } | 152 | } |