annotate src/http/modules/ngx_http_sub_filter_module.c @ 1557:9d094e581587

*) add sub_filter parser fix similar to r1261 in SSI parser *) fix case when pattern is split between two buffers: it had been fixed in SSI parser long ago
author Igor Sysoev <igor@sysoev.ru>
date Tue, 02 Oct 2007 18:53:31 +0000
parents 76fe59c6fafb
children c10e7b563fb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1172
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 typedef struct {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 ngx_str_t match;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 ngx_str_t sub;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 ngx_array_t *types; /* array of ngx_str_t */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 ngx_array_t *sub_lengths;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 ngx_array_t *sub_values;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 ngx_flag_t once;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 } ngx_http_sub_loc_conf_t;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 typedef enum {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 sub_start_state = 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 sub_match_state,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 } ngx_http_sub_state_e;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 typedef struct {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 ngx_str_t match;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 ngx_uint_t once; /* unsigned once:1 */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 ngx_buf_t *buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 u_char *pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 u_char *copy_start;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 u_char *copy_end;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 ngx_chain_t *in;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 ngx_chain_t *out;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 ngx_chain_t **last_out;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 ngx_chain_t *busy;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 ngx_chain_t *free;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 ngx_str_t sub;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 ngx_uint_t state;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 size_t saved;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 size_t looked;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 } ngx_http_sub_ctx_t;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 static ngx_int_t ngx_http_sub_output(ngx_http_request_t *r,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 ngx_http_sub_ctx_t *ctx);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 ngx_http_sub_ctx_t *ctx);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 void *conf);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 static char *ngx_http_sub_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 static void *ngx_http_sub_create_conf(ngx_conf_t *cf);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 static char *ngx_http_sub_merge_conf(ngx_conf_t *cf,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 void *parent, void *child);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67 static ngx_int_t ngx_http_sub_filter_init(ngx_conf_t *cf);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 static ngx_command_t ngx_http_sub_filter_commands[] = {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 { ngx_string("sub_filter"),
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 ngx_http_sub_filter,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 NGX_HTTP_LOC_CONF_OFFSET,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 NULL },
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 { ngx_string("sub_filter_types"),
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 ngx_http_sub_types,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 NGX_HTTP_LOC_CONF_OFFSET,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 NULL },
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 { ngx_string("sub_filter_once"),
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 ngx_conf_set_flag_slot,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 NGX_HTTP_LOC_CONF_OFFSET,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 offsetof(ngx_http_sub_loc_conf_t, once),
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 NULL },
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 ngx_null_command
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 };
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 static ngx_http_module_t ngx_http_sub_filter_module_ctx = {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 NULL, /* preconfiguration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 ngx_http_sub_filter_init, /* postconfiguration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 NULL, /* create main configuration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 NULL, /* init main configuration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 NULL, /* create server configuration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105 NULL, /* merge server configuration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 ngx_http_sub_create_conf, /* create location configuration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 ngx_http_sub_merge_conf /* merge location configuration */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 };
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 ngx_module_t ngx_http_sub_filter_module = {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113 NGX_MODULE_V1,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 &ngx_http_sub_filter_module_ctx, /* module context */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 ngx_http_sub_filter_commands, /* module directives */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 NGX_HTTP_MODULE, /* module type */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117 NULL, /* init master */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 NULL, /* init module */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 NULL, /* init process */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 NULL, /* init thread */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 NULL, /* exit thread */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 NULL, /* exit process */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 NULL, /* exit master */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 NGX_MODULE_V1_PADDING
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 };
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 static ngx_int_t
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 ngx_http_sub_header_filter(ngx_http_request_t *r)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 ngx_str_t *type;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 ngx_uint_t i;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 ngx_http_sub_ctx_t *ctx;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 ngx_http_sub_loc_conf_t *slcf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 if (slcf->match.len == 0
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 || r->headers_out.content_type.len == 0
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 || r->headers_out.content_length_n == 0)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 return ngx_http_next_header_filter(r);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 type = slcf->types->elts;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 for (i = 0; i < slcf->types->nelts; i++) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 if (r->headers_out.content_type.len >= type[i].len
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 && ngx_strncasecmp(r->headers_out.content_type.data,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 type[i].data, type[i].len) == 0)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 goto found;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 return ngx_http_next_header_filter(r);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 found:
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_sub_ctx_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 if (ctx == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 ngx_http_set_ctx(r, ctx, ngx_http_sub_filter_module);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 ctx->match = slcf->match;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 ctx->last_out = &ctx->out;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172 ctx->sub = slcf->sub;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 r->filter_need_in_memory = 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 if (r == r->main) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 ngx_http_clear_content_length(r);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178 ngx_http_clear_last_modified(r);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 return ngx_http_next_header_filter(r);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 static ngx_int_t
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 ngx_int_t rc;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 ngx_buf_t *b;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 ngx_chain_t *cl;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 ngx_http_sub_ctx_t *ctx;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 ngx_http_sub_loc_conf_t *slcf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 ctx = ngx_http_get_module_ctx(r, ngx_http_sub_filter_module);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 if (ctx == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 return ngx_http_next_body_filter(r, in);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 if ((in == NULL
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201 && ctx->buf == NULL
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 && ctx->in == NULL
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 && ctx->busy == NULL))
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 return ngx_http_next_body_filter(r, in);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 if (ctx->once && (ctx->buf == NULL || ctx->in == NULL)) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 if (ctx->busy) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 if (ngx_http_sub_output(r, ctx) == NGX_ERROR) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 return ngx_http_next_body_filter(r, in);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 /* add the incoming chain to the chain ctx->in */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 if (in) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 if (ngx_chain_add_copy(r->pool, &ctx->in, in) == NGX_ERROR) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 "http sub filter \"%V\"", &r->uri);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 while (ctx->in || ctx->buf) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232 if (ctx->buf == NULL ){
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 ctx->buf = ctx->in->buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 ctx->in = ctx->in->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 ctx->pos = ctx->buf->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 if (ctx->state == sub_start_state) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 ctx->copy_start = ctx->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 ctx->copy_end = ctx->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 b = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245 while (ctx->pos < ctx->buf->last) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 "saved: %d state: %d", ctx->saved, ctx->state);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250 rc = ngx_http_sub_parse(r, ctx);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
251
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253 "parse: %d, looked: %d %p-%p",
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 rc, ctx->looked, ctx->copy_start, ctx->copy_end);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 if (rc == NGX_ERROR) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257 return rc;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 if (ctx->copy_start != ctx->copy_end) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263 "saved: %d", ctx->saved);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265 if (ctx->saved) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
267 if (ctx->free) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268 cl = ctx->free;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 ctx->free = ctx->free->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270 b = cl->buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
271 ngx_memzero(b, sizeof(ngx_buf_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 b = ngx_calloc_buf(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275 if (b == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
277 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
278
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
279 cl = ngx_alloc_chain_link(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280 if (cl == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
281 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
282 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
283
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
284 cl->buf = b;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
285 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
287 b->memory = 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
288 b->pos = ctx->match.data;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
289 b->last = ctx->match.data + ctx->saved;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
291 *ctx->last_out = cl;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
292 ctx->last_out = &cl->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
293
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
294 ctx->saved = 0;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
295 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
296
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
297 if (ctx->free) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
298 cl = ctx->free;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
299 ctx->free = ctx->free->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
300 b = cl->buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
301
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
303 b = ngx_alloc_buf(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
304 if (b == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
305 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
306 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
307
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
308 cl = ngx_alloc_chain_link(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
309 if (cl == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
310 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
311 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
312
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
313 cl->buf = b;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
314 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
315
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
316 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
317
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
318 b->pos = ctx->copy_start;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319 b->last = ctx->copy_end;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 b->shadow = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
321 b->last_buf = 0;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322 b->recycled = 0;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 if (b->in_file) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325 b->file_last = b->file_pos + (b->last - b->start);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326 b->file_pos += b->pos - b->start;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
328
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329 cl->next = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330 *ctx->last_out = cl;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331 ctx->last_out = &cl->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
333
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334 if (ctx->state == sub_start_state) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
335 ctx->copy_start = ctx->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
336 ctx->copy_end = ctx->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339 ctx->copy_start = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
340 ctx->copy_end = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343 if (rc == NGX_AGAIN) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344 continue;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
348 /* rc == NGX_OK */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
349
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350 b = ngx_calloc_buf(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351 if (b == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355 cl = ngx_alloc_chain_link(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 if (cl == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
359
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
360 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362 if (ctx->sub.data == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
364 if (ngx_http_script_run(r, &ctx->sub, slcf->sub_lengths->elts,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
365 0, slcf->sub_values->elts)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366 == NULL)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
370 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371
1555
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
372 if (ctx->sub.len) {
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
373 b->memory = 1;
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
374 b->pos = ctx->sub.data;
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
375 b->last = ctx->sub.data + ctx->sub.len;
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
376
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
377 } else {
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
378 b->sync = 1;
76fe59c6fafb fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents: 1172
diff changeset
379 }
1172
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381 cl->buf = b;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382 cl->next = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 *ctx->last_out = cl;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384 ctx->last_out = &cl->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386 ctx->once = slcf->once;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
388 continue;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
391 if (ctx->buf->last_buf || ngx_buf_in_memory(ctx->buf)) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
392 if (b == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
393 if (ctx->free) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394 cl = ctx->free;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
395 ctx->free = ctx->free->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
396 b = cl->buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
397 ngx_memzero(b, sizeof(ngx_buf_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
399 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
400 b = ngx_calloc_buf(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401 if (b == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
403 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
404
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405 cl = ngx_alloc_chain_link(r->pool);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
406 if (cl == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
407 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
408 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
409
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 cl->buf = b;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
412
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
413 b->sync = 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
414
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
415 cl->next = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
416 *ctx->last_out = cl;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417 ctx->last_out = &cl->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
418 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
419
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
420 b->last_buf = ctx->buf->last_buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
421 b->shadow = ctx->buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423 b->recycled = ctx->buf->recycled;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
424 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
425
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
426 ctx->buf = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
427
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
428 ctx->saved = ctx->looked;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
429 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
430
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
431 if (ctx->out == NULL && ctx->busy == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432 return NGX_OK;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
435 return ngx_http_sub_output(r, ctx);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
438
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
439 static ngx_int_t
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
440 ngx_http_sub_output(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442 ngx_int_t rc;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
443 ngx_buf_t *b;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
444 ngx_chain_t *cl;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446 #if 1
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 b = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
448 for (cl = ctx->out; cl; cl = cl->next) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
449 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
450 "sub out: %p %p", cl->buf, cl->buf->pos);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
451 if (cl->buf == b) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
452 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
453 "the same buf was used in sub");
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
454 ngx_debug_point();
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
455 return NGX_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457 b = cl->buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
459 #endif
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461 rc = ngx_http_next_body_filter(r, ctx->out);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
462
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
463 if (ctx->busy == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464 ctx->busy = ctx->out;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
465
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
468 cl->next = ctx->out;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
469 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471 ctx->out = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472 ctx->last_out = &ctx->out;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
474 while (ctx->busy) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
475
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
476 cl = ctx->busy;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
477 b = cl->buf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479 if (ngx_buf_size(b) != 0) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
480 break;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
481 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
482
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
483 #if (NGX_HAVE_WRITE_ZEROCOPY)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
484 if (b->zerocopy_busy) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485 break;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
486 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
487 #endif
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
488
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
489 if (b->shadow) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
490 b->shadow->pos = b->shadow->last;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
491 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
492
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
493 ctx->busy = cl->next;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
494
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495 if (ngx_buf_in_memory(b) || b->in_file) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
496 /* add data bufs only to the free buf chain */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
497
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
498 cl->next = ctx->free;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
499 ctx->free = cl;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
500 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
501 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
502
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
503 if (ctx->in || ctx->buf) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
504 r->buffered |= NGX_HTTP_SUB_BUFFERED;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
505
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
506 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
507 r->buffered &= ~NGX_HTTP_SUB_BUFFERED;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
508 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
509
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
510 return rc;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514 static ngx_int_t
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
515 ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
517 u_char *p, *last, *copy_end, ch, match;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
518 size_t looked;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
519 ngx_http_sub_state_e state;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
520
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
521 if (ctx->once) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
522 ctx->copy_start = ctx->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
523 ctx->copy_end = ctx->buf->last;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
524 ctx->pos = ctx->buf->last;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
525 ctx->looked = 0;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
526
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "once");
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
528
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
529 return NGX_AGAIN;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
530 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
531
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
532 state = ctx->state;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533 looked = ctx->looked;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534 last = ctx->buf->last;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
535 copy_end = ctx->copy_end;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
536
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
537 for (p = ctx->pos; p < last; p++) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
538
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
539 ch = *p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
540 ch = ngx_tolower(ch);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
541
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
542 if (state == sub_start_state) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
543
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
544 /* the tight loop */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
545
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
546 match = ctx->match.data[0];
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
547
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
548 for ( ;; ) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
549 if (ch == match) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
550 copy_end = p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
551 looked = 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
552 state = sub_match_state;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
553
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
554 goto match_started;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
555 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
556
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
557 if (++p == last) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
558 break;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
559 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
560
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
561 ch = *p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
562 ch = ngx_tolower(ch);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
563 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
564
1557
9d094e581587 *) add sub_filter parser fix similar to r1261 in SSI parser
Igor Sysoev <igor@sysoev.ru>
parents: 1555
diff changeset
565 ctx->state = state;
1172
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
566 ctx->pos = p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
567 ctx->looked = looked;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
568 ctx->copy_end = p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
569
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
570 if (ctx->copy_start == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
571 ctx->copy_start = ctx->buf->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
572 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
573
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
574 return NGX_AGAIN;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
575
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
576 match_started:
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578 continue;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
580
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
581 /* state == sub_match_state */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
582
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
583 if (ch == ctx->match.data[looked]) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584 looked++;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
585
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
586 if (looked == ctx->match.len) {
1557
9d094e581587 *) add sub_filter parser fix similar to r1261 in SSI parser
Igor Sysoev <igor@sysoev.ru>
parents: 1555
diff changeset
587 if ((size_t) (p - ctx->pos) < looked) {
9d094e581587 *) add sub_filter parser fix similar to r1261 in SSI parser
Igor Sysoev <igor@sysoev.ru>
parents: 1555
diff changeset
588 ctx->saved = 0;
9d094e581587 *) add sub_filter parser fix similar to r1261 in SSI parser
Igor Sysoev <igor@sysoev.ru>
parents: 1555
diff changeset
589 }
9d094e581587 *) add sub_filter parser fix similar to r1261 in SSI parser
Igor Sysoev <igor@sysoev.ru>
parents: 1555
diff changeset
590
1172
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
591 ctx->state = sub_start_state;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
592 ctx->pos = p + 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
593 ctx->looked = looked;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
594 ctx->copy_end = copy_end;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
595
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
596 if (ctx->copy_start == NULL && copy_end) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
597 ctx->copy_start = ctx->buf->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
598 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
599
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600 return NGX_OK;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
601 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
602
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
603 } else if (ch == ctx->match.data[0]) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604 copy_end = p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
605 looked = 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
606
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
607 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
608 copy_end = p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
609 looked = 0;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610 state = sub_start_state;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
613
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
614 ctx->state = state;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
615 ctx->pos = p;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616 ctx->looked = looked;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
617
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
618 ctx->copy_end = (state == sub_start_state) ? p : copy_end;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
620 if (ctx->copy_start == NULL && ctx->copy_end) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
621 ctx->copy_start = ctx->buf->pos;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
622 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
623
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
624 return NGX_AGAIN;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
625 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
627
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
628 static char *
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629 ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
630 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
631 ngx_http_sub_loc_conf_t *slcf = conf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
632
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
633 ngx_str_t *value;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
634 ngx_int_t n;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635 ngx_uint_t i;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 ngx_http_script_compile_t sc;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
638 if (slcf->match.len) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639 return "is duplicate";
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
640 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
642 value = cf->args->elts;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
643
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 slcf->match = value[1];
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
646 for (i = 0; i < value[1].len; i++) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
647 value[1].data[i] = ngx_tolower(value[1].data[i]);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
648 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
650 n = ngx_http_script_variables_count(&value[2]);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
652 if (n == 0) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
653 slcf->sub = value[2];
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
654 return NGX_CONF_OK;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
658
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
659 sc.cf = cf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
660 sc.source = &value[2];
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661 sc.lengths = &slcf->sub_lengths;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
662 sc.values = &slcf->sub_values;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
663 sc.variables = n;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
664 sc.complete_lengths = 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
665 sc.complete_values = 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
666
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667 if (ngx_http_script_compile(&sc) != NGX_OK) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
669 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671 return NGX_CONF_OK;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
673
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675 static char *
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676 ngx_http_sub_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
678 ngx_http_sub_loc_conf_t *slcf = conf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
679
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
680 ngx_str_t *value, *type;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681 ngx_uint_t i;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
682
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
683 if (slcf->types == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
684 slcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
685 if (slcf->types == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
686 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
687 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
688
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
689 type = ngx_array_push(slcf->types);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
690 if (type == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
691 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
692 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
693
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
694 type->len = sizeof("text/html") - 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695 type->data = (u_char *) "text/html";
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
697
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
698 value = cf->args->elts;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
699
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
700 for (i = 1; i < cf->args->nelts; i++) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
701
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
702 if (ngx_strcmp(value[i].data, "text/html") == 0) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
703 continue;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
705
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
706 type = ngx_array_push(slcf->types);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707 if (type == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
708 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
709 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
711 type->len = value[i].len;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
712
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
713 type->data = ngx_palloc(cf->pool, type->len + 1);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
714 if (type->data == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
715 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
716 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
717
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718 ngx_cpystrn(type->data, value[i].data, type->len + 1);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
719 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
720
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721 return NGX_CONF_OK;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
722 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
723
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
724
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
725 static void *
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
726 ngx_http_sub_create_conf(ngx_conf_t *cf)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
727 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
728 ngx_http_sub_loc_conf_t *slcf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
729
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
730 slcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_sub_loc_conf_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
731 if (slcf == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
732 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
733 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
734
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
735 /*
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
736 * set by ngx_pcalloc():
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
737 *
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 * conf->match.len = 0;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
739 * conf->match.data = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740 * conf->sub.len = 0;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741 * conf->sub.data = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742 * conf->sub_lengths = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743 * conf->sub_values = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 * conf->types = NULL;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
745 */
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
746
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
747 slcf->once = NGX_CONF_UNSET;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
748
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
749 return slcf;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
750 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
751
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
752
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
753 static char *
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
754 ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
755 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756 ngx_http_sub_loc_conf_t *prev = parent;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
757 ngx_http_sub_loc_conf_t *conf = child;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
758
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
759 ngx_str_t *type;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
760
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
761 ngx_conf_merge_value(conf->once, prev->once, 1);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
762 ngx_conf_merge_str_value(conf->match, prev->match, "");
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
763
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
764 if (conf->sub.data == NULL && conf->sub_lengths == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
765 conf->sub = prev->sub;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
766 conf->sub_lengths = prev->sub_lengths;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
767 conf->sub_values = prev->sub_values;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
768 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
769
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
770 if (conf->types == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
771 if (prev->types == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
772 conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t));
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
773 if (conf->types == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
774 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
775 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
776
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
777 type = ngx_array_push(conf->types);
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
778 if (type == NULL) {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
779 return NGX_CONF_ERROR;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
780 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
781
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
782 type->len = sizeof("text/html") - 1;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
783 type->data = (u_char *) "text/html";
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
784
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
785 } else {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
786 conf->types = prev->types;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
787 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
788 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
789
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
790 return NGX_CONF_OK;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
791 }
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
792
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
793
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
794 static ngx_int_t
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
795 ngx_http_sub_filter_init(ngx_conf_t *cf)
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
796 {
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
797 ngx_http_next_header_filter = ngx_http_top_header_filter;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
798 ngx_http_top_header_filter = ngx_http_sub_header_filter;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
799
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
800 ngx_http_next_body_filter = ngx_http_top_body_filter;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
801 ngx_http_top_body_filter = ngx_http_sub_body_filter;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
802
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
803 return NGX_OK;
383ae25c3171 ngx_http_sub_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
804 }