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