[nginx] Charset filter: fixed charset setting on encoded replies.

Maxim Dounin mdounin at mdounin.ru
Mon May 19 18:47:16 UTC 2014


details:   http://hg.nginx.org/nginx/rev/fcb0420f90de
branches:  
changeset: 5698:fcb0420f90de
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Mon May 19 22:45:34 2014 +0400
description:
Charset filter: fixed charset setting on encoded replies.

If response is gzipped we can't recode response, but in case it's not
needed we still can add charset to Content-Type.

The r->ignore_content_encoding is dropped accordingly, charset with gzip_static
now properly works without any special flags.

diffstat:

 src/http/modules/ngx_http_charset_filter_module.c |  34 ++++++++++++----------
 src/http/modules/ngx_http_gzip_static_module.c    |   2 -
 src/http/ngx_http_request.h                       |   1 -
 3 files changed, 19 insertions(+), 18 deletions(-)

diffs (84 lines):

diff --git a/src/http/modules/ngx_http_charset_filter_module.c b/src/http/modules/ngx_http_charset_filter_module.c
--- a/src/http/modules/ngx_http_charset_filter_module.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -272,12 +272,27 @@ ngx_http_charset_header_filter(ngx_http_
         return ngx_http_next_header_filter(r);
     }
 
+    if (source_charset == charset) {
+        r->headers_out.content_type.len = r->headers_out.content_type_len;
+
+        ngx_http_set_charset(r, &dst);
+
+        return ngx_http_next_header_filter(r);
+    }
+
+    /* source_charset != charset */
+
+    if (r->headers_out.content_encoding
+        && r->headers_out.content_encoding->value.len)
+    {
+        return ngx_http_next_header_filter(r);
+    }
+
     mcf = ngx_http_get_module_main_conf(r, ngx_http_charset_filter_module);
     charsets = mcf->charsets.elts;
 
-    if (source_charset != charset
-        && (charsets[source_charset].tables == NULL
-            || charsets[source_charset].tables[charset] == NULL))
+    if (charsets[source_charset].tables == NULL
+        || charsets[source_charset].tables[charset] == NULL)
     {
         goto no_charset_map;
     }
@@ -286,11 +301,7 @@ ngx_http_charset_header_filter(ngx_http_
 
     ngx_http_set_charset(r, &dst);
 
-    if (source_charset != charset) {
-        return ngx_http_charset_ctx(r, charsets, charset, source_charset);
-    }
-
-    return ngx_http_next_header_filter(r);
+    return ngx_http_charset_ctx(r, charsets, charset, source_charset);
 
 no_charset_map:
 
@@ -311,13 +322,6 @@ ngx_http_destination_charset(ngx_http_re
     ngx_http_charset_loc_conf_t   *mlcf;
     ngx_http_charset_main_conf_t  *mcf;
 
-    if (!r->ignore_content_encoding
-        && r->headers_out.content_encoding
-        && r->headers_out.content_encoding->value.len)
-    {
-        return NGX_DECLINED;
-    }
-
     if (r->headers_out.content_type.len == 0) {
         return NGX_DECLINED;
     }
diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c
--- a/src/http/modules/ngx_http_gzip_static_module.c
+++ b/src/http/modules/ngx_http_gzip_static_module.c
@@ -246,8 +246,6 @@ ngx_http_gzip_static_handler(ngx_http_re
     ngx_str_set(&h->value, "gzip");
     r->headers_out.content_encoding = h;
 
-    r->ignore_content_encoding = 1;
-
     /* we need to allocate all before the header would be sent */
 
     b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -511,7 +511,6 @@ struct ngx_http_request_s {
     unsigned                          discard_body:1;
     unsigned                          internal:1;
     unsigned                          error_page:1;
-    unsigned                          ignore_content_encoding:1;
     unsigned                          filter_finalize:1;
     unsigned                          post_action:1;
     unsigned                          request_complete:1;



More information about the nginx-devel mailing list