~ubuntu-branches/ubuntu/karmic/nginx/karmic

« back to all changes in this revision

Viewing changes to src/http/modules/ngx_http_charset_filter_module.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2009-05-31 18:38:56 UTC
  • mfrom: (1.1.11 upstream) (4.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090531183856-lkdgdzr9m731fz92
Tags: 0.7.59-1
* New upstream release, first in Debian for the 0.7 branch. Among other
  issues, it also fixes the problem with wildcard dns names used with SSL.
  (Closes: #515904)
* debian/watch: updated.
* debian/postinst: fixed a bashism. (Closes: #507913)
* debian/conf/nginx.conf: removed default_type. (Closes: #509390)
* debian/control: updated Standards-Version to 3.8.1, no changes needed.
* debian/NEWS.Debian: documented the issues with
  server_names_hash_bucket_size. (Closes: #524785)

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    ngx_int_t                   charset;
53
53
    ngx_int_t                   source_charset;
54
54
    ngx_flag_t                  override_charset;
 
55
 
 
56
    ngx_hash_t                  types;
 
57
    ngx_array_t                *types_keys;
55
58
} ngx_http_charset_loc_conf_t;
56
59
 
57
60
 
110
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/xml"),
 
119
    ngx_string("text/plain"),
 
120
    ngx_string("text/vnd.wap.wml"),
 
121
    ngx_string("application/x-javascript"),
 
122
    ngx_string("application/rss+xml"),
 
123
    ngx_null_string
 
124
};
 
125
 
 
126
 
113
127
static ngx_command_t  ngx_http_charset_filter_commands[] = {
114
128
 
115
129
    { ngx_string("charset"),
136
150
      offsetof(ngx_http_charset_loc_conf_t, override_charset),
137
151
      NULL },
138
152
 
 
153
    { ngx_string("charset_types"),
 
154
      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
 
155
      ngx_http_types_slot,
 
156
      NGX_HTTP_LOC_CONF_OFFSET,
 
157
      offsetof(ngx_http_charset_loc_conf_t, types_keys),
 
158
      &ngx_http_charset_default_types[0] },
 
159
 
139
160
    { ngx_string("charset_map"),
140
161
      NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2,
141
162
      ngx_http_charset_map_block,
185
206
static ngx_int_t
186
207
ngx_http_charset_header_filter(ngx_http_request_t *r)
187
208
{
188
 
    u_char                        *ct;
189
209
    ngx_int_t                      charset, source_charset;
190
210
    ngx_str_t                     *mc, *from, *to, s;
191
211
    ngx_uint_t                     n;
204
224
 
205
225
    if (r == r->main) {
206
226
 
207
 
        if (r->headers_out.content_encoding
 
227
        if (!r->ignore_content_encoding
 
228
            && r->headers_out.content_encoding
208
229
            && r->headers_out.content_encoding->value.len)
209
230
        {
210
231
            return ngx_http_next_header_filter(r);
243
264
                }
244
265
 
245
266
            } else {
246
 
                ct = r->headers_out.content_type.data;
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
 
                {
 
267
                if (ngx_http_test_content_type(r, &mlcf->types) == NULL) {
253
268
                    return ngx_http_next_header_filter(r);
254
269
                }
255
270
            }
527
542
                break;
528
543
            }
529
544
 
530
 
#if (NGX_HAVE_WRITE_ZEROCOPY)
531
 
            if (b->zerocopy_busy) {
532
 
                break;
533
 
            }
534
 
#endif
535
 
 
536
545
            ctx->busy = cl->next;
537
546
 
538
547
            if (b->tag != (ngx_buf_tag_t) &ngx_http_charset_filter_module) {
1413
1422
    }
1414
1423
 
1415
1424
    if (ngx_array_init(&mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t))
1416
 
        == NGX_ERROR)
 
1425
        != NGX_OK)
1417
1426
    {
1418
1427
        return NGX_CONF_ERROR;
1419
1428
    }
1420
1429
 
1421
1430
    if (ngx_array_init(&mcf->tables, cf->pool, 1,
1422
 
                       sizeof(ngx_http_charset_tables_t)) == NGX_ERROR)
 
1431
                       sizeof(ngx_http_charset_tables_t))
 
1432
        != NGX_OK)
1423
1433
    {
1424
1434
        return NGX_CONF_ERROR;
1425
1435
    }
1426
1436
 
1427
1437
    if (ngx_array_init(&mcf->recodes, cf->pool, 2,
1428
 
                       sizeof(ngx_http_charset_recode_t)) == NGX_ERROR)
 
1438
                       sizeof(ngx_http_charset_recode_t))
 
1439
        != NGX_OK)
1429
1440
    {
1430
1441
        return NGX_CONF_ERROR;
1431
1442
    }
1444
1455
        return NGX_CONF_ERROR;
1445
1456
    }
1446
1457
 
 
1458
    /*
 
1459
     * set by ngx_pcalloc():
 
1460
     *
 
1461
     *     lcf->types = { NULL };
 
1462
     *     lcf->types_keys = NULL;
 
1463
     */
 
1464
 
1447
1465
    lcf->charset = NGX_CONF_UNSET;
1448
1466
    lcf->source_charset = NGX_CONF_UNSET;
1449
1467
    lcf->override_charset = NGX_CONF_UNSET;
1462
1480
    ngx_http_charset_recode_t     *recode;
1463
1481
    ngx_http_charset_main_conf_t  *mcf;
1464
1482
 
 
1483
    if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
 
1484
                             prev->types_keys, &prev->types,
 
1485
                             ngx_http_charset_default_types)
 
1486
        != NGX_OK)
 
1487
    {
 
1488
        return NGX_CONF_ERROR;
 
1489
    }
 
1490
 
1465
1491
    ngx_conf_merge_value(conf->override_charset, prev->override_charset, 0);
1466
1492
    ngx_conf_merge_value(conf->charset, prev->charset, NGX_HTTP_NO_CHARSET);
1467
1493