diff src/http/modules/ngx_http_addition_filter_module.c @ 394:05981f639d21 NGINX_0_7_9

nginx 0.7.9 *) Change: now ngx_http_charset_module works by default with following MIME types: text/html, text/css, text/xml, text/plain, text/vnd.wap.wml, application/x-javascript, and application/rss+xml. *) Feature: the "charset_types" and "addition_types" directives. *) Feature: now the "gzip_types", "ssi_types", and "sub_filter_types" directives use hash. *) Feature: the ngx_cpp_test_module. *) Feature: the "expires" directive supports daily time. *) Feature: the ngx_http_xslt_module improvements and bug fixing. Thanks to Denis F. Latypoff and Maxim Dounin. *) Bugfix: the "log_not_found" directive did not work for index files tests. *) Bugfix: HTTPS connections might hang, if kqueue, epoll, rtsig, or eventport methods were used; the bug had appeared in 0.7.7. *) Bugfix: if the "server_name", "valid_referers", and "map" directives used an "*.domain.tld" wildcard and exact name "domain.tld" was not set, then the exact name was matched by the wildcard; the bugs had appeared in 0.3.18.
author Igor Sysoev <http://sysoev.ru>
date Tue, 12 Aug 2008 00:00:00 +0400
parents 5bef04fc3fd5
children e7dbea1ee115
line wrap: on
line diff
--- a/src/http/modules/ngx_http_addition_filter_module.c
+++ b/src/http/modules/ngx_http_addition_filter_module.c
@@ -10,13 +10,16 @@
 
 
 typedef struct {
-    ngx_str_t   before_body;
-    ngx_str_t   after_body;
+    ngx_str_t     before_body;
+    ngx_str_t     after_body;
+
+    ngx_hash_t    types;
+    ngx_array_t  *types_keys;
 } ngx_http_addition_conf_t;
 
 
 typedef struct {
-    ngx_uint_t  before_body_sent;
+    ngx_uint_t    before_body_sent;
 } ngx_http_addition_ctx_t;
 
 
@@ -42,6 +45,13 @@ static ngx_command_t  ngx_http_addition_
       offsetof(ngx_http_addition_conf_t, after_body),
       NULL },
 
+    { ngx_string("addtion_types"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
+      ngx_http_types_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_addition_conf_t, types_keys),
+      &ngx_http_html_default_types[0] },
+
       ngx_null_command
 };
 
@@ -87,10 +97,7 @@ ngx_http_addition_header_filter(ngx_http
     ngx_http_addition_ctx_t   *ctx;
     ngx_http_addition_conf_t  *conf;
 
-    if (r->headers_out.status != NGX_HTTP_OK
-        || r != r->main
-        || r->headers_out.content_type.data == NULL)
-    {
+    if (r->headers_out.status != NGX_HTTP_OK || r != r->main) {
         return ngx_http_next_header_filter(r);
     }
 
@@ -100,10 +107,7 @@ ngx_http_addition_header_filter(ngx_http
         return ngx_http_next_header_filter(r);
     }
 
-    if (ngx_strncasecmp(r->headers_out.content_type.data,
-                        (u_char *) "text/html", sizeof("text/html") - 1)
-        != 0)
-    {
+    if (ngx_http_test_content_type(r, &conf->types) == NULL) {
         return ngx_http_next_header_filter(r);
     }
 
@@ -214,10 +218,10 @@ ngx_http_addition_create_conf(ngx_conf_t
     /*
      * set by ngx_pcalloc():
      *
-     *     conf->before_body.len = 0;
-     *     conf->before_body.date = NULL;
-     *     conf->after_body.len = 0;
-     *     conf->after_body.date = NULL;
+     *     conf->before_body = { 0, NULL };
+     *     conf->after_body = { 0, NULL };
+     *     conf->types = { NULL };
+     *     conf->types_keys = NULL;
      */
 
     return conf;
@@ -233,5 +237,13 @@ ngx_http_addition_merge_conf(ngx_conf_t 
     ngx_conf_merge_str_value(conf->before_body, prev->before_body, "");
     ngx_conf_merge_str_value(conf->after_body, prev->after_body, "");
 
+    if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
+                             prev->types_keys, &prev->types,
+                             ngx_http_html_default_types)
+        != NGX_OK)
+    {
+        return NGX_CONF_ERROR;
+    }
+
     return NGX_CONF_OK;
 }