Mercurial > hg > nginx
annotate src/http/modules/ngx_http_scgi_module.c @ 4373:f41b79fa95a3
Scgi: removed error if there is no Status header.
The SCGI specification doesn't specify format of the response, and assuming
CGI specs should be used there is no reason to complain. RFC 3875
explicitly states that "A Status header field is optional, and status
200 'OK' is assumed if it is omitted".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 19 Dec 2011 11:25:40 +0000 |
parents | b228587a6494 |
children | 92deb73393f7 |
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 u->headers_in.status_n = 200; | |
986 ngx_str_set(&u->headers_in.status_line, "200 OK"); | |
987 } | |
988 | |
989 if (u->state) { | |
990 u->state->status = u->headers_in.status_n; | |
991 } | |
992 | |
993 return NGX_OK; | |
994 } | |
995 | |
996 if (rc == NGX_AGAIN) { | |
997 return NGX_AGAIN; | |
998 } | |
999 | |
1000 /* there was error while a header line parsing */ | |
1001 | |
1002 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1003 "upstream sent invalid header"); | |
1004 | |
1005 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1006 } | |
1007 } | |
1008 | |
1009 | |
1010 static void | |
1011 ngx_http_scgi_abort_request(ngx_http_request_t *r) | |
1012 { | |
1013 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1014 "abort http scgi request"); | |
1015 | |
1016 return; | |
1017 } | |
1018 | |
1019 | |
1020 static void | |
1021 ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
1022 { | |
1023 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1024 "finalize http scgi request"); | |
1025 | |
1026 return; | |
1027 } | |
1028 | |
1029 | |
1030 static void * | |
1031 ngx_http_scgi_create_loc_conf(ngx_conf_t *cf) | |
1032 { | |
1033 ngx_http_scgi_loc_conf_t *conf; | |
1034 | |
1035 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_scgi_loc_conf_t)); | |
1036 if (conf == NULL) { | |
1037 return NULL; | |
1038 } | |
1039 | |
1040 conf->upstream.store = NGX_CONF_UNSET; | |
1041 conf->upstream.store_access = NGX_CONF_UNSET_UINT; | |
1042 conf->upstream.buffering = NGX_CONF_UNSET; | |
1043 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; | |
1044 | |
1045 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; | |
1046 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
1047 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
1048 | |
1049 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | |
1050 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; | |
1051 | |
1052 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | |
1053 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; | |
1054 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; | |
1055 | |
1056 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1057 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
1058 | |
1059 #if (NGX_HTTP_CACHE) | |
1060 conf->upstream.cache = NGX_CONF_UNSET_PTR; | |
1061 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
|
1062 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
|
1063 conf->upstream.no_cache = NGX_CONF_UNSET_PTR; |
3637 | 1064 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR; |
1065 #endif | |
1066 | |
1067 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR; | |
1068 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR; | |
1069 | |
1070 conf->upstream.intercept_errors = NGX_CONF_UNSET; | |
1071 | |
1072 /* "scgi_cyclic_temp_file" is disabled */ | |
1073 conf->upstream.cyclic_temp_file = 0; | |
1074 | |
4157
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
1075 conf->upstream.change_buffering = 1; |
9d59a8eda373
Added uwsgi_buffering and scgi_buffering directives.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4015
diff
changeset
|
1076 |
3976
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
1077 ngx_str_set(&conf->upstream.module, "scgi"); |
215fe9223419
update r3945 with more descriptive error message
Igor Sysoev <igor@sysoev.ru>
parents:
3879
diff
changeset
|
1078 |
3637 | 1079 return conf; |
1080 } | |
1081 | |
1082 | |
1083 static char * | |
1084 ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
1085 { | |
1086 ngx_http_scgi_loc_conf_t *prev = parent; | |
1087 ngx_http_scgi_loc_conf_t *conf = child; | |
1088 | |
1089 size_t size; | |
1090 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
|
1091 ngx_http_core_loc_conf_t *clcf; |
3637 | 1092 |
1093 if (conf->upstream.store != 0) { | |
1094 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); | |
1095 | |
1096 if (conf->upstream.store_lengths == NULL) { | |
1097 conf->upstream.store_lengths = prev->upstream.store_lengths; | |
1098 conf->upstream.store_values = prev->upstream.store_values; | |
1099 } | |
1100 } | |
1101 | |
1102 ngx_conf_merge_uint_value(conf->upstream.store_access, | |
1103 prev->upstream.store_access, 0600); | |
1104 | |
1105 ngx_conf_merge_value(conf->upstream.buffering, | |
1106 prev->upstream.buffering, 1); | |
1107 | |
1108 ngx_conf_merge_value(conf->upstream.ignore_client_abort, | |
1109 prev->upstream.ignore_client_abort, 0); | |
1110 | |
1111 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | |
1112 prev->upstream.connect_timeout, 60000); | |
1113 | |
1114 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1115 prev->upstream.send_timeout, 60000); | |
1116 | |
1117 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1118 prev->upstream.read_timeout, 60000); | |
1119 | |
1120 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1121 prev->upstream.send_lowat, 0); | |
1122 | |
1123 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
1124 prev->upstream.buffer_size, | |
1125 (size_t) ngx_pagesize); | |
1126 | |
1127 | |
1128 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1129 8, ngx_pagesize); | |
1130 | |
1131 if (conf->upstream.bufs.num < 2) { | |
1132 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1133 "there must be at least 2 \"scgi_buffers\""); | |
1134 return NGX_CONF_ERROR; | |
1135 } | |
1136 | |
1137 | |
1138 size = conf->upstream.buffer_size; | |
1139 if (size < conf->upstream.bufs.size) { | |
1140 size = conf->upstream.bufs.size; | |
1141 } | |
1142 | |
1143 | |
1144 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, | |
1145 prev->upstream.busy_buffers_size_conf, | |
1146 NGX_CONF_UNSET_SIZE); | |
1147 | |
1148 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { | |
1149 conf->upstream.busy_buffers_size = 2 * size; | |
1150 } else { | |
1151 conf->upstream.busy_buffers_size = | |
1152 conf->upstream.busy_buffers_size_conf; | |
1153 } | |
1154 | |
1155 if (conf->upstream.busy_buffers_size < size) { | |
1156 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1157 "\"scgi_busy_buffers_size\" must be equal or bigger " | |
1158 "than maximum of the value of \"scgi_buffer_size\" and " | |
1159 "one of the \"scgi_buffers\""); | |
1160 | |
1161 return NGX_CONF_ERROR; | |
1162 } | |
1163 | |
1164 if (conf->upstream.busy_buffers_size | |
1165 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
1166 { | |
1167 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1168 "\"scgi_busy_buffers_size\" must be less than " | |
1169 "the size of all \"scgi_buffers\" minus one buffer"); | |
1170 | |
1171 return NGX_CONF_ERROR; | |
1172 } | |
1173 | |
1174 | |
1175 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, | |
1176 prev->upstream.temp_file_write_size_conf, | |
1177 NGX_CONF_UNSET_SIZE); | |
1178 | |
1179 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { | |
1180 conf->upstream.temp_file_write_size = 2 * size; | |
1181 } else { | |
1182 conf->upstream.temp_file_write_size = | |
1183 conf->upstream.temp_file_write_size_conf; | |
1184 } | |
1185 | |
1186 if (conf->upstream.temp_file_write_size < size) { | |
1187 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1188 "\"scgi_temp_file_write_size\" must be equal or bigger than " | |
1189 "maximum of the value of \"scgi_buffer_size\" and " | |
1190 "one of the \"scgi_buffers\""); | |
1191 | |
1192 return NGX_CONF_ERROR; | |
1193 } | |
1194 | |
1195 | |
1196 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, | |
1197 prev->upstream.max_temp_file_size_conf, | |
1198 NGX_CONF_UNSET_SIZE); | |
1199 | |
1200 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { | |
1201 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; | |
1202 } else { | |
1203 conf->upstream.max_temp_file_size = | |
1204 conf->upstream.max_temp_file_size_conf; | |
1205 } | |
1206 | |
1207 if (conf->upstream.max_temp_file_size != 0 | |
1208 && conf->upstream.max_temp_file_size < size) { | |
1209 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1210 "\"scgi_max_temp_file_size\" must be equal to zero to disable " | |
1211 "the temporary files usage or must be equal or bigger than " | |
1212 "maximum of the value of \"scgi_buffer_size\" and " | |
1213 "one of the \"scgi_buffers\""); | |
1214 | |
1215 return NGX_CONF_ERROR; | |
1216 } | |
1217 | |
1218 | |
1219 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, | |
1220 prev->upstream.ignore_headers, | |
1221 NGX_CONF_BITMASK_SET); | |
1222 | |
1223 | |
1224 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
1225 prev->upstream.next_upstream, | |
1226 (NGX_CONF_BITMASK_SET | |
1227 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1228 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1229 | |
1230 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1231 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1232 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1233 } | |
1234 | |
1235 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path, | |
1236 prev->upstream.temp_path, | |
1237 &ngx_http_scgi_temp_path) | |
1238 != NGX_OK) | |
1239 { | |
1240 return NGX_CONF_ERROR; | |
1241 } | |
1242 | |
1243 #if (NGX_HTTP_CACHE) | |
1244 | |
1245 ngx_conf_merge_ptr_value(conf->upstream.cache, | |
1246 prev->upstream.cache, NULL); | |
1247 | |
1248 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { | |
1249 ngx_shm_zone_t *shm_zone; | |
1250 | |
1251 shm_zone = conf->upstream.cache; | |
1252 | |
1253 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1254 "\"scgi_cache\" zone \"%V\" is unknown", | |
1255 &shm_zone->shm.name); | |
1256 | |
1257 return NGX_CONF_ERROR; | |
1258 } | |
1259 | |
1260 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses, | |
1261 prev->upstream.cache_min_uses, 1); | |
1262 | |
1263 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale, | |
1264 prev->upstream.cache_use_stale, | |
1265 (NGX_CONF_BITMASK_SET | |
1266 |NGX_HTTP_UPSTREAM_FT_OFF)); | |
1267 | |
1268 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1269 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET | |
1270 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1271 } | |
1272 | |
1273 if (conf->upstream.cache_methods == 0) { | |
1274 conf->upstream.cache_methods = prev->upstream.cache_methods; | |
1275 } | |
1276 | |
1277 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD; | |
1278 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3693
diff
changeset
|
1279 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
|
1280 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
|
1281 |
3637 | 1282 ngx_conf_merge_ptr_value(conf->upstream.no_cache, |
1283 prev->upstream.no_cache, NULL); | |
1284 | |
1285 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, | |
1286 prev->upstream.cache_valid, NULL); | |
1287 | |
1288 if (conf->cache_key.value.data == NULL) { | |
1289 conf->cache_key = prev->cache_key; | |
1290 } | |
1291 | |
1292 #endif | |
1293 | |
1294 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1295 prev->upstream.pass_request_headers, 1); | |
1296 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1297 prev->upstream.pass_request_body, 1); | |
1298 | |
1299 ngx_conf_merge_value(conf->upstream.intercept_errors, | |
1300 prev->upstream.intercept_errors, 0); | |
1301 | |
1302 hash.max_size = 512; | |
1303 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
1304 hash.name = "scgi_hide_headers_hash"; | |
1305 | |
1306 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
|
1307 &prev->upstream, ngx_http_scgi_hide_headers, &hash) |
3637 | 1308 != NGX_OK) |
1309 { | |
1310 return NGX_CONF_ERROR; | |
1311 } | |
1312 | |
1313 if (conf->upstream.upstream == NULL) { | |
1314 conf->upstream.upstream = prev->upstream.upstream; | |
1315 } | |
1316 | |
1317 if (conf->scgi_lengths == NULL) { | |
1318 conf->scgi_lengths = prev->scgi_lengths; | |
1319 conf->scgi_values = prev->scgi_values; | |
1320 } | |
1321 | |
3731
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1322 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
|
1323 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
|
1324 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
|
1325 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
|
1326 } |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1327 } |
72cc5b789021
inherit proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass inside
Igor Sysoev <igor@sysoev.ru>
parents:
3729
diff
changeset
|
1328 |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1329 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
|
1330 return NGX_CONF_ERROR; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1331 } |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1332 |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1333 return NGX_CONF_OK; |
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 |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1337 static ngx_int_t |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1338 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
|
1339 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
|
1340 { |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1341 u_char *p; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1342 size_t size; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1343 uintptr_t *code; |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1344 ngx_uint_t i, nsrc; |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1345 ngx_array_t headers_names; |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1346 #if (NGX_HTTP_CACHE) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1347 ngx_array_t params_merged; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1348 #endif |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1349 ngx_hash_key_t *hk; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1350 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
|
1351 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
|
1352 ngx_http_script_compile_t sc; |
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1353 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
|
1354 |
3637 | 1355 if (conf->params_source == NULL) { |
1356 conf->params_source = prev->params_source; | |
1357 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1358 if (prev->headers_hash.buckets |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1359 #if (NGX_HTTP_CACHE) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1360 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1361 #endif |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1362 ) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1363 { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1364 conf->flushes = prev->flushes; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1365 conf->params_len = prev->params_len; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1366 conf->params = prev->params; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1367 conf->headers_hash = prev->headers_hash; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1368 conf->header_params = prev->header_params; |
3637 | 1369 |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1370 return NGX_OK; |
3637 | 1371 } |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1372 } |
3637 | 1373 |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1374 if (conf->params_source == NULL |
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 && (conf->upstream.cache == NULL) |
3637 | 1377 #endif |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1378 ) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1379 { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1380 conf->headers_hash.buckets = (void *) 1; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1381 return NGX_OK; |
3637 | 1382 } |
1383 | |
1384 conf->params_len = ngx_array_create(cf->pool, 64, 1); | |
1385 if (conf->params_len == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1386 return NGX_ERROR; |
3637 | 1387 } |
1388 | |
1389 conf->params = ngx_array_create(cf->pool, 512, 1); | |
1390 if (conf->params == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1391 return NGX_ERROR; |
3637 | 1392 } |
1393 | |
1394 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | |
1395 != NGX_OK) | |
1396 { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1397 return NGX_ERROR; |
3637 | 1398 } |
1399 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1400 if (conf->params_source) { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1401 src = conf->params_source->elts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1402 nsrc = conf->params_source->nelts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1403 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1404 } else { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1405 src = NULL; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1406 nsrc = 0; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1407 } |
3637 | 1408 |
1409 #if (NGX_HTTP_CACHE) | |
1410 | |
1411 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
|
1412 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
|
1413 ngx_http_upstream_param_t *s; |
3637 | 1414 |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1415 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
|
1416 sizeof(ngx_http_upstream_param_t)) |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1417 != NGX_OK) |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1418 { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1419 return NGX_ERROR; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1420 } |
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 for (i = 0; i < nsrc; i++) { |
3637 | 1423 |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1424 s = ngx_array_push(¶ms_merged); |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1425 if (s == NULL) { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1426 return NGX_ERROR; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1427 } |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1428 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1429 *s = src[i]; |
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 h = ngx_http_scgi_cache_headers; |
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 while (h->key.len) { |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1435 |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1436 src = params_merged.elts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1437 nsrc = params_merged.nelts; |
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 for (i = 0; i < nsrc; i++) { |
3637 | 1440 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { |
1441 goto next; | |
1442 } | |
1443 } | |
1444 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1445 s = ngx_array_push(¶ms_merged); |
3637 | 1446 if (s == NULL) { |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1447 return NGX_ERROR; |
3637 | 1448 } |
1449 | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1450 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
|
1451 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
|
1452 s->skip_empty = 0; |
3637 | 1453 |
1454 next: | |
1455 | |
1456 h++; | |
1457 } | |
4278
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 src = params_merged.elts; |
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1460 nsrc = params_merged.nelts; |
3637 | 1461 } |
1462 | |
1463 #endif | |
1464 | |
4278
f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4277
diff
changeset
|
1465 for (i = 0; i < nsrc; i++) { |
3637 | 1466 |
1467 if (src[i].key.len > sizeof("HTTP_") - 1 | |
1468 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | |
1469 { | |
1470 hk = ngx_array_push(&headers_names); | |
1471 if (hk == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1472 return NGX_ERROR; |
3637 | 1473 } |
1474 | |
1475 hk->key.len = src[i].key.len - 5; | |
1476 hk->key.data = src[i].key.data + 5; | |
1477 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); | |
1478 hk->value = (void *) 1; | |
1479 | |
1480 if (src[i].value.len == 0) { | |
1481 continue; | |
1482 } | |
1483 } | |
1484 | |
1485 copy = ngx_array_push_n(conf->params_len, | |
1486 sizeof(ngx_http_script_copy_code_t)); | |
1487 if (copy == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1488 return NGX_ERROR; |
3637 | 1489 } |
1490 | |
1491 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | |
1492 copy->len = src[i].key.len + 1; | |
1493 | |
4331
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1494 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
|
1495 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
|
1496 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
|
1497 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
|
1498 } |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1499 |
059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4294
diff
changeset
|
1500 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
|
1501 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
|
1502 |
3637 | 1503 |
1504 size = (sizeof(ngx_http_script_copy_code_t) | |
1505 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) | |
1506 & ~(sizeof(uintptr_t) - 1); | |
1507 | |
1508 copy = ngx_array_push_n(conf->params, size); | |
1509 if (copy == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1510 return NGX_ERROR; |
3637 | 1511 } |
1512 | |
1513 copy->code = ngx_http_script_copy_code; | |
1514 copy->len = src[i].key.len + 1; | |
1515 | |
1516 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
1517 (void) ngx_cpystrn(p, src[i].key.data, src[i].key.len + 1); | |
1518 | |
1519 | |
1520 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1521 | |
1522 sc.cf = cf; | |
1523 sc.source = &src[i].value; | |
1524 sc.flushes = &conf->flushes; | |
1525 sc.lengths = &conf->params_len; | |
1526 sc.values = &conf->params; | |
1527 | |
1528 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
|
1529 return NGX_ERROR; |
3637 | 1530 } |
1531 | |
1532 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
1533 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1534 return NGX_ERROR; |
3637 | 1535 } |
1536 | |
1537 *code = (uintptr_t) NULL; | |
1538 | |
1539 | |
1540 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | |
1541 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1542 return NGX_ERROR; |
3637 | 1543 } |
1544 | |
1545 *code = (uintptr_t) NULL; | |
1546 } | |
1547 | |
1548 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
1549 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1550 return NGX_ERROR; |
3637 | 1551 } |
1552 | |
1553 *code = (uintptr_t) NULL; | |
1554 | |
1555 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | |
1556 if (code == NULL) { | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1557 return NGX_ERROR; |
3637 | 1558 } |
1559 | |
1560 *code = (uintptr_t) NULL; | |
1561 | |
1562 conf->header_params = headers_names.nelts; | |
1563 | |
1564 hash.hash = &conf->headers_hash; | |
1565 hash.key = ngx_hash_key_lc; | |
1566 hash.max_size = 512; | |
1567 hash.bucket_size = 64; | |
1568 hash.name = "scgi_params_hash"; | |
1569 hash.pool = cf->pool; | |
1570 hash.temp_pool = NULL; | |
1571 | |
4277
e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4157
diff
changeset
|
1572 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts); |
3637 | 1573 } |
1574 | |
1575 | |
1576 static char * | |
1577 ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1578 { | |
1579 ngx_http_scgi_loc_conf_t *scf = conf; | |
1580 | |
1581 ngx_url_t u; | |
1582 ngx_str_t *value, *url; | |
1583 ngx_uint_t n; | |
1584 ngx_http_core_loc_conf_t *clcf; | |
1585 ngx_http_script_compile_t sc; | |
1586 | |
1587 if (scf->upstream.upstream || scf->scgi_lengths) { | |
1588 return "is duplicate"; | |
1589 } | |
1590 | |
1591 clcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module); | |
1592 clcf->handler = ngx_http_scgi_handler; | |
1593 | |
1594 value = cf->args->elts; | |
1595 | |
1596 url = &value[1]; | |
1597 | |
1598 n = ngx_http_script_variables_count(url); | |
1599 | |
1600 if (n) { | |
1601 | |
1602 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1603 | |
1604 sc.cf = cf; | |
1605 sc.source = url; | |
1606 sc.lengths = &scf->scgi_lengths; | |
1607 sc.values = &scf->scgi_values; | |
1608 sc.variables = n; | |
1609 sc.complete_lengths = 1; | |
1610 sc.complete_values = 1; | |
1611 | |
1612 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1613 return NGX_CONF_ERROR; | |
1614 } | |
1615 | |
1616 return NGX_CONF_OK; | |
1617 } | |
1618 | |
1619 ngx_memzero(&u, sizeof(ngx_url_t)); | |
1620 | |
1621 u.url = value[1]; | |
1622 u.no_resolve = 1; | |
1623 | |
1624 scf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); | |
1625 if (scf->upstream.upstream == NULL) { | |
1626 return NGX_CONF_ERROR; | |
1627 } | |
1628 | |
1629 if (clcf->name.data[clcf->name.len - 1] == '/') { | |
1630 clcf->auto_redirect = 1; | |
1631 } | |
1632 | |
1633 return NGX_CONF_OK; | |
1634 } | |
1635 | |
1636 | |
1637 static char * | |
1638 ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1639 { | |
1640 ngx_http_scgi_loc_conf_t *scf = conf; | |
1641 | |
1642 ngx_str_t *value; | |
1643 ngx_http_script_compile_t sc; | |
1644 | |
1645 if (scf->upstream.store != NGX_CONF_UNSET || scf->upstream.store_lengths) { | |
1646 return "is duplicate"; | |
1647 } | |
1648 | |
1649 value = cf->args->elts; | |
1650 | |
1651 if (ngx_strcmp(value[1].data, "off") == 0) { | |
1652 scf->upstream.store = 0; | |
1653 return NGX_CONF_OK; | |
1654 } | |
1655 | |
1656 #if (NGX_HTTP_CACHE) | |
1657 | |
1658 if (scf->upstream.cache != NGX_CONF_UNSET_PTR | |
1659 && scf->upstream.cache != NULL) | |
1660 { | |
1661 return "is incompatible with \"scgi_cache\""; | |
1662 } | |
1663 | |
1664 #endif | |
1665 | |
1666 if (ngx_strcmp(value[1].data, "on") == 0) { | |
1667 scf->upstream.store = 1; | |
1668 return NGX_CONF_OK; | |
1669 } | |
1670 | |
1671 /* include the terminating '\0' into script */ | |
1672 value[1].len++; | |
1673 | |
1674 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1675 | |
1676 sc.cf = cf; | |
1677 sc.source = &value[1]; | |
1678 sc.lengths = &scf->upstream.store_lengths; | |
1679 sc.values = &scf->upstream.store_values; | |
1680 sc.variables = ngx_http_script_variables_count(&value[1]);; | |
1681 sc.complete_lengths = 1; | |
1682 sc.complete_values = 1; | |
1683 | |
1684 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1685 return NGX_CONF_ERROR; | |
1686 } | |
1687 | |
1688 return NGX_CONF_OK; | |
1689 } | |
1690 | |
1691 | |
1692 #if (NGX_HTTP_CACHE) | |
1693 | |
1694 static char * | |
1695 ngx_http_scgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1696 { | |
1697 ngx_http_scgi_loc_conf_t *scf = conf; | |
1698 | |
1699 ngx_str_t *value; | |
1700 | |
1701 value = cf->args->elts; | |
1702 | |
1703 if (scf->upstream.cache != NGX_CONF_UNSET_PTR) { | |
1704 return "is duplicate"; | |
1705 } | |
1706 | |
1707 if (ngx_strcmp(value[1].data, "off") == 0) { | |
1708 scf->upstream.cache = NULL; | |
1709 return NGX_CONF_OK; | |
1710 } | |
1711 | |
1712 if (scf->upstream.store > 0 || scf->upstream.store_lengths) { | |
1713 return "is incompatible with \"scgi_store\""; | |
1714 } | |
1715 | |
1716 scf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0, | |
1717 &ngx_http_scgi_module); | |
1718 if (scf->upstream.cache == NULL) { | |
1719 return NGX_CONF_ERROR; | |
1720 } | |
1721 | |
1722 return NGX_CONF_OK; | |
1723 } | |
1724 | |
1725 | |
1726 static char * | |
1727 ngx_http_scgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1728 { | |
1729 ngx_http_scgi_loc_conf_t *scf = conf; | |
1730 | |
1731 ngx_str_t *value; | |
1732 ngx_http_compile_complex_value_t ccv; | |
1733 | |
1734 value = cf->args->elts; | |
1735 | |
1736 if (scf->cache_key.value.len) { | |
1737 return "is duplicate"; | |
1738 } | |
1739 | |
1740 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
1741 | |
1742 ccv.cf = cf; | |
1743 ccv.value = &value[1]; | |
1744 ccv.complex_value = &scf->cache_key; | |
1745 | |
1746 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
1747 return NGX_CONF_ERROR; | |
1748 } | |
1749 | |
1750 return NGX_CONF_OK; | |
1751 } | |
1752 | |
1753 #endif |