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