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