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 | 23 | #include <string.h> |
24 | 24 | |
25 | 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 | 28 | #define vcl_string char |
29 | 29 | #define LANG_LIST_SIZE 16 |
... | ... | @@ -162,20 +162,21 @@ void select_language(const vcl_string *incoming_header, char *lang) { |
162 | 162 | } |
163 | 163 | |
164 | 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 | 166 | vcl_string *in_hdr; |
167 | 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 | 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 | 174 | /* Normalize and filter out by list of supported languages */ |
173 | 175 | memset(lang, 0, sizeof(lang)); |
174 | 176 | select_language(in_hdr, lang); |
175 | 177 | |
176 | 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 | 180 | return; |
180 | 181 | } |
181 | 182 | |
... | ... | @@ -188,15 +189,14 @@ void vcl_rewrite_accept_language(const struct sess *sp) { |
188 | 189 | |
189 | 190 | sub vcl_recv { |
190 | 191 | C{ |
191 | - vcl_rewrite_accept_language(sp); | |
192 | + vcl_rewrite_accept_language(ctx); | |
192 | 193 | }C |
193 | 194 | } |
194 | 195 | |
195 | -sub vcl_fetch { | |
196 | +sub vcl_backend_response { | |
196 | 197 | if (beresp.http.Vary) { |
197 | 198 | set beresp.http.Vary = beresp.http.Vary + ", X-Varnish-Accept-Language"; |
198 | 199 | } else { |
199 | 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 | 3 | sub vcl_recv { |
2 | - if (req.request == "GET" || req.request == "HEAD") { | |
4 | + if (req.method == "GET" || req.method == "HEAD") { | |
3 | 5 | if (req.http.Cookie) { |
4 | 6 | # We only care about the "_noosfero_.*" cookies, used by Noosfero |
5 | 7 | if (req.http.Cookie !~ "_noosfero_.*" ) { |
... | ... | @@ -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 | 26 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
25 | 27 | <html xmlns="http://www.w3.org/1999/xhtml"> |
26 | 28 | <head> |
... | ... | @@ -52,7 +54,7 @@ sub vcl_error { |
52 | 54 | <div id='wrap'> |
53 | 55 | <div id='header'> |
54 | 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 | 58 | </div> |
57 | 59 | |
58 | 60 | <div id='de' style='display: none' class='message'> |
... | ... | @@ -145,6 +147,6 @@ sub vcl_error { |
145 | 147 | </div> |
146 | 148 | </body> |
147 | 149 | </html> |
148 | - "}; | |
150 | + "}); | |
149 | 151 | return(deliver); |
150 | 152 | } | ... | ... |