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