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