diff src/http/modules/ngx_http_gzip_filter_module.c @ 76:da9a3b14312d NGINX_0_1_38

nginx 0.1.38 *) Feature: the "limit_rate" directive is supported in in proxy and FastCGI mode. *) Feature: the "X-Accel-Limit-Rate" response header line is supported in proxy and FastCGI mode. *) Feature: the "break" directive. *) Feature: the "log_not_found" directive. *) Bugfix: the response status code was not changed when request was redirected by the ""X-Accel-Redirect" header line. *) Bugfix: the variables set by the "set" directive could not be used in SSI. *) Bugfix: the segmentation fault may occurred if the SSI page has more than one remote subrequest. *) Bugfix: nginx treated the backend response as invalid if the status line in the header was transferred in two packets; bug appeared in 0.1.29. *) Feature: the "ssi_types" directive. *) Feature: the "autoindex_exact_size" directive. *) Bugfix: the ngx_http_autoindex_module did not support the long file names in UTF-8. *) Feature: the IMAP/POP3 proxy.
author Igor Sysoev <http://sysoev.ru>
date Fri, 08 Jul 2005 00:00:00 +0400
parents 0790a8599248
children 9db7e0b5b27f
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
@@ -15,7 +15,7 @@ typedef struct {
     ngx_flag_t           enable;
     ngx_flag_t           no_buffer;
 
-    ngx_array_t         *types;     /* array of ngx_http_gzip_type_t */
+    ngx_array_t         *types;     /* array of ngx_str_t */
 
     ngx_bufs_t           bufs;
 
@@ -29,12 +29,6 @@ typedef struct {
 } ngx_http_gzip_conf_t;
 
 
-typedef struct {
-    ngx_str_t            name;
-    ngx_uint_t           enable;
-} ngx_http_gzip_type_t;
-
-
 #define NGX_HTTP_GZIP_PROXIED_OFF       0x0002
 #define NGX_HTTP_GZIP_PROXIED_EXPIRED   0x0004
 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE  0x0008
@@ -91,20 +85,18 @@ static ngx_int_t ngx_http_gzip_filter_in
 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static char *ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd,
+static char *ngx_http_gzip_types(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
-static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data);
-static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data);
+static char *ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data);
+static char *ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data);
 
 
 static ngx_conf_num_bounds_t  ngx_http_gzip_comp_level_bounds = {
     ngx_conf_check_num_bounds, 1, 9
 };
 
-static ngx_conf_post_handler_pt  ngx_http_gzip_set_window_p =
-                                                      ngx_http_gzip_set_window;
-static ngx_conf_post_handler_pt  ngx_http_gzip_set_hash_p =
-                                                        ngx_http_gzip_set_hash;
+static ngx_conf_post_handler_pt  ngx_http_gzip_window_p = ngx_http_gzip_window;
+static ngx_conf_post_handler_pt  ngx_http_gzip_hash_p = ngx_http_gzip_hash;
 
 
 
