comparison src/http/modules/ngx_http_charset_filter_module.c @ 212:56688ed172c8 NGINX_0_3_53

nginx 0.3.53 *) Change: the "add_header" directive adds the string to 204, 301, and 302 responses. *) Feature: the "server" directive in the "upstream" context supports the "weight" parameter. *) Feature: the "server_name" directive supports the "*" wildcard. *) Feature: nginx supports the request body size more than 2G. *) Bugfix: if a client was successfully authorized using "satisfy_any on", then anyway the message "access forbidden by rule" was written in the log. *) Bugfix: the "PUT" method may erroneously not create a file and return the 409 code. *) Bugfix: if the IMAP/POP3 backend returned an error, then nginx continued proxying anyway.
author Igor Sysoev <http://sysoev.ru>
date Fri, 07 Jul 2006 00:00:00 +0400
parents 14050d2bec9b
children 0ad9eeb6ac7f
comparison
equal deleted inserted replaced
211:f04a54878110 212:56688ed172c8
186 static ngx_int_t 186 static ngx_int_t
187 ngx_http_charset_header_filter(ngx_http_request_t *r) 187 ngx_http_charset_header_filter(ngx_http_request_t *r)
188 { 188 {
189 u_char *ct; 189 u_char *ct;
190 ngx_int_t charset, source_charset; 190 ngx_int_t charset, source_charset;
191 ngx_str_t *mc; 191 ngx_str_t *mc, *from, *to;
192 ngx_uint_t n; 192 ngx_uint_t n;
193 ngx_http_charset_t *charsets; 193 ngx_http_charset_t *charsets;
194 ngx_http_charset_ctx_t *ctx; 194 ngx_http_charset_ctx_t *ctx;
195 ngx_http_charset_loc_conf_t *lcf, *mlcf; 195 ngx_http_charset_loc_conf_t *lcf, *mlcf;
196 ngx_http_charset_main_conf_t *mcf; 196 ngx_http_charset_main_conf_t *mcf;
286 286
287 if (lcf->source_charset == NGX_CONF_UNSET) { 287 if (lcf->source_charset == NGX_CONF_UNSET) {
288 return ngx_http_next_header_filter(r); 288 return ngx_http_next_header_filter(r);
289 } 289 }
290 290
291 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 291 from = &charsets[lcf->source_charset].name;
292 "no \"charset_map\" between the charsets " 292 to = &r->main->headers_out.charset;
293 "\"%V\" and \"%V\"", 293
294 &charsets[lcf->source_charset].name, 294 goto no_charset_map;
295 &r->main->headers_out.charset);
296
297 return ngx_http_next_header_filter(r);
298 } 295 }
299 296
300 source_charset = ngx_http_charset_get_charset(charsets, n, 297 source_charset = ngx_http_charset_get_charset(charsets, n,
301 r->headers_out.charset.data); 298 r->headers_out.charset.data);
302 299
306 if (charset != source_charset 303 if (charset != source_charset
307 || ngx_strcasecmp(r->main->headers_out.charset.data, 304 || ngx_strcasecmp(r->main->headers_out.charset.data,
308 r->headers_out.charset.data) 305 r->headers_out.charset.data)
309 != 0) 306 != 0)
310 { 307 {
311 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 308 from = &r->headers_out.charset;
312 "no \"charset_map\" between the charsets " 309 to = (charset == NGX_HTTP_NO_CHARSET) ?
313 "\"%V\" and \"%V\"", 310 &r->main->headers_out.charset:
314 &r->headers_out.charset, 311 &charsets[charset].name;
315 &r->main->headers_out.charset); 312
313 goto no_charset_map;
316 } 314 }
317 315
318 return ngx_http_next_header_filter(r); 316 return ngx_http_next_header_filter(r);
319 } 317 }
320 318
321 if (source_charset != charset 319 if (source_charset != charset
322 && (charsets[source_charset].tables == NULL 320 && (charsets[source_charset].tables == NULL
323 || charsets[source_charset].tables[charset] == NULL)) 321 || charsets[source_charset].tables[charset] == NULL))
324 { 322 {
325 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 323 from = &charsets[source_charset].name;
326 "no \"charset_map\" between the charsets " 324 to = &charsets[charset].name;
327 "\"%V\" and \"%V\"", 325
328 &charsets[source_charset].name, &charsets[charset].name); 326 goto no_charset_map;
329
330 return ngx_http_next_header_filter(r);
331 } 327 }
332 328
333 r->headers_out.content_type.len = r->headers_out.content_type_len; 329 r->headers_out.content_type.len = r->headers_out.content_type_len;
334 330
335 return ngx_http_charset_set_charset(r, mcf->charsets.elts, charset, 331 return ngx_http_charset_set_charset(r, mcf->charsets.elts, charset,
336 source_charset); 332 source_charset);
333
334 no_charset_map:
335
336 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
337 "no \"charset_map\" between the charsets "
338 "\"%V\" and \"%V\"", from, to);
339
340 return ngx_http_next_header_filter(r);
337 } 341 }
338 342
339 343
340 static ngx_int_t 344 static ngx_int_t
341 ngx_http_charset_get_charset(ngx_http_charset_t *charsets, ngx_uint_t n, 345 ngx_http_charset_get_charset(ngx_http_charset_t *charsets, ngx_uint_t n,
390 ctx->charset = charset; 394 ctx->charset = charset;
391 ctx->length = charsets[charset].length; 395 ctx->length = charsets[charset].length;
392 ctx->from_utf8 = charsets[source_charset].utf8; 396 ctx->from_utf8 = charsets[source_charset].utf8;
393 ctx->to_utf8 = charsets[charset].utf8; 397 ctx->to_utf8 = charsets[charset].utf8;
394 398
399 r->filter_need_in_memory = 1;
400
395 if ((ctx->to_utf8 || ctx->from_utf8) && r == r->main) { 401 if ((ctx->to_utf8 || ctx->from_utf8) && r == r->main) {
396 ngx_http_clear_content_length(r); 402 ngx_http_clear_content_length(r);
397 } 403
398 404 } else {
399 r->filter_need_in_memory = 1; 405 r->filter_need_temporary = 1;
406 }
400 407
401 return ngx_http_next_header_filter(r); 408 return ngx_http_next_header_filter(r);
402 } 409 }
403 410
404 411