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