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