comparison src/http/modules/ngx_http_charset_filter_module.c @ 397: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 0b6053502c55
children 349057ecf4d5
comparison
equal deleted inserted replaced
395:040b8c84d040 397:05981f639d21
50 50
51 typedef struct { 51 typedef struct {
52 ngx_int_t charset; 52 ngx_int_t charset;
53 ngx_int_t source_charset; 53 ngx_int_t source_charset;
54 ngx_flag_t override_charset; 54 ngx_flag_t override_charset;
55
56 ngx_hash_t types;
57 ngx_array_t *types_keys;
55 } ngx_http_charset_loc_conf_t; 58 } ngx_http_charset_loc_conf_t;
56 59
57 60
58 typedef struct { 61 typedef struct {
59 u_char *table; 62 u_char *table;
108 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, 111 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
109 void *parent, void *child); 112 void *parent, void *child);
110 static ngx_int_t ngx_http_charset_postconfiguration(ngx_conf_t *cf); 113 static ngx_int_t ngx_http_charset_postconfiguration(ngx_conf_t *cf);
111 114
112 115
116 ngx_str_t ngx_http_charset_default_types[] = {
117 ngx_string("text/html"),
118 ngx_string("text/css"),
119 ngx_string("text/xml"),
120 ngx_string("text/plain"),
121 ngx_string("text/vnd.wap.wml"),
122 ngx_string("application/x-javascript"),
123 ngx_string("application/rss+xml"),
124 ngx_null_string
125 };
126
127
113 static ngx_command_t ngx_http_charset_filter_commands[] = { 128 static ngx_command_t ngx_http_charset_filter_commands[] = {
114 129
115 { ngx_string("charset"), 130 { ngx_string("charset"),
116 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF 131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
117 |NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, 132 |NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
133 |NGX_HTTP_LIF_CONF|NGX_CONF_FLAG, 148 |NGX_HTTP_LIF_CONF|NGX_CONF_FLAG,
134 ngx_conf_set_flag_slot, 149 ngx_conf_set_flag_slot,
135 NGX_HTTP_LOC_CONF_OFFSET, 150 NGX_HTTP_LOC_CONF_OFFSET,
136 offsetof(ngx_http_charset_loc_conf_t, override_charset), 151 offsetof(ngx_http_charset_loc_conf_t, override_charset),
137 NULL }, 152 NULL },
153
154 { ngx_string("charset_types"),
155 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
156 ngx_http_types_slot,
157 NGX_HTTP_LOC_CONF_OFFSET,
158 offsetof(ngx_http_charset_loc_conf_t, types_keys),
159 &ngx_http_charset_default_types[0] },
138 160
139 { ngx_string("charset_map"), 161 { ngx_string("charset_map"),
140 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2, 162 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2,
141 ngx_http_charset_map_block, 163 ngx_http_charset_map_block,
142 NGX_HTTP_MAIN_CONF_OFFSET, 164 NGX_HTTP_MAIN_CONF_OFFSET,
183 205
184 206
185 static ngx_int_t 207 static ngx_int_t
186 ngx_http_charset_header_filter(ngx_http_request_t *r) 208 ngx_http_charset_header_filter(ngx_http_request_t *r)
187 { 209 {
188 u_char *ct;
189 ngx_int_t charset, source_charset; 210 ngx_int_t charset, source_charset;
190 ngx_str_t *mc, *from, *to, s; 211 ngx_str_t *mc, *from, *to, s;
191 ngx_uint_t n; 212 ngx_uint_t n;
192 ngx_http_charset_t *charsets; 213 ngx_http_charset_t *charsets;
193 ngx_http_charset_ctx_t *ctx; 214 ngx_http_charset_ctx_t *ctx;
241 if (mlcf->override_charset == 0) { 262 if (mlcf->override_charset == 0) {
242 return ngx_http_next_header_filter(r); 263 return ngx_http_next_header_filter(r);
243 } 264 }
244 265
245 } else { 266 } else {
246 ct = r->headers_out.content_type.data; 267 if (ngx_http_test_content_type(r, &mlcf->types) == NULL) {
247
248 if (ngx_strncasecmp(ct, (u_char *) "text/", 5) != 0
249 && ngx_strncasecmp(ct,
250 (u_char *) "application/x-javascript", 24)
251 != 0)
252 {
253 return ngx_http_next_header_filter(r); 268 return ngx_http_next_header_filter(r);
254 } 269 }
255 } 270 }
256 271
257 if (charset >= NGX_HTTP_CHARSET_VAR) { 272 if (charset >= NGX_HTTP_CHARSET_VAR) {
1442 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)); 1457 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t));
1443 if (lcf == NULL) { 1458 if (lcf == NULL) {
1444 return NGX_CONF_ERROR; 1459 return NGX_CONF_ERROR;
1445 } 1460 }
1446 1461
1462 /*
1463 * set by ngx_pcalloc():
1464 *
1465 * lcf->types = { NULL };
1466 * lcf->types_keys = NULL;
1467 */
1468
1447 lcf->charset = NGX_CONF_UNSET; 1469 lcf->charset = NGX_CONF_UNSET;
1448 lcf->source_charset = NGX_CONF_UNSET; 1470 lcf->source_charset = NGX_CONF_UNSET;
1449 lcf->override_charset = NGX_CONF_UNSET; 1471 lcf->override_charset = NGX_CONF_UNSET;
1450 1472
1451 return lcf; 1473 return lcf;
1498 return NGX_CONF_ERROR; 1520 return NGX_CONF_ERROR;
1499 } 1521 }
1500 1522
1501 recode->src = conf->source_charset; 1523 recode->src = conf->source_charset;
1502 recode->dst = conf->charset; 1524 recode->dst = conf->charset;
1525
1526 if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
1527 prev->types_keys, &prev->types,
1528 ngx_http_charset_default_types)
1529 != NGX_OK)
1530 {
1531 return NGX_CONF_ERROR;
1532 }
1503 1533
1504 return NGX_CONF_OK; 1534 return NGX_CONF_OK;
1505 } 1535 }
1506 1536
1507 1537