content-type header charset info problem

Maxim Dounin mdounin at mdounin.ru
Fri May 11 07:10:03 UTC 2012


Hello!

On Thu, May 10, 2012 at 04:36:46PM -0400, djeps wrote:

> Yes, you're correct Maxim, I've a WURFL-based caching system that
> handles content compression.
> 
> If I understand you correctly, the headers nginx receive from the
> upstream proxied server are sent without avail of the 'charset utf-8;'
> directive in nginx.
> 
> I was wondering If nginx without third party modules would be able to
> append the charset portion of the Content-Type header with the correct
> charset. But then, the answer is no. 

Ah, ok, you are trying to use the "charset" directive to add 
charset, but it doesn't work with gzipped content, right?

This is indeed looks like a problem: charset module ignores 
gzipped content, as it assumes it can't recode it anyway, and it 
doesn't check if it really needs to recode anything.  This should 
be fixed to still allow it to set charset if no recode needed.

You may try the following patch:

--- a/src/http/modules/ngx_http_charset_filter_module.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -258,6 +258,13 @@ ngx_http_charset_header_filter(ngx_http_
         return ngx_http_next_header_filter(r);
     }
 
+    if (!r->ignore_content_encoding
+        && r->headers_out.content_encoding
+        && r->headers_out.content_encoding->value.len)
+    {
+        return ngx_http_next_header_filter(r);
+    }
+
     if (charset == NGX_HTTP_NO_CHARSET
         || source_charset == NGX_HTTP_NO_CHARSET)
     {
@@ -311,13 +318,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;
     }


Maxim Dounin



More information about the nginx mailing list