Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_scgi_module.c @ 4659:f12d474f0d5e stable-1.2
Merge of r4612: proper subrequest handling in various modules.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 04 Jun 2012 10:27:00 +0000 |
parents | 834049edae24 |
children | adcd60233817 |
rev | line source |
---|---|
3637 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
3637 | 5 * Copyright (C) Manlio Perillo (manlio.perillo@gmail.com) |
6 */ | |
7 | |
8 | |
9 #include <ngx_config.h> | |
10 #include <ngx_core.h> | |
11 #include <ngx_http.h> | |
12 | |
13 | |
14 typedef struct { | |
15 ngx_http_upstream_conf_t upstream; | |
16 | |
17 ngx_array_t *flushes; | |
18 ngx_array_t *params_len; | |
19 ngx_array_t *params; | |
20 ngx_array_t *params_source; | |
21 | |
22 ngx_hash_t headers_hash; | |
23 ngx_uint_t header_params; | |
24 | |
25 ngx_array_t *scgi_lengths; | |
26 ngx_array_t *scgi_values; | |
27 | |
28 #if (NGX_HTTP_CACHE) | |
29 ngx_http_complex_value_t cache_key; | |
30 #endif | |
31 } ngx_http_scgi_loc_conf_t; | |
32 | |
33 | |
34 static ngx_int_t ngx_http_scgi_eval(ngx_http_request_t *r, | |
35 ngx_http_scgi_loc_conf_t *scf); | |
36 static ngx_int_t ngx_http_scgi_create_request(ngx_http_request_t *r); | |
37 static ngx_int_t ngx_http_scgi_reinit_request(ngx_http_request_t *r); | |
38 static ngx_int_t ngx_http_scgi_process_status_line(ngx_http_request_t *r); | |
39 static ngx_int_t ngx_http_scgi_process_header(ngx_http_request_t *r); | |
40 static void ngx_http_scgi_abort_request(ngx_http_request_t *r); | |
41 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc); | |
42 | |
43 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); | |
44 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, | |
45 void *child); | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
46 static ngx_int_t ngx_http_scgi_merge_params(ngx_conf_t *cf, |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
47 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_loc_conf_t *prev); |
3637 | 48 |
49 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
50 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, | |
51 void *conf); | |
52 | |
53 #if (NGX_HTTP_CACHE) | |
54 static ngx_int_t ngx_http_scgi_create_key(ngx_http_request_t *r); | |
55 static char *ngx_http_scgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, | |
56 void *conf); | |
57 static char *ngx_http_scgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, | |
58 void *conf); | |
59 #endif | |
60 | |
61 | |
62 static ngx_conf_bitmask_t ngx_http_scgi_next_upstream_masks[] = { | |
63 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, | |
64 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, | |
65 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, | |
66 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, | |
67 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, | |
68 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, | |
69 { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING }, | |
70 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, | |
71 { ngx_null_string, 0 } | |
72 }; | |
73 | |
74 | |
75 ngx_module_t ngx_http_scgi_module; | |
76 | |
77 | |
78 static ngx_command_t ngx_http_scgi_commands[] = { | |
79 | |
80 { ngx_string("scgi_pass"), | |
81 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, | |
82 ngx_http_scgi_pass, | |
83 NGX_HTTP_LOC_CONF_OFFSET, | |
84 0, | |
85 NULL }, | |
86 | |
87 { ngx_string("scgi_store"), | |
88 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
89 ngx_http_scgi_store, | |
90 NGX_HTTP_LOC_CONF_OFFSET, | |
91 0, | |
92 NULL }, | |
93 | |
94 { ngx_string("scgi_store_access"), | |
95 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123, | |
96 ngx_conf_set_access_slot, | |
97 NGX_HTTP_LOC_CONF_OFFSET, | |
98 offsetof(ngx_http_scgi_loc_conf_t, upstream.store_access), | |
99 NULL }, | |
100 | |
4157
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
101 { ngx_string("scgi_buffering"), |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
102 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
103 ngx_conf_set_flag_slot, |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
104 NGX_HTTP_LOC_CONF_OFFSET, |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
105 offsetof(ngx_http_scgi_loc_conf_t, upstream.buffering), |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
106 NULL }, |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
107 |
3637 | 108 { ngx_string("scgi_ignore_client_abort"), |
109 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
110 ngx_conf_set_flag_slot, | |
111 NGX_HTTP_LOC_CONF_OFFSET, | |
112 offsetof(ngx_http_scgi_loc_conf_t, upstream.ignore_client_abort), | |
113 NULL }, | |
114 | |
115 { ngx_string("scgi_bind"), | |
116 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
117 ngx_http_upstream_bind_set_slot, | |
118 NGX_HTTP_LOC_CONF_OFFSET, | |
119 offsetof(ngx_http_scgi_loc_conf_t, upstream.local), | |
120 NULL }, | |
121 | |
122 { ngx_string("scgi_connect_timeout"), | |
123 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
124 ngx_conf_set_msec_slot, | |
125 NGX_HTTP_LOC_CONF_OFFSET, | |
126 offsetof(ngx_http_scgi_loc_conf_t, upstream.connect_timeout), | |
127 NULL }, | |
128 | |
129 { ngx_string("scgi_send_timeout"), | |
130 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
131 ngx_conf_set_msec_slot, | |
132 NGX_HTTP_LOC_CONF_OFFSET, | |
133 offsetof(ngx_http_scgi_loc_conf_t, upstream.send_timeout), | |
134 NULL }, | |
135 | |
136 { ngx_string("scgi_buffer_size"), | |
137 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
138 ngx_conf_set_size_slot, | |
139 NGX_HTTP_LOC_CONF_OFFSET, | |
140 offsetof(ngx_http_scgi_loc_conf_t, upstream.buffer_size), | |
141 NULL }, | |
142 | |
143 { ngx_string("scgi_pass_request_headers"), | |
144 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
145 ngx_conf_set_flag_slot, | |
146 NGX_HTTP_LOC_CONF_OFFSET, | |
147 offsetof(ngx_http_scgi_loc_conf_t, upstream.pass_request_headers), | |
148 NULL }, | |
149 | |
150 { ngx_string("scgi_pass_request_body"), | |
151 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
152 ngx_conf_set_flag_slot, | |
153 NGX_HTTP_LOC_CONF_OFFSET, | |
154 offsetof(ngx_http_scgi_loc_conf_t, upstream.pass_request_body), | |
155 NULL }, | |
156 | |
157 { ngx_string("scgi_intercept_errors"), | |
158 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
159 ngx_conf_set_flag_slot, | |
160 NGX_HTTP_LOC_CONF_OFFSET, | |
161 offsetof(ngx_http_scgi_loc_conf_t, upstream.intercept_errors), | |
162 NULL }, | |
163 | |
164 { ngx_string("scgi_read_timeout"), | |
165 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
166 ngx_conf_set_msec_slot, | |
167 NGX_HTTP_LOC_CONF_OFFSET, | |
168 offsetof(ngx_http_scgi_loc_conf_t, upstream.read_timeout), | |
169 NULL }, | |
170 | |
171 { ngx_string("scgi_buffers"), | |
172 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
173 ngx_conf_set_bufs_slot, | |
174 NGX_HTTP_LOC_CONF_OFFSET, | |
175 offsetof(ngx_http_scgi_loc_conf_t, upstream.bufs), | |
176 NULL }, | |
177 | |
178 { ngx_string("scgi_busy_buffers_size"), | |
179 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
180 ngx_conf_set_size_slot, | |
181 NGX_HTTP_LOC_CONF_OFFSET, | |
182 offsetof(ngx_http_scgi_loc_conf_t, upstream.busy_buffers_size_conf), | |
183 NULL }, | |
184 | |
185 #if (NGX_HTTP_CACHE) | |
186 | |
187 { ngx_string("scgi_cache"), | |
3729 | 188 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
3637 | 189 ngx_http_scgi_cache, |
190 NGX_HTTP_LOC_CONF_OFFSET, | |
191 0, | |
192 NULL }, | |
193 | |
194 { ngx_string("scgi_cache_key"), | |
3729 | 195 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
3637 | 196 ngx_http_scgi_cache_key, |
197 NGX_HTTP_LOC_CONF_OFFSET, | |
198 0, | |
199 NULL }, | |
200 | |
201 { ngx_string("scgi_cache_path"), | |
202 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, | |
203 ngx_http_file_cache_set_slot, | |
204 0, | |
205 0, | |
206 &ngx_http_scgi_module }, | |
207 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
208 { ngx_string("scgi_cache_bypass"), |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
209 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
210 ngx_http_set_predicate_slot, |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
211 NGX_HTTP_LOC_CONF_OFFSET, |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
212 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_bypass), |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
213 NULL }, |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
214 |
3637 | 215 { ngx_string("scgi_no_cache"), |
216 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
3692
045ea40cbfe8
use ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3670
diff
changeset
|
217 ngx_http_set_predicate_slot, |
3637 | 218 NGX_HTTP_LOC_CONF_OFFSET, |
219 offsetof(ngx_http_scgi_loc_conf_t, upstream.no_cache), | |
220 NULL }, | |
221 | |
222 { ngx_string("scgi_cache_valid"), | |
223 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
224 ngx_http_file_cache_valid_set_slot, | |
225 NGX_HTTP_LOC_CONF_OFFSET, | |
226 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_valid), | |
227 NULL }, | |
228 | |
229 { ngx_string("scgi_cache_min_uses"), | |
230 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
231 ngx_conf_set_num_slot, | |
232 NGX_HTTP_LOC_CONF_OFFSET, | |
233 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_min_uses), | |
234 NULL }, | |
235 | |
236 { ngx_string("scgi_cache_use_stale"), | |
237 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
238 ngx_conf_set_bitmask_slot, | |
239 NGX_HTTP_LOC_CONF_OFFSET, | |
240 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_use_stale), | |
241 &ngx_http_scgi_next_upstream_masks }, | |
242 | |
243 { ngx_string("scgi_cache_methods"), | |
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
245 ngx_conf_set_bitmask_slot, | |
246 NGX_HTTP_LOC_CONF_OFFSET, | |
247 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_methods), | |
248 &ngx_http_upstream_cache_method_mask }, | |
249 | |
4386
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
250 { ngx_string("scgi_cache_lock"), |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
252 ngx_conf_set_flag_slot, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
253 NGX_HTTP_LOC_CONF_OFFSET, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
254 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_lock), |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
255 NULL }, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
256 |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
257 { ngx_string("scgi_cache_lock_timeout"), |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
259 ngx_conf_set_msec_slot, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
260 NGX_HTTP_LOC_CONF_OFFSET, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
261 offsetof(ngx_http_scgi_loc_conf_t, upstream.cache_lock_timeout), |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
262 NULL }, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
263 |
3637 | 264 #endif |
265 | |
266 { ngx_string("scgi_temp_path"), | |
267 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
268 ngx_conf_set_path_slot, | |
269 NGX_HTTP_LOC_CONF_OFFSET, | |
270 offsetof(ngx_http_scgi_loc_conf_t, upstream.temp_path), | |
271 NULL }, | |
272 | |
273 { ngx_string("scgi_max_temp_file_size"), | |
274 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
275 ngx_conf_set_size_slot, | |
276 NGX_HTTP_LOC_CONF_OFFSET, | |
277 offsetof(ngx_http_scgi_loc_conf_t, upstream.max_temp_file_size_conf), | |
278 NULL }, | |
279 | |
280 { ngx_string("scgi_temp_file_write_size"), | |
281 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
282 ngx_conf_set_size_slot, | |
283 NGX_HTTP_LOC_CONF_OFFSET, | |
284 offsetof(ngx_http_scgi_loc_conf_t, upstream.temp_file_write_size_conf), | |
285 NULL }, | |
286 | |
287 { ngx_string("scgi_next_upstream"), | |
288 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
289 ngx_conf_set_bitmask_slot, | |
290 NGX_HTTP_LOC_CONF_OFFSET, | |
291 offsetof(ngx_http_scgi_loc_conf_t, upstream.next_upstream), | |
292 &ngx_http_scgi_next_upstream_masks }, | |
293 | |
294 { ngx_string("scgi_param"), | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
295 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE23, |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
296 ngx_http_upstream_param_set_slot, |
3637 | 297 NGX_HTTP_LOC_CONF_OFFSET, |
298 offsetof(ngx_http_scgi_loc_conf_t, params_source), | |
299 NULL }, | |
300 | |
301 { ngx_string("scgi_pass_header"), | |
3729 | 302 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
3637 | 303 ngx_conf_set_str_array_slot, |
304 NGX_HTTP_LOC_CONF_OFFSET, | |
305 offsetof(ngx_http_scgi_loc_conf_t, upstream.pass_headers), | |
306 NULL }, | |
307 | |
308 { ngx_string("scgi_hide_header"), | |
3729 | 309 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
3637 | 310 ngx_conf_set_str_array_slot, |
311 NGX_HTTP_LOC_CONF_OFFSET, | |
312 offsetof(ngx_http_scgi_loc_conf_t, upstream.hide_headers), | |
313 NULL }, | |
314 | |
315 { ngx_string("scgi_ignore_headers"), | |
316 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
317 ngx_conf_set_bitmask_slot, | |
318 NGX_HTTP_LOC_CONF_OFFSET, | |
319 offsetof(ngx_http_scgi_loc_conf_t, upstream.ignore_headers), | |
3667
12bd9e26fadb
use shared ngx_http_upstream_ignore_headers_masks[]
Igor Sysoev <igor@sysoev.ru>
parents:
3637
diff
changeset
|
320 &ngx_http_upstream_ignore_headers_masks }, |
3637 | 321 |
322 ngx_null_command | |
323 }; | |
324 | |
325 | |
326 static ngx_http_module_t ngx_http_scgi_module_ctx = { | |
327 NULL, /* preconfiguration */ | |
328 NULL, /* postconfiguration */ | |
329 | |
330 NULL, /* create main configuration */ | |
331 NULL, /* init main configuration */ | |
332 | |
333 NULL, /* create server configuration */ | |
334 NULL, /* merge server configuration */ | |
335 | |
336 ngx_http_scgi_create_loc_conf, /* create location configuration */ | |
337 ngx_http_scgi_merge_loc_conf /* merge location configuration */ | |
338 }; | |
339 | |
340 | |
341 ngx_module_t ngx_http_scgi_module = { | |
342 NGX_MODULE_V1, | |
343 &ngx_http_scgi_module_ctx, /* module context */ | |
344 ngx_http_scgi_commands, /* module directives */ | |
345 NGX_HTTP_MODULE, /* module type */ | |
346 NULL, /* init master */ | |
347 NULL, /* init module */ | |
348 NULL, /* init process */ | |
349 NULL, /* init thread */ | |
350 NULL, /* exit thread */ | |
351 NULL, /* exit process */ | |
352 NULL, /* exit master */ | |
353 NGX_MODULE_V1_PADDING | |
354 }; | |
355 | |
356 | |
357 static ngx_str_t ngx_http_scgi_hide_headers[] = { | |
358 ngx_string("Status"), | |
359 ngx_string("X-Accel-Expires"), | |
360 ngx_string("X-Accel-Redirect"), | |
361 ngx_string("X-Accel-Limit-Rate"), | |
362 ngx_string("X-Accel-Buffering"), | |
363 ngx_string("X-Accel-Charset"), | |
364 ngx_null_string | |
365 }; | |
366 | |
367 | |
368 #if (NGX_HTTP_CACHE) | |
369 | |
370 static ngx_keyval_t ngx_http_scgi_cache_headers[] = { | |
371 { ngx_string("HTTP_IF_MODIFIED_SINCE"), ngx_string("") }, | |
372 { ngx_string("HTTP_IF_UNMODIFIED_SINCE"), ngx_string("") }, | |
373 { ngx_string("HTTP_IF_NONE_MATCH"), ngx_string("") }, | |
374 { ngx_string("HTTP_IF_MATCH"), ngx_string("") }, | |
375 { ngx_string("HTTP_RANGE"), ngx_string("") }, | |
376 { ngx_string("HTTP_IF_RANGE"), ngx_string("") }, | |
377 { ngx_null_string, ngx_null_string } | |
378 }; | |
379 | |
380 #endif | |
381 | |
382 | |
383 static ngx_path_init_t ngx_http_scgi_temp_path = { | |
384 ngx_string(NGX_HTTP_SCGI_TEMP_PATH), { 1, 2, 0 } | |
385 }; | |
386 | |
387 | |
388 static ngx_int_t | |
389 ngx_http_scgi_handler(ngx_http_request_t *r) | |
390 { | |
391 ngx_int_t rc; | |
392 ngx_http_status_t *status; | |
393 ngx_http_upstream_t *u; | |
394 ngx_http_scgi_loc_conf_t *scf; | |
395 | |
396 if (r->subrequest_in_memory) { | |
397 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
398 "ngx_http_scgi_module does not support " | |
399 "subrequests in memory"); | |
400 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
401 } | |
402 | |
403 if (ngx_http_upstream_create(r) != NGX_OK) { | |
404 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
405 } | |
406 | |
407 status = ngx_pcalloc(r->pool, sizeof(ngx_http_status_t)); | |
408 if (status == NULL) { | |
409 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
410 } | |
411 | |
412 ngx_http_set_ctx(r, status, ngx_http_scgi_module); | |
413 | |
414 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module); | |
415 | |
416 if (scf->scgi_lengths) { | |
417 if (ngx_http_scgi_eval(r, scf) != NGX_OK) { | |
418 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
419 } | |
420 } | |
421 | |
422 u = r->upstream; | |
423 | |
424 ngx_str_set(&u->schema, "scgi://"); | |
425 u->output.tag = (ngx_buf_tag_t) &ngx_http_scgi_module; | |
426 | |
427 u->conf = &scf->upstream; | |
428 | |
429 #if (NGX_HTTP_CACHE) | |
430 u->create_key = ngx_http_scgi_create_key; | |
431 #endif | |
432 u->create_request = ngx_http_scgi_create_request; | |
433 u->reinit_request = ngx_http_scgi_reinit_request; | |
434 u->process_header = ngx_http_scgi_process_status_line; | |
435 u->abort_request = ngx_http_scgi_abort_request; | |
436 u->finalize_request = ngx_http_scgi_finalize_request; | |
437 | |
4157
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
438 u->buffering = scf->upstream.buffering; |
3637 | 439 |
440 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t)); | |
441 if (u->pipe == NULL) { | |
442 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
443 } | |
444 | |
445 u->pipe->input_filter = ngx_event_pipe_copy_input_filter; | |
446 u->pipe->input_ctx = r; | |
447 | |
448 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); | |
449 | |
450 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
451 return rc; | |
452 } | |
453 | |
454 return NGX_DONE; | |
455 } | |
456 | |
457 | |
458 static ngx_int_t | |
459 ngx_http_scgi_eval(ngx_http_request_t *r, ngx_http_scgi_loc_conf_t * scf) | |
460 { | |
461 ngx_url_t url; | |
462 ngx_http_upstream_t *u; | |
463 | |
464 ngx_memzero(&url, sizeof(ngx_url_t)); | |
465 | |
466 if (ngx_http_script_run(r, &url.url, scf->scgi_lengths->elts, 0, | |
467 scf->scgi_values->elts) | |
468 == NULL) | |
469 { | |
470 return NGX_ERROR; | |
471 } | |
472 | |
473 url.no_resolve = 1; | |
474 | |
475 if (ngx_parse_url(r->pool, &url) != NGX_OK) { | |
476 if (url.err) { | |
477 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
478 "%s in upstream \"%V\"", url.err, &url.url); | |
479 } | |
480 | |
481 return NGX_ERROR; | |
482 } | |
483 | |
484 u = r->upstream; | |
485 | |
486 u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t)); | |
487 if (u->resolved == NULL) { | |
488 return NGX_ERROR; | |
489 } | |
490 | |
491 if (url.addrs && url.addrs[0].sockaddr) { | |
492 u->resolved->sockaddr = url.addrs[0].sockaddr; | |
493 u->resolved->socklen = url.addrs[0].socklen; | |
494 u->resolved->naddrs = 1; | |
495 u->resolved->host = url.addrs[0].name; | |
496 | |
497 } else { | |
498 u->resolved->host = url.host; | |
499 u->resolved->port = url.port; | |
3879
502a6b0acf3f
fix case when a host in fastcgi_pass, scgi_pass, and uwsgi_pass
Igor Sysoev <igor@sysoev.ru>
parents:
3731
diff
changeset
|
500 u->resolved->no_port = url.no_port; |
3637 | 501 } |
502 | |
503 return NGX_OK; | |
504 } | |
505 | |
506 | |
507 #if (NGX_HTTP_CACHE) | |
508 | |
509 static ngx_int_t | |
510 ngx_http_scgi_create_key(ngx_http_request_t *r) | |
511 { | |
512 ngx_str_t *key; | |
513 ngx_http_scgi_loc_conf_t *scf; | |
514 | |
515 key = ngx_array_push(&r->cache->keys); | |
516 if (key == NULL) { | |
517 return NGX_ERROR; | |
518 } | |
519 | |
520 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module); | |
521 | |
522 if (ngx_http_complex_value(r, &scf->cache_key, key) != NGX_OK) { | |
523 return NGX_ERROR; | |
524 } | |
525 | |
526 return NGX_OK; | |
527 } | |
528 | |
529 #endif | |
530 | |
531 | |
532 static ngx_int_t | |
533 ngx_http_scgi_create_request(ngx_http_request_t *r) | |
534 { | |
535 u_char ch, *key, *val, *lowcase_key; | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
536 size_t len, key_len, val_len, allocated; |
3637 | 537 ngx_buf_t *b; |
538 ngx_str_t *content_length; | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
539 ngx_uint_t i, n, hash, skip_empty, header_params; |
3637 | 540 ngx_chain_t *cl, *body; |
541 ngx_list_part_t *part; | |
542 ngx_table_elt_t *header, **ignored; | |
543 ngx_http_script_code_pt code; | |
544 ngx_http_script_engine_t e, le; | |
545 ngx_http_scgi_loc_conf_t *scf; | |
546 ngx_http_script_len_code_pt lcode; | |
547 static ngx_str_t zero = ngx_string("0"); | |
548 | |
549 content_length = r->headers_in.content_length ? | |
550 &r->headers_in.content_length->value : &zero; | |
551 | |
552 len = sizeof("CONTENT_LENGTH") + content_length->len + 1; | |
553 | |
554 header_params = 0; | |
555 ignored = NULL; | |
556 | |
557 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module); | |
558 | |
559 if (scf->params_len) { | |
560 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
561 | |
562 ngx_http_script_flush_no_cacheable_variables(r, scf->flushes); | |
563 le.flushed = 1; | |
564 | |
565 le.ip = scf->params_len->elts; | |
566 le.request = r; | |
567 | |
568 while (*(uintptr_t *) le.ip) { | |
569 | |
570 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
571 key_len = lcode(&le); |
3637 | 572 |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
573 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
574 skip_empty = lcode(&le); |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
575 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
576 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { |
3637 | 577 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
578 } | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
579 le.ip += sizeof(uintptr_t); |
4294
56cb2255735a
Fixed incorrect counting the length of headers in a SCGI request.
Valentin Bartenev <vbart@nginx.com>
parents:
4278
diff
changeset
|
580 |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
581 if (skip_empty && val_len == 0) { |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
582 continue; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
583 } |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
584 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
585 len += key_len + val_len + 1; |
3637 | 586 } |
587 } | |
588 | |
589 if (scf->upstream.pass_request_headers) { | |
590 | |
591 allocated = 0; | |
592 lowcase_key = NULL; | |
593 | |
594 if (scf->header_params) { | |
4015
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
595 n = 0; |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
596 part = &r->headers_in.headers.part; |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
597 |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
598 while (part) { |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
599 n += part->nelts; |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
600 part = part->next; |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
601 } |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
602 |
e0a435f5f504
Fix ignored headers handling in fastcgi/scgi/uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3976
diff
changeset
|
603 ignored = ngx_palloc(r->pool, n * sizeof(void *)); |
3637 | 604 if (ignored == NULL) { |
605 return NGX_ERROR; | |
606 } | |
607 } | |
608 | |
609 part = &r->headers_in.headers.part; | |
610 header = part->elts; | |
611 | |
612 for (i = 0; /* void */; i++) { | |
613 | |
614 if (i >= part->nelts) { | |
615 if (part->next == NULL) { | |
616 break; | |
617 } | |
618 | |
619 part = part->next; | |
620 header = part->elts; | |
621 i = 0; | |
622 } | |
623 | |
624 if (scf->header_params) { | |
625 if (allocated < header[i].key.len) { | |
626 allocated = header[i].key.len + 16; | |
627 lowcase_key = ngx_pnalloc(r->pool, allocated); | |
628 if (lowcase_key == NULL) { | |
629 return NGX_ERROR; | |
630 } | |
631 } | |
632 | |
633 hash = 0; | |
634 | |
635 for (n = 0; n < header[i].key.len; n++) { | |
636 ch = header[i].key.data[n]; | |
637 | |
638 if (ch >= 'A' && ch <= 'Z') { | |
639 ch |= 0x20; | |
640 | |
641 } else if (ch == '-') { | |
642 ch = '_'; | |
643 } | |
644 | |
645 hash = ngx_hash(hash, ch); | |
646 lowcase_key[n] = ch; | |
647 } | |
648 | |
649 if (ngx_hash_find(&scf->headers_hash, hash, lowcase_key, n)) { | |
650 ignored[header_params++] = &header[i]; | |
651 continue; | |
652 } | |
653 } | |
654 | |
655 len += sizeof("HTTP_") - 1 + header[i].key.len + 1 | |
656 + header[i].value.len + 1; | |
657 } | |
658 } | |
659 | |
660 /* netstring: "length:" + packet + "," */ | |
661 | |
662 b = ngx_create_temp_buf(r->pool, NGX_SIZE_T_LEN + 1 + len + 1); | |
663 if (b == NULL) { | |
664 return NGX_ERROR; | |
665 } | |
666 | |
667 cl = ngx_alloc_chain_link(r->pool); | |
668 if (cl == NULL) { | |
669 return NGX_ERROR; | |
670 } | |
671 | |
672 cl->buf = b; | |
673 | |
674 b->last = ngx_snprintf(b->last, | |
675 NGX_SIZE_T_LEN + 1 + sizeof("CONTENT_LENGTH") | |
676 + NGX_OFF_T_LEN + 1, | |
677 "%ui:CONTENT_LENGTH%Z%V%Z", | |
678 len, content_length); | |
679 | |
680 if (scf->params_len) { | |
681 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
682 | |
683 e.ip = scf->params->elts; | |
684 e.pos = b->last; | |
685 e.request = r; | |
686 e.flushed = 1; | |
687 | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
688 le.ip = scf->params_len->elts; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
689 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
690 while (*(uintptr_t *) le.ip) { |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
691 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
692 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
693 lcode(&le); /* key length */ |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
694 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
695 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
696 skip_empty = lcode(&le); |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
697 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
698 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
699 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
700 } |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
701 le.ip += sizeof(uintptr_t); |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
702 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
703 if (skip_empty && val_len == 0) { |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
704 e.skip = 1; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
705 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
706 while (*(uintptr_t *) e.ip) { |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
707 code = *(ngx_http_script_code_pt *) e.ip; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
708 code((ngx_http_script_engine_t *) &e); |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
709 } |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
710 e.ip += sizeof(uintptr_t); |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
711 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
712 e.skip = 0; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
713 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
714 continue; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
715 } |
3637 | 716 |
717 #if (NGX_DEBUG) | |
718 key = e.pos; | |
719 #endif | |
720 code = *(ngx_http_script_code_pt *) e.ip; | |
721 code((ngx_http_script_engine_t *) & e); | |
722 | |
723 #if (NGX_DEBUG) | |
724 val = e.pos; | |
725 #endif | |
726 while (*(uintptr_t *) e.ip) { | |
727 code = *(ngx_http_script_code_pt *) e.ip; | |
728 code((ngx_http_script_engine_t *) &e); | |
729 } | |
730 *e.pos++ = '\0'; | |
731 e.ip += sizeof(uintptr_t); | |
732 | |
733 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
734 "scgi param: \"%s: %s\"", key, val); | |
735 } | |
736 | |
737 b->last = e.pos; | |
738 } | |
739 | |
740 if (scf->upstream.pass_request_headers) { | |
741 | |
742 part = &r->headers_in.headers.part; | |
743 header = part->elts; | |
744 | |
745 for (i = 0; /* void */; i++) { | |
746 | |
747 if (i >= part->nelts) { | |
748 if (part->next == NULL) { | |
749 break; | |
750 } | |
751 | |
752 part = part->next; | |
753 header = part->elts; | |
754 i = 0; | |
755 } | |
756 | |
757 for (n = 0; n < header_params; n++) { | |
758 if (&header[i] == ignored[n]) { | |
759 goto next; | |
760 } | |
761 } | |
762 | |
763 key = b->last; | |
764 b->last = ngx_cpymem(key, "HTTP_", sizeof("HTTP_") - 1); | |
765 | |
766 for (n = 0; n < header[i].key.len; n++) { | |
767 ch = header[i].key.data[n]; | |
768 | |
769 if (ch >= 'a' && ch <= 'z') { | |
770 ch &= ~0x20; | |
771 | |
772 } else if (ch == '-') { | |
773 ch = '_'; | |
774 } | |
775 | |
776 *b->last++ = ch; | |
777 } | |
778 | |
779 *b->last++ = (u_char) 0; | |
780 | |
781 val = b->last; | |
782 b->last = ngx_copy(val, header[i].value.data, header[i].value.len); | |
783 *b->last++ = (u_char) 0; | |
784 | |
785 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
786 "scgi param: \"%s: %s\"", key, val); | |
787 | |
788 next: | |
789 | |
790 continue; | |
791 } | |
792 } | |
793 | |
794 *b->last++ = (u_char) ','; | |
795 | |
796 if (scf->upstream.pass_request_body) { | |
797 body = r->upstream->request_bufs; | |
798 r->upstream->request_bufs = cl; | |
799 | |
800 while (body) { | |
801 b = ngx_alloc_buf(r->pool); | |
802 if (b == NULL) { | |
803 return NGX_ERROR; | |
804 } | |
805 | |
806 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); | |
807 | |
808 cl->next = ngx_alloc_chain_link(r->pool); | |
809 if (cl->next == NULL) { | |
810 return NGX_ERROR; | |
811 } | |
812 | |
813 cl = cl->next; | |
814 cl->buf = b; | |
815 | |
816 body = body->next; | |
817 } | |
818 | |
819 } else { | |
820 r->upstream->request_bufs = cl; | |
821 } | |
822 | |
823 cl->next = NULL; | |
824 | |
825 return NGX_OK; | |
826 } | |
827 | |
828 | |
829 static ngx_int_t | |
830 ngx_http_scgi_reinit_request(ngx_http_request_t *r) | |
831 { | |
832 ngx_http_status_t *status; | |
833 | |
834 status = ngx_http_get_module_ctx(r, ngx_http_scgi_module); | |
835 | |
836 if (status == NULL) { | |
837 return NGX_OK; | |
838 } | |
839 | |
840 status->code = 0; | |
841 status->count = 0; | |
842 status->start = NULL; | |
843 status->end = NULL; | |
844 | |
845 r->upstream->process_header = ngx_http_scgi_process_status_line; | |
846 | |
847 return NGX_OK; | |
848 } | |
849 | |
850 | |
851 static ngx_int_t | |
852 ngx_http_scgi_process_status_line(ngx_http_request_t *r) | |
853 { | |
854 size_t len; | |
855 ngx_int_t rc; | |
856 ngx_http_status_t *status; | |
857 ngx_http_upstream_t *u; | |
858 | |
859 status = ngx_http_get_module_ctx(r, ngx_http_scgi_module); | |
860 | |
861 if (status == NULL) { | |
862 return NGX_ERROR; | |
863 } | |
864 | |
865 u = r->upstream; | |
866 | |
867 rc = ngx_http_parse_status_line(r, &u->buffer, status); | |
868 | |
869 if (rc == NGX_AGAIN) { | |
870 return rc; | |
871 } | |
872 | |
873 if (rc == NGX_ERROR) { | |
874 u->process_header = ngx_http_scgi_process_header; | |
875 return ngx_http_scgi_process_header(r); | |
876 } | |
877 | |
878 if (u->state) { | |
879 u->state->status = status->code; | |
880 } | |
881 | |
882 u->headers_in.status_n = status->code; | |
883 | |
884 len = status->end - status->start; | |
885 u->headers_in.status_line.len = len; | |
886 | |
887 u->headers_in.status_line.data = ngx_pnalloc(r->pool, len); | |
888 if (u->headers_in.status_line.data == NULL) { | |
889 return NGX_ERROR; | |
890 } | |
891 | |
892 ngx_memcpy(u->headers_in.status_line.data, status->start, len); | |
893 | |
894 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
895 "http scgi status %ui \"%V\"", | |
896 u->headers_in.status_n, &u->headers_in.status_line); | |
897 | |
898 u->process_header = ngx_http_scgi_process_header; | |
899 | |
900 return ngx_http_scgi_process_header(r); | |
901 } | |
902 | |
903 | |
904 static ngx_int_t | |
905 ngx_http_scgi_process_header(ngx_http_request_t *r) | |
906 { | |
907 ngx_str_t *status_line; | |
908 ngx_int_t rc, status; | |
909 ngx_table_elt_t *h; | |
910 ngx_http_upstream_t *u; | |
911 ngx_http_upstream_header_t *hh; | |
912 ngx_http_upstream_main_conf_t *umcf; | |
913 | |
914 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
915 | |
916 for ( ;; ) { | |
917 | |
918 rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1); | |
919 | |
920 if (rc == NGX_OK) { | |
921 | |
922 /* a header line has been parsed successfully */ | |
923 | |
924 h = ngx_list_push(&r->upstream->headers_in.headers); | |
925 if (h == NULL) { | |
926 return NGX_ERROR; | |
927 } | |
928 | |
929 h->hash = r->header_hash; | |
930 | |
931 h->key.len = r->header_name_end - r->header_name_start; | |
932 h->value.len = r->header_end - r->header_start; | |
933 | |
934 h->key.data = ngx_pnalloc(r->pool, | |
935 h->key.len + 1 + h->value.len + 1 | |
936 + h->key.len); | |
937 if (h->key.data == NULL) { | |
938 return NGX_ERROR; | |
939 } | |
940 | |
941 h->value.data = h->key.data + h->key.len + 1; | |
942 h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1; | |
943 | |
4529
1ebec1d15a25
Fixed incorrect ngx_cpystrn() usage in ngx_http_*_process_header().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4522
diff
changeset
|
944 ngx_memcpy(h->key.data, r->header_name_start, h->key.len); |
1ebec1d15a25
Fixed incorrect ngx_cpystrn() usage in ngx_http_*_process_header().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4522
diff
changeset
|
945 h->key.data[h->key.len] = '\0'; |
1ebec1d15a25
Fixed incorrect ngx_cpystrn() usage in ngx_http_*_process_header().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4522
diff
changeset
|
946 ngx_memcpy(h->value.data, r->header_start, h->value.len); |
1ebec1d15a25
Fixed incorrect ngx_cpystrn() usage in ngx_http_*_process_header().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4522
diff
changeset
|
947 h->value.data[h->value.len] = '\0'; |
3637 | 948 |
949 if (h->key.len == r->lowcase_index) { | |
950 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); | |
951 | |
952 } else { | |
953 ngx_strlow(h->lowcase_key, h->key.data, h->key.len); | |
954 } | |
955 | |
956 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, | |
957 h->lowcase_key, h->key.len); | |
958 | |
959 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) { | |
960 return NGX_ERROR; | |
961 } | |
962 | |
963 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
964 "http scgi header: \"%V: %V\"", &h->key, &h->value); | |
965 | |
966 continue; | |
967 } | |
968 | |
969 if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | |
970 | |
971 /* a whole header has been parsed successfully */ | |
972 | |
973 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
974 "http scgi header done"); | |
975 | |
4371
16ebad9447ee
Fixed incorrect use of r->http_version in scgi module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4331
diff
changeset
|
976 u = r->upstream; |
16ebad9447ee
Fixed incorrect use of r->http_version in scgi module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4331
diff
changeset
|
977 |
16ebad9447ee
Fixed incorrect use of r->http_version in scgi module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4331
diff
changeset
|
978 if (u->headers_in.status_n) { |
3637 | 979 return NGX_OK; |
980 } | |
981 | |
982 if (u->headers_in.status) { | |
983 status_line = &u->headers_in.status->value; | |
984 | |
985 status = ngx_atoi(status_line->data, 3); | |
986 if (status == NGX_ERROR) { | |
987 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
988 "upstream sent invalid status \"%V\"", | |
989 status_line); | |
990 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
991 } | |
992 | |
993 u->headers_in.status_n = status; | |
994 u->headers_in.status_line = *status_line; | |
995 | |
996 } else if (u->headers_in.location) { | |
997 u->headers_in.status_n = 302; | |
998 ngx_str_set(&u->headers_in.status_line, | |
999 "302 Moved Temporarily"); | |
1000 | |
1001 } else { | |
1002 u->headers_in.status_n = 200; | |
1003 ngx_str_set(&u->headers_in.status_line, "200 OK"); | |
1004 } | |
1005 | |
1006 if (u->state) { | |
1007 u->state->status = u->headers_in.status_n; | |
1008 } | |
1009 | |
1010 return NGX_OK; | |
1011 } | |
1012 | |
1013 if (rc == NGX_AGAIN) { | |
1014 return NGX_AGAIN; | |
1015 } | |
1016 | |
1017 /* there was error while a header line parsing */ | |
1018 | |
1019 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1020 "upstream sent invalid header"); | |
1021 | |
1022 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1023 } | |
1024 } | |
1025 | |
1026 | |
1027 static void | |
1028 ngx_http_scgi_abort_request(ngx_http_request_t *r) | |
1029 { | |
1030 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1031 "abort http scgi request"); | |
1032 | |
1033 return; | |
1034 } | |
1035 | |
1036 | |
1037 static void | |
1038 ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
1039 { | |
1040 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1041 "finalize http scgi request"); | |
1042 | |
1043 return; | |
1044 } | |
1045 | |
1046 | |
1047 static void * | |
1048 ngx_http_scgi_create_loc_conf(ngx_conf_t *cf) | |
1049 { | |
1050 ngx_http_scgi_loc_conf_t *conf; | |
1051 | |
1052 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_scgi_loc_conf_t)); | |
1053 if (conf == NULL) { | |
1054 return NULL; | |
1055 } | |
1056 | |
1057 conf->upstream.store = NGX_CONF_UNSET; | |
1058 conf->upstream.store_access = NGX_CONF_UNSET_UINT; | |
1059 conf->upstream.buffering = NGX_CONF_UNSET; | |
1060 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; | |
1061 | |
1062 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; | |
1063 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
1064 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
1065 | |
1066 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | |
1067 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; | |
1068 | |
1069 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | |
1070 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; | |
1071 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; | |
1072 | |
1073 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1074 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
1075 | |
1076 #if (NGX_HTTP_CACHE) | |
1077 conf->upstream.cache = NGX_CONF_UNSET_PTR; | |
1078 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT; | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
1079 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR; |
3693
e3bcc2f4c418
fix scgi_no_cache and uwsgi_no_cache initialization
Igor Sysoev <igor@sysoev.ru>
parents:
3692
diff
changeset
|
1080 conf->upstream.no_cache = NGX_CONF_UNSET_PTR; |
3637 | 1081 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR; |
4386
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1082 conf->upstream.cache_lock = NGX_CONF_UNSET; |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1083 conf->upstream.cache_lock_timeout = NGX_CONF_UNSET_MSEC; |
3637 | 1084 #endif |
1085 | |
1086 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR; | |
1087 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR; | |
1088 | |
1089 conf->upstream.intercept_errors = NGX_CONF_UNSET; | |
1090 | |
1091 /* "scgi_cyclic_temp_file" is disabled */ | |
1092 conf->upstream.cyclic_temp_file = 0; | |
1093 | |
4157
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
1094 conf->upstream.change_buffering = 1; |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
1095 |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
1096 ngx_str_set(&conf->upstream.module, "scgi"); |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
1097 |
3637 | 1098 return conf; |
1099 } | |
1100 | |
1101 | |
1102 static char * | |
1103 ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
1104 { | |
1105 ngx_http_scgi_loc_conf_t *prev = parent; | |
1106 ngx_http_scgi_loc_conf_t *conf = child; | |
1107 | |
1108 size_t size; | |
1109 ngx_hash_init_t hash; | |
3731
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1110 ngx_http_core_loc_conf_t *clcf; |
3637 | 1111 |
1112 if (conf->upstream.store != 0) { | |
1113 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); | |
1114 | |
1115 if (conf->upstream.store_lengths == NULL) { | |
1116 conf->upstream.store_lengths = prev->upstream.store_lengths; | |
1117 conf->upstream.store_values = prev->upstream.store_values; | |
1118 } | |
1119 } | |
1120 | |
1121 ngx_conf_merge_uint_value(conf->upstream.store_access, | |
1122 prev->upstream.store_access, 0600); | |
1123 | |
1124 ngx_conf_merge_value(conf->upstream.buffering, | |
1125 prev->upstream.buffering, 1); | |
1126 | |
1127 ngx_conf_merge_value(conf->upstream.ignore_client_abort, | |
1128 prev->upstream.ignore_client_abort, 0); | |
1129 | |
1130 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | |
1131 prev->upstream.connect_timeout, 60000); | |
1132 | |
1133 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1134 prev->upstream.send_timeout, 60000); | |
1135 | |
1136 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1137 prev->upstream.read_timeout, 60000); | |
1138 | |
1139 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1140 prev->upstream.send_lowat, 0); | |
1141 | |
1142 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
1143 prev->upstream.buffer_size, | |
1144 (size_t) ngx_pagesize); | |
1145 | |
1146 | |
1147 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1148 8, ngx_pagesize); | |
1149 | |
1150 if (conf->upstream.bufs.num < 2) { | |
1151 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1152 "there must be at least 2 \"scgi_buffers\""); | |
1153 return NGX_CONF_ERROR; | |
1154 } | |
1155 | |
1156 | |
1157 size = conf->upstream.buffer_size; | |
1158 if (size < conf->upstream.bufs.size) { | |
1159 size = conf->upstream.bufs.size; | |
1160 } | |
1161 | |
1162 | |
1163 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, | |
1164 prev->upstream.busy_buffers_size_conf, | |
1165 NGX_CONF_UNSET_SIZE); | |
1166 | |
1167 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { | |
1168 conf->upstream.busy_buffers_size = 2 * size; | |
1169 } else { | |
1170 conf->upstream.busy_buffers_size = | |
1171 conf->upstream.busy_buffers_size_conf; | |
1172 } | |
1173 | |
1174 if (conf->upstream.busy_buffers_size < size) { | |
1175 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4593
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4529
diff
changeset
|
1176 "\"scgi_busy_buffers_size\" must be equal to or greater " |
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4529
diff
changeset
|
1177 "than the maximum of the value of \"scgi_buffer_size\" and " |
3637 | 1178 "one of the \"scgi_buffers\""); |
1179 | |
1180 return NGX_CONF_ERROR; | |
1181 } | |
1182 | |
1183 if (conf->upstream.busy_buffers_size | |
1184 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
1185 { | |
1186 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1187 "\"scgi_busy_buffers_size\" must be less than " | |
1188 "the size of all \"scgi_buffers\" minus one buffer"); | |
1189 | |
1190 return NGX_CONF_ERROR; | |
1191 } | |
1192 | |
1193 | |
1194 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, | |
1195 prev->upstream.temp_file_write_size_conf, | |
1196 NGX_CONF_UNSET_SIZE); | |
1197 | |
1198 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { | |
1199 conf->upstream.temp_file_write_size = 2 * size; | |
1200 } else { | |
1201 conf->upstream.temp_file_write_size = | |
1202 conf->upstream.temp_file_write_size_conf; | |
1203 } | |
1204 | |
1205 if (conf->upstream.temp_file_write_size < size) { | |
1206 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4593
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4529
diff
changeset
|
1207 "\"scgi_temp_file_write_size\" must be equal to or greater than " |
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4529
diff
changeset
|
1208 "the maximum of the value of \"scgi_buffer_size\" and " |
3637 | 1209 "one of the \"scgi_buffers\""); |
1210 | |
1211 return NGX_CONF_ERROR; | |
1212 } | |
1213 | |
1214 | |
1215 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, | |
1216 prev->upstream.max_temp_file_size_conf, | |
1217 NGX_CONF_UNSET_SIZE); | |
1218 | |
1219 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { | |
1220 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; | |
1221 } else { | |
1222 conf->upstream.max_temp_file_size = | |
1223 conf->upstream.max_temp_file_size_conf; | |
1224 } | |
1225 | |
1226 if (conf->upstream.max_temp_file_size != 0 | |
1227 && conf->upstream.max_temp_file_size < size) { | |
1228 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1229 "\"scgi_max_temp_file_size\" must be equal to zero to disable " | |
4593
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4529
diff
changeset
|
1230 "temporary files usage or must be equal to or greater than " |
834049edae24
Fixed grammar in error messages.
Ruslan Ermilov <ru@nginx.com>
parents:
4529
diff
changeset
|
1231 "the maximum of the value of \"scgi_buffer_size\" and " |
3637 | 1232 "one of the \"scgi_buffers\""); |
1233 | |
1234 return NGX_CONF_ERROR; | |
1235 } | |
1236 | |
1237 | |
1238 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, | |
1239 prev->upstream.ignore_headers, | |
1240 NGX_CONF_BITMASK_SET); | |
1241 | |
1242 | |
1243 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
1244 prev->upstream.next_upstream, | |
1245 (NGX_CONF_BITMASK_SET | |
1246 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1247 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1248 | |
1249 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1250 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1251 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1252 } | |
1253 | |
1254 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path, | |
1255 prev->upstream.temp_path, | |
1256 &ngx_http_scgi_temp_path) | |
1257 != NGX_OK) | |
1258 { | |
1259 return NGX_CONF_ERROR; | |
1260 } | |
1261 | |
1262 #if (NGX_HTTP_CACHE) | |
1263 | |
1264 ngx_conf_merge_ptr_value(conf->upstream.cache, | |
1265 prev->upstream.cache, NULL); | |
1266 | |
1267 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { | |
1268 ngx_shm_zone_t *shm_zone; | |
1269 | |
1270 shm_zone = conf->upstream.cache; | |
1271 | |
1272 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1273 "\"scgi_cache\" zone \"%V\" is unknown", | |
1274 &shm_zone->shm.name); | |
1275 | |
1276 return NGX_CONF_ERROR; | |
1277 } | |
1278 | |
1279 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses, | |
1280 prev->upstream.cache_min_uses, 1); | |
1281 | |
1282 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale, | |
1283 prev->upstream.cache_use_stale, | |
1284 (NGX_CONF_BITMASK_SET | |
1285 |NGX_HTTP_UPSTREAM_FT_OFF)); | |
1286 | |
1287 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1288 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET | |
1289 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1290 } | |
1291 | |
4401
d45742815c90
Fixed proxy_cache_use_stale in "no live upstreams" case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4386
diff
changeset
|
1292 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_ERROR) { |
d45742815c90
Fixed proxy_cache_use_stale in "no live upstreams" case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4386
diff
changeset
|
1293 conf->upstream.cache_use_stale |= NGX_HTTP_UPSTREAM_FT_NOLIVE; |
d45742815c90
Fixed proxy_cache_use_stale in "no live upstreams" case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4386
diff
changeset
|
1294 } |
d45742815c90
Fixed proxy_cache_use_stale in "no live upstreams" case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4386
diff
changeset
|
1295 |
3637 | 1296 if (conf->upstream.cache_methods == 0) { |
1297 conf->upstream.cache_methods = prev->upstream.cache_methods; | |
1298 } | |
1299 | |
1300 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD; | |
1301 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
1302 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass, |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
1303 prev->upstream.cache_bypass, NULL); |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
1304 |
3637 | 1305 ngx_conf_merge_ptr_value(conf->upstream.no_cache, |
1306 prev->upstream.no_cache, NULL); | |
1307 | |
1308 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, | |
1309 prev->upstream.cache_valid, NULL); | |
1310 | |
1311 if (conf->cache_key.value.data == NULL) { | |
1312 conf->cache_key = prev->cache_key; | |
1313 } | |
1314 | |
4386
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1315 ngx_conf_merge_value(conf->upstream.cache_lock, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1316 prev->upstream.cache_lock, 0); |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1317 |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1318 ngx_conf_merge_msec_value(conf->upstream.cache_lock_timeout, |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1319 prev->upstream.cache_lock_timeout, 5000); |
92deb73393f7
Cache lock support for fastcgi, scgi, uwsgi.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4373
diff
changeset
|
1320 |
3637 | 1321 #endif |
1322 | |
1323 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1324 prev->upstream.pass_request_headers, 1); | |
1325 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1326 prev->upstream.pass_request_body, 1); | |
1327 | |
1328 ngx_conf_merge_value(conf->upstream.intercept_errors, | |
1329 prev->upstream.intercept_errors, 0); | |
1330 | |
1331 hash.max_size = 512; | |
1332 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
1333 hash.name = "scgi_hide_headers_hash"; | |
1334 | |
1335 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, | |
3670
2728c4e4a9ae
do not use a cache headers set to hide
Igor Sysoev <igor@sysoev.ru>
parents:
3668
diff
changeset
|
1336 &prev->upstream, ngx_http_scgi_hide_headers, &hash) |
3637 | 1337 != NGX_OK) |
1338 { | |
1339 return NGX_CONF_ERROR; | |
1340 } | |
1341 | |
1342 if (conf->upstream.upstream == NULL) { | |
1343 conf->upstream.upstream = prev->upstream.upstream; | |
1344 } | |
1345 | |
1346 if (conf->scgi_lengths == NULL) { | |
1347 conf->scgi_lengths = prev->scgi_lengths; | |
1348 conf->scgi_values = prev->scgi_values; | |
1349 } | |
1350 | |
3731
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1351 if (conf->upstream.upstream || conf->scgi_lengths) { |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1352 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1353 if (clcf->handler == NULL && clcf->lmt_excpt) { |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1354 clcf->handler = ngx_http_scgi_handler; |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1355 } |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1356 } |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1357 |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1358 if (ngx_http_scgi_merge_params(cf, conf, prev) != NGX_OK) { |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1359 return NGX_CONF_ERROR; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1360 } |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1361 |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1362 return NGX_CONF_OK; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1363 } |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1364 |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1365 |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1366 static ngx_int_t |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1367 ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf, |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1368 ngx_http_scgi_loc_conf_t *prev) |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1369 { |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1370 u_char *p; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1371 size_t size; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1372 uintptr_t *code; |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1373 ngx_uint_t i, nsrc; |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1374 ngx_array_t headers_names; |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1375 #if (NGX_HTTP_CACHE) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1376 ngx_array_t params_merged; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1377 #endif |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1378 ngx_hash_key_t *hk; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1379 ngx_hash_init_t hash; |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1380 ngx_http_upstream_param_t *src; |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1381 ngx_http_script_compile_t sc; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1382 ngx_http_script_copy_code_t *copy; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1383 |
3637 | 1384 if (conf->params_source == NULL) { |
1385 conf->params_source = prev->params_source; | |
1386 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1387 if (prev->headers_hash.buckets |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1388 #if (NGX_HTTP_CACHE) |
4522 | 1389 && ((conf->upstream.cache == NULL) |
1390 == (prev->upstream.cache == NULL)) | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1391 #endif |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1392 ) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1393 { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1394 conf->flushes = prev->flushes; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1395 conf->params_len = prev->params_len; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1396 conf->params = prev->params; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1397 conf->headers_hash = prev->headers_hash; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1398 conf->header_params = prev->header_params; |
3637 | 1399 |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1400 return NGX_OK; |
3637 | 1401 } |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1402 } |
3637 | 1403 |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1404 if (conf->params_source == NULL |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1405 #if (NGX_HTTP_CACHE) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1406 && (conf->upstream.cache == NULL) |
3637 | 1407 #endif |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1408 ) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1409 { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1410 conf->headers_hash.buckets = (void *) 1; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1411 return NGX_OK; |
3637 | 1412 } |
1413 | |
1414 conf->params_len = ngx_array_create(cf->pool, 64, 1); | |
1415 if (conf->params_len == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1416 return NGX_ERROR; |
3637 | 1417 } |
1418 | |
1419 conf->params = ngx_array_create(cf->pool, 512, 1); | |
1420 if (conf->params == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1421 return NGX_ERROR; |
3637 | 1422 } |
1423 | |
1424 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | |
1425 != NGX_OK) | |
1426 { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1427 return NGX_ERROR; |
3637 | 1428 } |
1429 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1430 if (conf->params_source) { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1431 src = conf->params_source->elts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1432 nsrc = conf->params_source->nelts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1433 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1434 } else { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1435 src = NULL; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1436 nsrc = 0; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1437 } |
3637 | 1438 |
1439 #if (NGX_HTTP_CACHE) | |
1440 | |
1441 if (conf->upstream.cache) { | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1442 ngx_keyval_t *h; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1443 ngx_http_upstream_param_t *s; |
3637 | 1444 |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1445 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1446 sizeof(ngx_http_upstream_param_t)) |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1447 != NGX_OK) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1448 { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1449 return NGX_ERROR; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1450 } |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1451 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1452 for (i = 0; i < nsrc; i++) { |
3637 | 1453 |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1454 s = ngx_array_push(¶ms_merged); |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1455 if (s == NULL) { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1456 return NGX_ERROR; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1457 } |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1458 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1459 *s = src[i]; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1460 } |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1461 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1462 h = ngx_http_scgi_cache_headers; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1463 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1464 while (h->key.len) { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1465 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1466 src = params_merged.elts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1467 nsrc = params_merged.nelts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1468 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1469 for (i = 0; i < nsrc; i++) { |
3637 | 1470 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { |
1471 goto next; | |
1472 } | |
1473 } | |
1474 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1475 s = ngx_array_push(¶ms_merged); |
3637 | 1476 if (s == NULL) { |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1477 return NGX_ERROR; |
3637 | 1478 } |
1479 | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1480 s->key = h->key; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1481 s->value = h->value; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1482 s->skip_empty = 0; |
3637 | 1483 |
1484 next: | |
1485 | |
1486 h++; | |
1487 } | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1488 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1489 src = params_merged.elts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1490 nsrc = params_merged.nelts; |
3637 | 1491 } |
1492 | |
1493 #endif | |
1494 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1495 for (i = 0; i < nsrc; i++) { |
3637 | 1496 |
1497 if (src[i].key.len > sizeof("HTTP_") - 1 | |
1498 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | |
1499 { | |
1500 hk = ngx_array_push(&headers_names); | |
1501 if (hk == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1502 return NGX_ERROR; |
3637 | 1503 } |
1504 | |
1505 hk->key.len = src[i].key.len - 5; | |
1506 hk->key.data = src[i].key.data + 5; | |
1507 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); | |
1508 hk->value = (void *) 1; | |
1509 | |
1510 if (src[i].value.len == 0) { | |
1511 continue; | |
1512 } | |
1513 } | |
1514 | |
1515 copy = ngx_array_push_n(conf->params_len, | |
1516 sizeof(ngx_http_script_copy_code_t)); | |
1517 if (copy == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1518 return NGX_ERROR; |
3637 | 1519 } |
1520 | |
1521 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | |
1522 copy->len = src[i].key.len + 1; | |
1523 | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1524 copy = ngx_array_push_n(conf->params_len, |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1525 sizeof(ngx_http_script_copy_code_t)); |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1526 if (copy == NULL) { |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1527 return NGX_ERROR; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1528 } |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1529 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1530 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1531 copy->len = src[i].skip_empty; |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1532 |
3637 | 1533 |
1534 size = (sizeof(ngx_http_script_copy_code_t) | |
1535 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) | |
1536 & ~(sizeof(uintptr_t) - 1); | |
1537 | |
1538 copy = ngx_array_push_n(conf->params, size); | |
1539 if (copy == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1540 return NGX_ERROR; |
3637 | 1541 } |
1542 | |
1543 copy->code = ngx_http_script_copy_code; | |
1544 copy->len = src[i].key.len + 1; | |
1545 | |
1546 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
1547 (void) ngx_cpystrn(p, src[i].key.data, src[i].key.len + 1); | |
1548 | |
1549 | |
1550 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1551 | |
1552 sc.cf = cf; | |
1553 sc.source = &src[i].value; | |
1554 sc.flushes = &conf->flushes; | |
1555 sc.lengths = &conf->params_len; | |
1556 sc.values = &conf->params; | |
1557 | |
1558 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1559 return NGX_ERROR; |
3637 | 1560 } |
1561 | |
1562 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
1563 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1564 return NGX_ERROR; |
3637 | 1565 } |
1566 | |
1567 *code = (uintptr_t) NULL; | |
1568 | |
1569 | |
1570 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | |
1571 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1572 return NGX_ERROR; |
3637 | 1573 } |
1574 | |
1575 *code = (uintptr_t) NULL; | |
1576 } | |
1577 | |
1578 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
1579 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1580 return NGX_ERROR; |
3637 | 1581 } |
1582 | |
1583 *code = (uintptr_t) NULL; | |
1584 | |
1585 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | |
1586 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1587 return NGX_ERROR; |
3637 | 1588 } |
1589 | |
1590 *code = (uintptr_t) NULL; | |
1591 | |
1592 conf->header_params = headers_names.nelts; | |
1593 | |
1594 hash.hash = &conf->headers_hash; | |
1595 hash.key = ngx_hash_key_lc; | |
1596 hash.max_size = 512; | |
1597 hash.bucket_size = 64; | |
1598 hash.name = "scgi_params_hash"; | |
1599 hash.pool = cf->pool; | |
1600 hash.temp_pool = NULL; | |
1601 | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1602 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts); |
3637 | 1603 } |
1604 | |
1605 | |
1606 static char * | |
1607 ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1608 { | |
1609 ngx_http_scgi_loc_conf_t *scf = conf; | |
1610 | |
1611 ngx_url_t u; | |
1612 ngx_str_t *value, *url; | |
1613 ngx_uint_t n; | |
1614 ngx_http_core_loc_conf_t *clcf; | |
1615 ngx_http_script_compile_t sc; | |
1616 | |
1617 if (scf->upstream.upstream || scf->scgi_lengths) { | |
1618 return "is duplicate"; | |
1619 } | |
1620 | |
1621 clcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module); | |
1622 clcf->handler = ngx_http_scgi_handler; | |
1623 | |
1624 value = cf->args->elts; | |
1625 | |
1626 url = &value[1]; | |
1627 | |
1628 n = ngx_http_script_variables_count(url); | |
1629 | |
1630 if (n) { | |
1631 | |
1632 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1633 | |
1634 sc.cf = cf; | |
1635 sc.source = url; | |
1636 sc.lengths = &scf->scgi_lengths; | |
1637 sc.values = &scf->scgi_values; | |
1638 sc.variables = n; | |
1639 sc.complete_lengths = 1; | |
1640 sc.complete_values = 1; | |
1641 | |
1642 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1643 return NGX_CONF_ERROR; | |
1644 } | |
1645 | |
1646 return NGX_CONF_OK; | |
1647 } | |
1648 | |
1649 ngx_memzero(&u, sizeof(ngx_url_t)); | |
1650 | |
1651 u.url = value[1]; | |
1652 u.no_resolve = 1; | |
1653 | |
1654 scf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); | |
1655 if (scf->upstream.upstream == NULL) { | |
1656 return NGX_CONF_ERROR; | |
1657 } | |
1658 | |
1659 if (clcf->name.data[clcf->name.len - 1] == '/') { | |
1660 clcf->auto_redirect = 1; | |
1661 } | |
1662 | |
1663 return NGX_CONF_OK; | |
1664 } | |
1665 | |
1666 | |
1667 static char * | |
1668 ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1669 { | |
1670 ngx_http_scgi_loc_conf_t *scf = conf; | |
1671 | |
1672 ngx_str_t *value; | |
1673 ngx_http_script_compile_t sc; | |
1674 | |
1675 if (scf->upstream.store != NGX_CONF_UNSET || scf->upstream.store_lengths) { | |
1676 return "is duplicate"; | |
1677 } | |
1678 | |
1679 value = cf->args->elts; | |
1680 | |
1681 if (ngx_strcmp(value[1].data, "off") == 0) { | |
1682 scf->upstream.store = 0; | |
1683 return NGX_CONF_OK; | |
1684 } | |
1685 | |
1686 #if (NGX_HTTP_CACHE) | |
1687 | |
1688 if (scf->upstream.cache != NGX_CONF_UNSET_PTR | |
1689 && scf->upstream.cache != NULL) | |
1690 { | |
1691 return "is incompatible with \"scgi_cache\""; | |
1692 } | |
1693 | |
1694 #endif | |
1695 | |
1696 if (ngx_strcmp(value[1].data, "on") == 0) { | |
1697 scf->upstream.store = 1; | |
1698 return NGX_CONF_OK; | |
1699 } | |
1700 | |
1701 /* include the terminating '\0' into script */ | |
1702 value[1].len++; | |
1703 | |
1704 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1705 | |
1706 sc.cf = cf; | |
1707 sc.source = &value[1]; | |
1708 sc.lengths = &scf->upstream.store_lengths; | |
1709 sc.values = &scf->upstream.store_values; | |
1710 sc.variables = ngx_http_script_variables_count(&value[1]);; | |
1711 sc.complete_lengths = 1; | |
1712 sc.complete_values = 1; | |
1713 | |
1714 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1715 return NGX_CONF_ERROR; | |
1716 } | |
1717 | |
1718 return NGX_CONF_OK; | |
1719 } | |
1720 | |
1721 | |
1722 #if (NGX_HTTP_CACHE) | |
1723 | |
1724 static char * | |
1725 ngx_http_scgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1726 { | |
1727 ngx_http_scgi_loc_conf_t *scf = conf; | |
1728 | |
1729 ngx_str_t *value; | |
1730 | |
1731 value = cf->args->elts; | |
1732 | |
1733 if (scf->upstream.cache != NGX_CONF_UNSET_PTR) { | |
1734 return "is duplicate"; | |
1735 } | |
1736 | |
1737 if (ngx_strcmp(value[1].data, "off") == 0) { | |
1738 scf->upstream.cache = NULL; | |
1739 return NGX_CONF_OK; | |
1740 } | |
1741 | |
1742 if (scf->upstream.store > 0 || scf->upstream.store_lengths) { | |
1743 return "is incompatible with \"scgi_store\""; | |
1744 } | |
1745 | |
1746 scf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0, | |
1747 &ngx_http_scgi_module); | |
1748 if (scf->upstream.cache == NULL) { | |
1749 return NGX_CONF_ERROR; | |
1750 } | |
1751 | |
1752 return NGX_CONF_OK; | |
1753 } | |
1754 | |
1755 | |
1756 static char * | |
1757 ngx_http_scgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1758 { | |
1759 ngx_http_scgi_loc_conf_t *scf = conf; | |
1760 | |
1761 ngx_str_t *value; | |
1762 ngx_http_compile_complex_value_t ccv; | |
1763 | |
1764 value = cf->args->elts; | |
1765 | |
1766 if (scf->cache_key.value.len) { | |
1767 return "is duplicate"; | |
1768 } | |
1769 | |
1770 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
1771 | |
1772 ccv.cf = cf; | |
1773 ccv.value = &value[1]; | |
1774 ccv.complex_value = &scf->cache_key; | |
1775 | |
1776 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
1777 return NGX_CONF_ERROR; | |
1778 } | |
1779 | |
1780 return NGX_CONF_OK; | |
1781 } | |
1782 | |
1783 #endif |