@@ -148,7 +140,7 @@ static ngx_command_t  ngx_http_gzip_filt
 
     { ngx_string("gzip_types"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
-      ngx_http_gzip_set_types,
+      ngx_http_gzip_types,
       NGX_HTTP_LOC_CONF_OFFSET,
       0,
       NULL },
@@ -165,14 +157,14 @@ static ngx_command_t  ngx_http_gzip_filt
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_gzip_conf_t, wbits),
-      &ngx_http_gzip_set_window_p },
+      &ngx_http_gzip_window_p },
 
     { ngx_string("gzip_hash"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_gzip_conf_t, memlevel),
-      &ngx_http_gzip_set_hash_p },
+      &ngx_http_gzip_hash_p },
 
     { ngx_string("gzip_no_buffer"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
@@ -270,10 +262,10 @@ static ngx_http_output_body_filter_pt   
 static ngx_int_t
 ngx_http_gzip_header_filter(ngx_http_request_t *r)
 {
-    ngx_uint_t             i, found;
+    ngx_str_t             *type;
+    ngx_uint_t             i;
     ngx_http_gzip_ctx_t   *ctx;
     ngx_http_gzip_conf_t  *conf;
-    ngx_http_gzip_type_t  *type;
 
     conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
 
@@ -297,24 +289,21 @@ ngx_http_gzip_header_filter(ngx_http_req
     }
 
 
-    found = 0;
     type = conf->types->elts;
-
     for (i = 0; i < conf->types->nelts; i++) {
-        if (r->headers_out.content_type.len >= type[i].name.len
+        if (r->headers_out.content_type.len >= type[i].len
             && ngx_strncasecmp(r->headers_out.content_type.data, 
-                               type[i].name.data, type[i].name.len) == 0)
+                               type[i].data, type[i].len) == 0)
         {
-            found = 1;
-            break;
+            goto found;
         }
     }
 
-    if (!found) {
-        return ngx_http_next_header_filter(r);
-    }
+    return ngx_http_next_header_filter(r);
 
 
+found:
+
     if (r->headers_in.via) {
         if (conf->proxied & NGX_HTTP_GZIP_PROXIED_OFF) {
             return ngx_http_next_header_filter(r);
@@ -1031,7 +1020,7 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf,
     ngx_http_gzip_conf_t *prev = parent;
     ngx_http_gzip_conf_t *conf = child;
 
-    ngx_http_gzip_type_t  *type;
+    ngx_str_t  *type;
 
     ngx_conf_merge_value(conf->enable, prev->enable, 0);
 
@@ -1051,8 +1040,7 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf,
 
     if (conf->types == NULL) {
         if (prev->types == NULL) {
-            conf->types = ngx_array_create(cf->pool, 1,
-                                           sizeof(ngx_http_gzip_type_t));
+            conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t));
             if (conf->types == NULL) {
                 return NGX_CONF_ERROR;
             }
@@ -1062,9 +1050,8 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf,
                 return NGX_CONF_ERROR;
             }
 
-            type->name.len = sizeof("text/html") - 1;
-            type->name.data = (u_char *) "text/html";
-            type->enable = 1;
+            type->len = sizeof("text/html") - 1;
+            type->data = (u_char *) "text/html";
 
         } else {
             conf->types = prev->types;
@@ -1076,17 +1063,15 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf,
 
 
 static char *
-ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+ngx_http_gzip_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     ngx_http_gzip_conf_t *gcf = conf;
 
-    ngx_str_t             *value;
-    ngx_uint_t             i;
-    ngx_http_gzip_type_t  *type;
+    ngx_str_t   *value, *type;
+    ngx_uint_t   i;
 
     if (gcf->types == NULL) {
-        gcf->types = ngx_array_create(cf->pool, 4,
-                                      sizeof(ngx_http_gzip_type_t));
+        gcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
         if (gcf->types == NULL) {
             return NGX_CONF_ERROR;
         }
@@ -1096,9 +1081,8 @@ ngx_http_gzip_set_types(ngx_conf_t *cf, 
             return NGX_CONF_ERROR;
         }
 
-        type->name.len = sizeof("text/html") - 1;
-        type->name.data = (u_char *) "text/html";
-        type->enable = 1;
+        type->len = sizeof("text/html") - 1;
+        type->data = (u_char *) "text/html";
     }
 
     value = cf->args->elts;
@@ -1114,14 +1098,14 @@ ngx_http_gzip_set_types(ngx_conf_t *cf, 
             return NGX_CONF_ERROR;
         }
 
-        type->name.len = value[i].len;
+        type->len = value[i].len;
 
-        type->name.data = ngx_palloc(cf->pool, type->name.len + 1);
-        if (type->name.data == NULL) {
+        type->data = ngx_palloc(cf->pool, type->len + 1);
+        if (type->data == NULL) {
             return NGX_CONF_ERROR;
         }
 
-        ngx_cpystrn(type->name.data, value[i].data, type->name.len + 1);
+        ngx_cpystrn(type->data, value[i].data, type->len + 1);
     }
 
     return NGX_CONF_OK;
@@ -1129,7 +1113,7 @@ ngx_http_gzip_set_types(ngx_conf_t *cf, 
 
 
 static char *
-ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data)
+ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data)
 {
     int *np = data;
 
@@ -1153,7 +1137,7 @@ ngx_http_gzip_set_window(ngx_conf_t *cf,
 
 
 static char *
-ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data)
+ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data)
 {
     int *np = data;