[Git][noosfero/noosfero][master] Upgrade varnish configuration to Varnish 4

Antonio Terceiro gitlab at mg.gitlab.com
Wed Dec 2 12:24:16 BRST 2015


Antonio Terceiro pushed to branch master at Noosfero / noosfero


Commits:
9ff5859c by Antonio Terceiro at 2015-12-02T12:22:27Z
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

- - - - -


2 changed files:

- etc/noosfero/varnish-accept-language.vcl
- etc/noosfero/varnish-noosfero.vcl


Changes:

=====================================
etc/noosfero/varnish-accept-language.vcl
=====================================
--- a/etc/noosfero/varnish-accept-language.vcl
+++ b/etc/noosfero/varnish-accept-language.vcl
@@ -23,7 +23,7 @@ C{
 #include <string.h>
 
 #define DEFAULT_LANGUAGE "en"
-#define SUPPORTED_LANGUAGES ":de:eo:es:fr:hy:it:pt:ru:"
+#define SUPPORTED_LANGUAGES ":en:cs:de:eo:es:fr:hy:it:pt:ru:"
 
 #define vcl_string char
 #define LANG_LIST_SIZE 16
@@ -162,20 +162,21 @@ void select_language(const vcl_string *incoming_header, char *lang) {
 }
 
 /* Reads req.http.Accept-Language and writes X-Varnish-Accept-Language */
-void vcl_rewrite_accept_language(const struct sess *sp) {
+void vcl_rewrite_accept_language(const struct vrt_ctx *ctx) {
     vcl_string *in_hdr;
     vcl_string lang[LANG_MAXLEN];
+    const struct gethdr_s hdr = { HDR_REQ, "\020Accept-Language:" };
+    const struct gethdr_s hdrUpd = { HDR_REQ, "\032X-Varnish-Accept-Language:"};
 
     /* Get Accept-Language header from client */
-    in_hdr = VRT_GetHdr(sp, HDR_REQ, "\020Accept-Language:");
+    in_hdr = VRT_GetHdr(ctx, &hdr);
 
     /* Normalize and filter out by list of supported languages */
     memset(lang, 0, sizeof(lang));
     select_language(in_hdr, lang);
 
     /* By default, use a different header name: don't mess with backend logic */
-    VRT_SetHdr(sp, HDR_REQ, "\032X-Varnish-Accept-Language:", lang, vrt_magic_string_end);
-
+    VRT_SetHdr(ctx, &hdrUpd, lang, vrt_magic_string_end);
     return;
 }
 
@@ -188,15 +189,14 @@ void vcl_rewrite_accept_language(const struct sess *sp) {
 
 sub vcl_recv {
   C{
-    vcl_rewrite_accept_language(sp);
+    vcl_rewrite_accept_language(ctx);
   }C
 }
 
-sub vcl_fetch {
+sub vcl_backend_response {
   if (beresp.http.Vary) {
     set beresp.http.Vary = beresp.http.Vary + ", X-Varnish-Accept-Language";
   } else {
     set beresp.http.Vary = "X-Varnish-Accept-Language";
   }
 }
-


=====================================
etc/noosfero/varnish-noosfero.vcl
=====================================
--- a/etc/noosfero/varnish-noosfero.vcl
+++ b/etc/noosfero/varnish-noosfero.vcl
@@ -1,5 +1,7 @@
+vcl 4.0;
+
 sub vcl_recv {
-  if (req.request == "GET" || req.request == "HEAD") {
+  if (req.method == "GET" || req.method == "HEAD") {
     if (req.http.Cookie) {
       # We only care about the "_noosfero_.*" cookies, used by Noosfero
       if (req.http.Cookie !~ "_noosfero_.*" ) {
@@ -17,10 +19,10 @@ sub vcl_deliver {
   }
 }
 
-sub vcl_error {
-    set obj.http.Content-Type = "text/html; charset=utf-8";
+sub vcl_backend_error {
+    set beresp.http.Content-Type = "text/html; charset=utf-8";
 
-    synthetic {"
+    synthetic({"
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
@@ -52,7 +54,7 @@ sub vcl_error {
   <div id='wrap'>
     <div id='header'>
       <div id='logo'> </div>
-      <div id='details'><b>"} + obj.status + "</b> - " + obj.response + {"</div>
+      <div id='details'><b>"} + beresp.status + "</b> - " + beresp.reason + {"</div>
     </div>
 
     <div id='de' style='display: none' class='message'>
@@ -145,6 +147,6 @@ sub vcl_error {
   </div>
 </body>
 </html>
-     "};
+     "});
     return(deliver);
 }



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/9ff5859cc607ca8e41d943fa523eef23da4a93e0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151202/f6578a53/attachment-0001.html>


More information about the Noosfero-dev mailing list