diff 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
line wrap: on
line diff
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -14,6 +14,7 @@
 typedef struct {
     ngx_flag_t           enable;
     ngx_flag_t           no_buffer;
+    ngx_flag_t           vary;
 
     ngx_array_t         *types;     /* array of ngx_str_t */
 
@@ -192,6 +193,13 @@ static ngx_command_t  ngx_http_gzip_filt
       offsetof(ngx_http_gzip_conf_t, min_length),
       NULL },
 
+    { ngx_string("gzip_vary"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_gzip_conf_t, vary),
+      NULL },
+
       ngx_null_command
 };
 
@@ -261,6 +269,7 @@ ngx_http_gzip_header_filter(ngx_http_req
 {
     ngx_str_t             *type;
     ngx_uint_t             i;
+    ngx_table_elt_t       *header;
     ngx_http_gzip_ctx_t   *ctx;
     ngx_http_gzip_conf_t  *conf;
 
@@ -336,16 +345,31 @@ found:
 
     ctx->request = r;
 
-    r->headers_out.content_encoding = ngx_list_push(&r->headers_out.headers);
-    if (r->headers_out.content_encoding == NULL) {
+    header = ngx_list_push(&r->headers_out.headers);
+    if (header == NULL) {
         return NGX_ERROR;
     }
 
-    r->headers_out.content_encoding->hash = 1;
-    r->headers_out.content_encoding->key.len = sizeof("Content-Encoding") - 1;
-    r->headers_out.content_encoding->key.data = (u_char *) "Content-Encoding";
-    r->headers_out.content_encoding->value.len = sizeof("gzip") - 1;
-    r->headers_out.content_encoding->value.data = (u_char *) "gzip";
+    header->hash = 1;
+    header->key.len = sizeof("Content-Encoding") - 1;
+    header->key.data = (u_char *) "Content-Encoding";
+    header->value.len = sizeof("gzip") - 1;
+    header->value.data = (u_char *) "gzip";
+
+    r->headers_out.content_encoding = header;
+
+    if (conf->vary) {
+        header = ngx_list_push(&r->headers_out.headers);
+        if (header == NULL) {
+            return NGX_ERROR;
+        }
+
+        header->hash = 1;
+        header->key.len = sizeof("Vary") - 1;
+        header->key.data = (u_char *) "Vary";
+        header->value.len = sizeof("Accept-Encoding") - 1;
+        header->value.data = (u_char *) "Accept-Encoding";
+    }
 
     ctx->length = r->headers_out.content_length_n;
 
@@ -996,6 +1020,7 @@ ngx_http_gzip_create_conf(ngx_conf_t *cf
 
     conf->enable = NGX_CONF_UNSET;
     conf->no_buffer = NGX_CONF_UNSET;
+    conf->vary = NGX_CONF_UNSET;
 
     conf->http_version = NGX_CONF_UNSET_UINT;
 
@@ -1031,6 +1056,7 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf,
                               MAX_MEM_LEVEL - 1);
     ngx_conf_merge_value(conf->min_length, prev->min_length, 20);
     ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
+    ngx_conf_merge_value(conf->vary, prev->vary, 0);
 
     if (conf->types == NULL) {
         if (prev->types == NULL) {