comparison src/http/modules/ngx_http_charset_filter_module.c @ 5698:fcb0420f90de

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 19 May 2014 22:45:34 +0400
parents ae3fd1ca62e0
children a72886067bbb
comparison
equal deleted inserted replaced
5697:c985d90a8d1f 5698:fcb0420f90de
270 ngx_http_set_charset(r, &dst); 270 ngx_http_set_charset(r, &dst);
271 271
272 return ngx_http_next_header_filter(r); 272 return ngx_http_next_header_filter(r);
273 } 273 }
274 274
275 if (source_charset == charset) {
276 r->headers_out.content_type.len = r->headers_out.content_type_len;
277
278 ngx_http_set_charset(r, &dst);
279
280 return ngx_http_next_header_filter(r);
281 }
282
283 /* source_charset != charset */
284
285 if (r->headers_out.content_encoding
286 && r->headers_out.content_encoding->value.len)
287 {
288 return ngx_http_next_header_filter(r);
289 }
290
275 mcf = ngx_http_get_module_main_conf(r, ngx_http_charset_filter_module); 291 mcf = ngx_http_get_module_main_conf(r, ngx_http_charset_filter_module);
276 charsets = mcf->charsets.elts; 292 charsets = mcf->charsets.elts;
277 293
278 if (source_charset != charset 294 if (charsets[source_charset].tables == NULL
279 && (charsets[source_charset].tables == NULL 295 || charsets[source_charset].tables[charset] == NULL)
280 || charsets[source_charset].tables[charset] == NULL))
281 { 296 {
282 goto no_charset_map; 297 goto no_charset_map;
283 } 298 }
284 299
285 r->headers_out.content_type.len = r->headers_out.content_type_len; 300 r->headers_out.content_type.len = r->headers_out.content_type_len;
286 301
287 ngx_http_set_charset(r, &dst); 302 ngx_http_set_charset(r, &dst);
288 303
289 if (source_charset != charset) { 304 return ngx_http_charset_ctx(r, charsets, charset, source_charset);
290 return ngx_http_charset_ctx(r, charsets, charset, source_charset);
291 }
292
293 return ngx_http_next_header_filter(r);
294 305
295 no_charset_map: 306 no_charset_map:
296 307
297 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 308 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
298 "no \"charset_map\" between the charsets \"%V\" and \"%V\"", 309 "no \"charset_map\" between the charsets \"%V\" and \"%V\"",
308 ngx_int_t charset; 319 ngx_int_t charset;
309 ngx_http_charset_t *charsets; 320 ngx_http_charset_t *charsets;
310 ngx_http_variable_value_t *vv; 321 ngx_http_variable_value_t *vv;
311 ngx_http_charset_loc_conf_t *mlcf; 322 ngx_http_charset_loc_conf_t *mlcf;
312 ngx_http_charset_main_conf_t *mcf; 323 ngx_http_charset_main_conf_t *mcf;
313
314 if (!r->ignore_content_encoding
315 && r->headers_out.content_encoding
316 && r->headers_out.content_encoding->value.len)
317 {
318 return NGX_DECLINED;
319 }
320 324
321 if (r->headers_out.content_type.len == 0) { 325 if (r->headers_out.content_type.len == 0) {
322 return NGX_DECLINED; 326 return NGX_DECLINED;
323 } 327 }
324 328