comparison src/http/modules/ngx_http_charset_filter.c @ 99:a059e1aa65d4

nginx-0.0.1-2003-06-02-19:24:30 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 02 Jun 2003 15:24:30 +0000
parents
children 152567c11325
comparison
equal deleted inserted replaced
98:c9b243802a17 99:a059e1aa65d4
1
2 #include <ngx_config.h>
3 #include <ngx_core.h>
4 #include <ngx_http.h>
5
6
7 typedef struct {
8 ngx_str_t default_charset;
9 } ngx_http_charset_loc_conf_t;
10
11
12 static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool);
13 static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool,
14 void *parent, void *child);
15 static int ngx_http_charset_filter_init(ngx_pool_t *pool);
16
17
18 static ngx_command_t ngx_http_charset_filter_commands[] = {
19
20 {ngx_string("default_charset"),
21 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
22 ngx_conf_set_str_slot,
23 NGX_HTTP_LOC_CONF_OFFSET,
24 offsetof(ngx_http_charset_loc_conf_t, default_charset),
25 NULL},
26
27 ngx_null_command
28 };
29
30
31 static ngx_http_module_t ngx_http_charset_filter_module_ctx = {
32 NULL, /* create main configuration */
33 NULL, /* init main configuration */
34
35 NULL, /* create server configuration */
36 NULL, /* merge server configuration */
37
38 ngx_http_charset_create_loc_conf, /* create location configuration */
39 ngx_http_charset_merge_loc_conf /* merge location configuration */
40 };
41
42
43 ngx_module_t ngx_http_charset_filter_module = {
44 NGX_MODULE,
45 &ngx_http_charset_filter_module_ctx, /* module context */
46 ngx_http_charset_filter_commands, /* module directives */
47 NGX_HTTP_MODULE, /* module type */
48 ngx_http_charset_filter_init /* init module */
49 };
50
51
52 static int (*next_header_filter) (ngx_http_request_t *r);
53 #if 0
54 static int (*next_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
55 #endif
56
57
58 static int ngx_http_charset_header_filter(ngx_http_request_t *r)
59 {
60 ngx_http_charset_loc_conf_t *lcf;
61
62 lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module);
63
64 if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY
65 && r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
66 {
67 /* do not set charset for the redirect because NN 4.x uses this
68 charset instead of the next page charset */
69 r->headers_out.charset.len = 0;
70
71 } else if (r->headers_out.charset.len == 0) {
72 r->headers_out.charset = lcf->default_charset;
73 }
74
75 return next_header_filter(r);
76 }
77
78
79 #if 0
80 static int ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
81 {
82 ngx_log_debug(r->connection->log, "CHARSET BODY");
83 return next_body_filter(r, in);
84 }
85 #endif
86
87
88 static int ngx_http_charset_filter_init(ngx_pool_t *pool)
89 {
90 next_header_filter = ngx_http_top_header_filter;
91 ngx_http_top_header_filter = ngx_http_charset_header_filter;
92
93 #if 0
94 next_body_filter = ngx_http_top_body_filter;
95 ngx_http_top_body_filter = ngx_http_charset_body_filter;
96 #endif
97
98 return NGX_OK;
99 }
100
101
102 static void *ngx_http_charset_create_loc_conf(ngx_pool_t *pool)
103 {
104 ngx_http_charset_loc_conf_t *lcf;
105
106 ngx_test_null(lcf,
107 ngx_pcalloc(pool, sizeof(ngx_http_charset_loc_conf_t)),
108 NGX_CONF_ERROR);
109
110 return lcf;
111 }
112
113
114 static char *ngx_http_charset_merge_loc_conf(ngx_pool_t *pool,
115 void *parent, void *child)
116 {
117 ngx_http_charset_loc_conf_t *prev = parent;
118 ngx_http_charset_loc_conf_t *conf = child;
119
120 ngx_conf_merge_str_value(conf->default_charset,
121 prev->default_charset, "koi8-r");
122
123 return NGX_CONF_OK;
124 }