Commit 6c535561c8d9b048129655382a5e6ef4d5b2ca63
1 parent
99fa04df
Exists in
master
and in
22 other branches
Fix 400 bad request of varnish with nginx and apache 2.4
Update vcl from https://github.com/cosimo/varnish-accept-language ./gen_vcl.pl pt de eo es fr hy it pt ru < accept-language.c > new.vcl (ActionItem3186)
Showing
1 changed file
with
19 additions
and
10 deletions
Show diff stats
etc/noosfero/varnish-accept-language.vcl
| ... | ... | @@ -6,7 +6,14 @@ C{ |
| 6 | 6 | /* |
| 7 | 7 | * Accept-language header normalization |
| 8 | 8 | * |
| 9 | - * Cosimo, 21/01/2010 | |
| 9 | + * - Parses client Accept-Language HTTP header | |
| 10 | + * - Tries to find the best match with the supported languages | |
| 11 | + * - Writes the best match as req.http.X-Varnish-Accept-Language | |
| 12 | + * | |
| 13 | + * First version: Cosimo, 21/Jan/2010 | |
| 14 | + * Last update: Cosimo, 03/Nov/2011 | |
| 15 | + * | |
| 16 | + * http://github.com/cosimo/varnish-accept-language | |
| 10 | 17 | * |
| 11 | 18 | */ |
| 12 | 19 | |
| ... | ... | @@ -16,11 +23,12 @@ C{ |
| 16 | 23 | #include <string.h> |
| 17 | 24 | |
| 18 | 25 | #define DEFAULT_LANGUAGE "en" |
| 19 | -#define SUPPORTED_LANGUAGES ":de:fr:es:ru:pt:hy:en:" | |
| 26 | +#define SUPPORTED_LANGUAGES ":de:eo:es:fr:hy:it:pt:ru:" | |
| 20 | 27 | |
| 21 | 28 | #define vcl_string char |
| 22 | -#define LANG_LIST_SIZE 16 | |
| 23 | -#define LANG_MAXLEN 16 | |
| 29 | +#define LANG_LIST_SIZE 16 | |
| 30 | +#define HDR_MAXLEN 256 | |
| 31 | +#define LANG_MAXLEN 8 | |
| 24 | 32 | #define RETURN_LANG(x) { \ |
| 25 | 33 | strncpy(lang, x, LANG_MAXLEN); \ |
| 26 | 34 | return; \ |
| ... | ... | @@ -64,9 +72,8 @@ int is_supported(vcl_string *lang) { |
| 64 | 72 | strncat(match_str, lang, LANG_MAXLEN); |
| 65 | 73 | strncat(match_str, ":\0", 2); |
| 66 | 74 | |
| 67 | - if (strstr(supported_languages, match_str)) { | |
| 75 | + if (strstr(supported_languages, match_str)) | |
| 68 | 76 | is_supported = 1; |
| 69 | - } | |
| 70 | 77 | |
| 71 | 78 | return is_supported; |
| 72 | 79 | } |
| ... | ... | @@ -90,6 +97,7 @@ void select_language(const vcl_string *incoming_header, char *lang) { |
| 90 | 97 | vcl_string *lang_tok = NULL; |
| 91 | 98 | vcl_string root_lang[3]; |
| 92 | 99 | vcl_string *header; |
| 100 | + vcl_string header_copy[HDR_MAXLEN]; | |
| 93 | 101 | vcl_string *pos = NULL; |
| 94 | 102 | vcl_string *q_spec = NULL; |
| 95 | 103 | unsigned int curr_lang = 0, i = 0; |
| ... | ... | @@ -106,7 +114,7 @@ void select_language(const vcl_string *incoming_header, char *lang) { |
| 106 | 114 | RETURN_DEFAULT_LANG; |
| 107 | 115 | |
| 108 | 116 | /* Tokenize Accept-Language */ |
| 109 | - header = (vcl_string *) incoming_header; | |
| 117 | + header = strncpy(header_copy, incoming_header, sizeof(header_copy)); | |
| 110 | 118 | |
| 111 | 119 | while ((lang_tok = strtok_r(header, " ,", &pos))) { |
| 112 | 120 | |
| ... | ... | @@ -137,7 +145,8 @@ void select_language(const vcl_string *incoming_header, char *lang) { |
| 137 | 145 | header = NULL; |
| 138 | 146 | |
| 139 | 147 | /* Break out if stored max no. of languages */ |
| 140 | - if (curr_lang >= LANG_MAXLEN) break; | |
| 148 | + if (curr_lang >= LANG_LIST_SIZE) | |
| 149 | + break; | |
| 141 | 150 | } |
| 142 | 151 | |
| 143 | 152 | /* Sort by priority */ |
| ... | ... | @@ -157,12 +166,11 @@ void vcl_rewrite_accept_language(const struct sess *sp) { |
| 157 | 166 | vcl_string *in_hdr; |
| 158 | 167 | vcl_string lang[LANG_MAXLEN]; |
| 159 | 168 | |
| 160 | - memset(lang, 0, LANG_MAXLEN); | |
| 161 | - | |
| 162 | 169 | /* Get Accept-Language header from client */ |
| 163 | 170 | in_hdr = VRT_GetHdr(sp, HDR_REQ, "\020Accept-Language:"); |
| 164 | 171 | |
| 165 | 172 | /* Normalize and filter out by list of supported languages */ |
| 173 | + memset(lang, 0, sizeof(lang)); | |
| 166 | 174 | select_language(in_hdr, lang); |
| 167 | 175 | |
| 168 | 176 | /* By default, use a different header name: don't mess with backend logic */ |
| ... | ... | @@ -191,3 +199,4 @@ sub vcl_fetch { |
| 191 | 199 | set beresp.http.Vary = "X-Varnish-Accept-Language"; |
| 192 | 200 | } |
| 193 | 201 | } |
| 202 | + | ... | ... |