comparison src/http/modules/ngx_http_gzip_filter_module.c @ 342:4276c2f1f434 NGINX_0_6_15

nginx 0.6.15 *) Feature: cygwin compatibility. Thanks to Vladimir Kutakov. *) Feature: the "merge_slashes" directive. *) Feature: the "gzip_vary" directive. *) Feature: the "server_tokens" directive. *) Bugfix: nginx did not unescape URI in the "include" SSI command. *) Bugfix: the segmentation fault was occurred on start or while reconfiguration if variable was used in the "charset" or "source_charset" directives. *) Bugfix: nginx returned the 400 response on requests like "GET http://www.domain.com HTTP/1.0". Thanks to James Oakley. *) Bugfix: if request with request body was redirected using the "error_page" directive, then nginx tried to read the request body again; bug appeared in 0.6.7. *) Bugfix: a segmentation fault occurred in worker process if no server_name was explicitly defined for server processing request; bug appeared in 0.6.7.
author Igor Sysoev <http://sysoev.ru>
date Mon, 22 Oct 2007 00:00:00 +0400
parents 10cc350ed8a1
children 05693816539c
comparison
equal deleted inserted replaced
341:183b4761fe5b 342:4276c2f1f434
12 12
13 13
14 typedef struct { 14 typedef struct {
15 ngx_flag_t enable; 15 ngx_flag_t enable;
16 ngx_flag_t no_buffer; 16 ngx_flag_t no_buffer;
17 ngx_flag_t vary;
17 18
18 ngx_array_t *types; /* array of ngx_str_t */ 19 ngx_array_t *types; /* array of ngx_str_t */
19 20
20 ngx_bufs_t bufs; 21 ngx_bufs_t bufs;
21 22
188 { ngx_string("gzip_min_length"), 189 { ngx_string("gzip_min_length"),
189 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 190 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
190 ngx_conf_set_size_slot, 191 ngx_conf_set_size_slot,
191 NGX_HTTP_LOC_CONF_OFFSET, 192 NGX_HTTP_LOC_CONF_OFFSET,
192 offsetof(ngx_http_gzip_conf_t, min_length), 193 offsetof(ngx_http_gzip_conf_t, min_length),
194 NULL },
195
196 { ngx_string("gzip_vary"),
197 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
198 ngx_conf_set_flag_slot,
199 NGX_HTTP_LOC_CONF_OFFSET,
200 offsetof(ngx_http_gzip_conf_t, vary),
193 NULL }, 201 NULL },
194 202
195 ngx_null_command 203 ngx_null_command
196 }; 204 };
197 205
259 static ngx_int_t 267 static ngx_int_t
260 ngx_http_gzip_header_filter(ngx_http_request_t *r) 268 ngx_http_gzip_header_filter(ngx_http_request_t *r)
261 { 269 {
262 ngx_str_t *type; 270 ngx_str_t *type;
263 ngx_uint_t i; 271 ngx_uint_t i;
272 ngx_table_elt_t *header;
264 ngx_http_gzip_ctx_t *ctx; 273 ngx_http_gzip_ctx_t *ctx;
265 ngx_http_gzip_conf_t *conf; 274 ngx_http_gzip_conf_t *conf;
266 275
267 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); 276 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
268 277
334 ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module); 343 ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module);
335 344
336 345
337 ctx->request = r; 346 ctx->request = r;
338 347
339 r->headers_out.content_encoding = ngx_list_push(&r->headers_out.headers); 348 header = ngx_list_push(&r->headers_out.headers);
340 if (r->headers_out.content_encoding == NULL) { 349 if (header == NULL) {
341 return NGX_ERROR; 350 return NGX_ERROR;
342 } 351 }
343 352
344 r->headers_out.content_encoding->hash = 1; 353 header->hash = 1;
345 r->headers_out.content_encoding->key.len = sizeof("Content-Encoding") - 1; 354 header->key.len = sizeof("Content-Encoding") - 1;
346 r->headers_out.content_encoding->key.data = (u_char *) "Content-Encoding"; 355 header->key.data = (u_char *) "Content-Encoding";
347 r->headers_out.content_encoding->value.len = sizeof("gzip") - 1; 356 header->value.len = sizeof("gzip") - 1;
348 r->headers_out.content_encoding->value.data = (u_char *) "gzip"; 357 header->value.data = (u_char *) "gzip";
358
359 r->headers_out.content_encoding = header;
360
361 if (conf->vary) {
362 header = ngx_list_push(&r->headers_out.headers);
363 if (header == NULL) {
364 return NGX_ERROR;
365 }
366
367 header->hash = 1;
368 header->key.len = sizeof("Vary") - 1;
369 header->key.data = (u_char *) "Vary";
370 header->value.len = sizeof("Accept-Encoding") - 1;
371 header->value.data = (u_char *) "Accept-Encoding";
372 }
349 373
350 ctx->length = r->headers_out.content_length_n; 374 ctx->length = r->headers_out.content_length_n;
351 375
352 r->main_filter_need_in_memory = 1; 376 r->main_filter_need_in_memory = 1;
353 377
994 * conf->types = NULL; 1018 * conf->types = NULL;
995 */ 1019 */
996 1020
997 conf->enable = NGX_CONF_UNSET; 1021 conf->enable = NGX_CONF_UNSET;
998 conf->no_buffer = NGX_CONF_UNSET; 1022 conf->no_buffer = NGX_CONF_UNSET;
1023 conf->vary = NGX_CONF_UNSET;
999 1024
1000 conf->http_version = NGX_CONF_UNSET_UINT; 1025 conf->http_version = NGX_CONF_UNSET_UINT;
1001 1026
1002 conf->level = NGX_CONF_UNSET; 1027 conf->level = NGX_CONF_UNSET;
1003 conf->wbits = (size_t) NGX_CONF_UNSET; 1028 conf->wbits = (size_t) NGX_CONF_UNSET;
1029 ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS); 1054 ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS);
1030 ngx_conf_merge_size_value(conf->memlevel, prev->memlevel, 1055 ngx_conf_merge_size_value(conf->memlevel, prev->memlevel,
1031 MAX_MEM_LEVEL - 1); 1056 MAX_MEM_LEVEL - 1);
1032 ngx_conf_merge_value(conf->min_length, prev->min_length, 20); 1057 ngx_conf_merge_value(conf->min_length, prev->min_length, 20);
1033 ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0); 1058 ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
1059 ngx_conf_merge_value(conf->vary, prev->vary, 0);
1034 1060
1035 if (conf->types == NULL) { 1061 if (conf->types == NULL) {
1036 if (prev->types == NULL) { 1062 if (prev->types == NULL) {
1037 conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t)); 1063 conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t));
1038 if (conf->types == NULL) { 1064 if (conf->types == NULL) {