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