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