comparison src/http/ngx_http_core_module.c @ 3993:f77ed914eb1d

refactor gzip quantity introduced in r3981: it ignored "q=1.000"
author Igor Sysoev <igor@sysoev.ru>
date Thu, 04 Aug 2011 14:50:59 +0000
parents 3165250f6c16
children 87628d211f9a
comparison
equal deleted inserted replaced
3992:a1dd9dc754ab 3993:f77ed914eb1d
69 void *conf); 69 void *conf);
70 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, 70 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
71 void *conf); 71 void *conf);
72 #if (NGX_HTTP_GZIP) 72 #if (NGX_HTTP_GZIP)
73 static ngx_int_t ngx_http_gzip_accept_encoding(ngx_str_t *ae); 73 static ngx_int_t ngx_http_gzip_accept_encoding(ngx_str_t *ae);
74 static ngx_uint_t ngx_http_gzip_quantity(u_char *p, u_char *last);
74 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, 75 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
75 void *conf); 76 void *conf);
76 #endif 77 #endif
77 78
78 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); 79 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
2187 } 2188 }
2188 2189
2189 2190
2190 /* 2191 /*
2191 * gzip is enabled for the following quantities: 2192 * gzip is enabled for the following quantities:
2192 * "gzip; q=0.001" ... "gzip; q=0.999", "gzip; q=1" 2193 * "gzip; q=0.001" ... "gzip; q=1.000"
2193 * gzip is disabled for the following quantities: 2194 * gzip is disabled for the following quantities:
2194 * "gzip; q=0" ... "gzip; q=0.000", and for any invalid cases 2195 * "gzip; q=0" ... "gzip; q=0.000", and for any invalid cases
2195 */ 2196 */
2196 2197
2197 static ngx_int_t 2198 static ngx_int_t
2198 ngx_http_gzip_accept_encoding(ngx_str_t *ae) 2199 ngx_http_gzip_accept_encoding(ngx_str_t *ae)
2199 { 2200 {
2200 u_char c, *p, *start, *last; 2201 u_char *p, *start, *last;
2201 ngx_uint_t n, q;
2202 2202
2203 start = ae->data; 2203 start = ae->data;
2204 last = start + ae->len; 2204 last = start + ae->len;
2205 2205
2206 for ( ;; ) { 2206 for ( ;; ) {
2253 2253
2254 if (p + 2 > last || *p++ != '=') { 2254 if (p + 2 > last || *p++ != '=') {
2255 return NGX_DECLINED; 2255 return NGX_DECLINED;
2256 } 2256 }
2257 2257
2258 if (ngx_http_gzip_quantity(p, last) == 0) {
2259 return NGX_DECLINED;
2260 }
2261
2262 return NGX_OK;
2263 }
2264
2265
2266 ngx_uint_t
2267 ngx_http_gzip_quantity(u_char *p, u_char *last)
2268 {
2269 u_char c;
2270 ngx_uint_t n, q;
2271
2258 c = *p++; 2272 c = *p++;
2259 2273
2260 if (c == '1') { 2274 if (c != '0' && c != '1') {
2261 if (p == last || *p == ',' || *p == ' ') { 2275 return 0;
2262 return NGX_OK; 2276 }
2263 } 2277
2264 return NGX_DECLINED; 2278 q = (c - '0') * 100;
2265 }
2266
2267 if (c != '0') {
2268 return NGX_DECLINED;
2269 }
2270 2279
2271 if (p == last) { 2280 if (p == last) {
2272 return NGX_DECLINED; 2281 return q;
2273 } 2282 }
2274 2283
2275 if (*p++ != '.') { 2284 c = *p++;
2276 return NGX_DECLINED; 2285
2286 if (c == ',' || c == ' ') {
2287 return q;
2288 }
2289
2290 if (c != '.') {
2291 return 0;
2277 } 2292 }
2278 2293
2279 n = 0; 2294 n = 0;
2280 q = 0;
2281 2295
2282 while (p < last) { 2296 while (p < last) {
2283 c = *p++; 2297 c = *p++;
2284 2298
2285 if (c == ',') { 2299 if (c == ',' || c == ' ') {
2286 break; 2300 break;
2287 } 2301 }
2288 2302
2289 if (c >= '1' && c <= '9') { 2303 if (c >= '0' && c <= '9') {
2290 n++; 2304 q += c - '0';
2291 q++;
2292 continue;
2293 }
2294
2295 if (c == '0') {
2296 n++; 2305 n++;
2297 continue; 2306 continue;
2298 } 2307 }
2299 2308
2300 return NGX_DECLINED; 2309 return 0;
2301 } 2310 }
2302 2311
2303 if (n < 4 && q != 0) { 2312 if (q > 100 || n == 0 || n > 3) {
2304 return NGX_OK; 2313 return 0;
2305 } 2314 }
2306 2315
2307 return NGX_DECLINED; 2316 return q;
2308 } 2317 }
2309 2318
2310 #endif 2319 #endif
2311 2320
2312 2321