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