Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_fastcgi_module.c @ 1571:f3a941d0d666
bump version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 15 Oct 2007 11:32:09 +0000 |
parents | 4c43e25d11ea |
children | 481fe1bc191b |
rev | line source |
---|---|
479 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 #include <nginx.h> | |
11 | |
12 | |
13 typedef struct { | |
651 | 14 ngx_http_upstream_conf_t upstream; |
15 | |
16 ngx_str_t index; | |
17 | |
18 ngx_array_t *flushes; | |
19 ngx_array_t *params_len; | |
20 ngx_array_t *params; | |
21 ngx_array_t *params_source; | |
1228 | 22 ngx_array_t *catch_stderr; |
479 | 23 } ngx_http_fastcgi_loc_conf_t; |
24 | |
25 | |
26 typedef enum { | |
27 ngx_http_fastcgi_st_version = 0, | |
28 ngx_http_fastcgi_st_type, | |
29 ngx_http_fastcgi_st_request_id_hi, | |
30 ngx_http_fastcgi_st_request_id_lo, | |
31 ngx_http_fastcgi_st_content_length_hi, | |
32 ngx_http_fastcgi_st_content_length_lo, | |
33 ngx_http_fastcgi_st_padding_length, | |
34 ngx_http_fastcgi_st_reserved, | |
35 ngx_http_fastcgi_st_data, | |
515 | 36 ngx_http_fastcgi_st_padding |
479 | 37 } ngx_http_fastcgi_state_e; |
38 | |
39 | |
40 typedef struct { | |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
41 u_char *start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
42 u_char *end; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
43 } ngx_http_fastcgi_split_part_t; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
44 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
45 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
46 typedef struct { |
651 | 47 ngx_http_fastcgi_state_e state; |
48 u_char *pos; | |
49 u_char *last; | |
50 ngx_uint_t type; | |
51 size_t length; | |
52 size_t padding; | |
53 | |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
54 ngx_uint_t fastcgi_stdout; /* unsigned :1 */ |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
55 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
56 ngx_array_t *split_parts; |
479 | 57 } ngx_http_fastcgi_ctx_t; |
58 | |
59 | |
60 #define NGX_HTTP_FASTCGI_RESPONDER 1 | |
61 | |
62 #define NGX_HTTP_FASTCGI_BEGIN_REQUEST 1 | |
63 #define NGX_HTTP_FASTCGI_ABORT_REQUEST 2 | |
64 #define NGX_HTTP_FASTCGI_END_REQUEST 3 | |
65 #define NGX_HTTP_FASTCGI_PARAMS 4 | |
66 #define NGX_HTTP_FASTCGI_STDIN 5 | |
67 #define NGX_HTTP_FASTCGI_STDOUT 6 | |
68 #define NGX_HTTP_FASTCGI_STDERR 7 | |
69 #define NGX_HTTP_FASTCGI_DATA 8 | |
70 | |
71 | |
72 typedef struct { | |
73 u_char version; | |
74 u_char type; | |
75 u_char request_id_hi; | |
76 u_char request_id_lo; | |
77 u_char content_length_hi; | |
78 u_char content_length_lo; | |
79 u_char padding_length; | |
80 u_char reserved; | |
81 } ngx_http_fastcgi_header_t; | |
82 | |
83 | |
84 typedef struct { | |
85 u_char role_hi; | |
86 u_char role_lo; | |
87 u_char flags; | |
88 u_char reserved[5]; | |
89 } ngx_http_fastcgi_begin_request_t; | |
90 | |
91 | |
509 | 92 typedef struct { |
93 u_char version; | |
94 u_char type; | |
95 u_char request_id_hi; | |
96 u_char request_id_lo; | |
97 } ngx_http_fastcgi_header_small_t; | |
98 | |
99 | |
100 typedef struct { | |
101 ngx_http_fastcgi_header_t h0; | |
102 ngx_http_fastcgi_begin_request_t br; | |
103 ngx_http_fastcgi_header_small_t h1; | |
104 } ngx_http_fastcgi_request_start_t; | |
105 | |
106 | |
479 | 107 static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r); |
108 static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r); | |
109 static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r); | |
110 static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, | |
487 | 111 ngx_buf_t *buf); |
479 | 112 static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r, |
487 | 113 ngx_http_fastcgi_ctx_t *f); |
479 | 114 static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r); |
115 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, | |
487 | 116 ngx_int_t rc); |
479 | 117 |
509 | 118 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); |
119 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | |
120 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | |
121 void *parent, void *child); | |
573 | 122 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, |
123 ngx_http_variable_value_t *v, uintptr_t data); | |
509 | 124 |
479 | 125 static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
487 | 126 void *conf); |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
127 static char *ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
128 void *conf); |
479 | 129 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, |
487 | 130 void *data); |
479 | 131 |
884 | 132 static char *ngx_http_fastcgi_upstream_max_fails_unsupported(ngx_conf_t *cf, |
133 ngx_command_t *cmd, void *conf); | |
134 static char *ngx_http_fastcgi_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
135 ngx_command_t *cmd, void *conf); | |
136 | |
479 | 137 |
509 | 138 static ngx_http_fastcgi_request_start_t ngx_http_fastcgi_request_start = { |
139 { 1, /* version */ | |
140 NGX_HTTP_FASTCGI_BEGIN_REQUEST, /* type */ | |
141 0, /* request_id_hi */ | |
142 1, /* request_id_lo */ | |
143 0, /* content_length_hi */ | |
144 sizeof(ngx_http_fastcgi_begin_request_t), /* content_length_lo */ | |
145 0, /* padding_length */ | |
146 0 }, /* reserved */ | |
147 | |
148 { 0, /* role_hi */ | |
149 NGX_HTTP_FASTCGI_RESPONDER, /* role_lo */ | |
150 0, /* NGX_HTTP_FASTCGI_KEEP_CONN */ /* flags */ | |
151 { 0, 0, 0, 0, 0 } }, /* reserved[5] */ | |
152 | |
153 { 1, /* version */ | |
154 NGX_HTTP_FASTCGI_PARAMS, /* type */ | |
155 0, /* request_id_hi */ | |
156 1 }, /* request_id_lo */ | |
157 | |
158 }; | |
159 | |
160 | |
161 static ngx_str_t ngx_http_fastcgi_script_name = | |
162 ngx_string("fastcgi_script_name"); | |
479 | 163 |
164 | |
509 | 165 static ngx_conf_post_t ngx_http_fastcgi_lowat_post = |
166 { ngx_http_fastcgi_lowat_check }; | |
479 | 167 |
581 | 168 static ngx_conf_deprecated_t ngx_conf_deprecated_fastcgi_header_buffer_size = { |
169 ngx_conf_deprecated, "fastcgi_header_buffer_size", "fastcgi_buffer_size" | |
170 }; | |
171 | |
657 | 172 static ngx_conf_deprecated_t ngx_conf_deprecated_fastcgi_redirect_errors = { |
173 ngx_conf_deprecated, "fastcgi_redirect_errors", "fastcgi_intercept_errors" | |
174 }; | |
175 | |
479 | 176 |
177 static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = { | |
178 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, | |
179 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, | |
180 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, | |
181 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, | |
623 | 182 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
479 | 183 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
665 | 184 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, |
479 | 185 { ngx_null_string, 0 } |
186 }; | |
187 | |
188 | |
189 static ngx_command_t ngx_http_fastcgi_commands[] = { | |
190 | |
191 { ngx_string("fastcgi_pass"), | |
629 | 192 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, |
479 | 193 ngx_http_fastcgi_pass, |
194 NGX_HTTP_LOC_CONF_OFFSET, | |
195 0, | |
196 NULL }, | |
197 | |
198 { ngx_string("fastcgi_index"), | |
199 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
200 ngx_conf_set_str_slot, | |
201 NGX_HTTP_LOC_CONF_OFFSET, | |
202 offsetof(ngx_http_fastcgi_loc_conf_t, index), | |
203 NULL }, | |
204 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1276
diff
changeset
|
205 { ngx_string("fastcgi_store"), |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
206 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
207 ngx_http_fastcgi_store, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
208 NGX_HTTP_LOC_CONF_OFFSET, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
209 0, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
210 NULL }, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
211 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
212 { ngx_string("fastcgi_store_access"), |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1276
diff
changeset
|
213 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1276
diff
changeset
|
214 ngx_conf_set_access_slot, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1276
diff
changeset
|
215 NGX_HTTP_LOC_CONF_OFFSET, |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
216 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.store_access), |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1276
diff
changeset
|
217 NULL }, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1276
diff
changeset
|
218 |
629 | 219 { ngx_string("fastcgi_ignore_client_abort"), |
220 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
221 ngx_conf_set_flag_slot, | |
222 NGX_HTTP_LOC_CONF_OFFSET, | |
223 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_client_abort), | |
224 NULL }, | |
225 | |
479 | 226 { ngx_string("fastcgi_connect_timeout"), |
227 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
228 ngx_conf_set_msec_slot, | |
229 NGX_HTTP_LOC_CONF_OFFSET, | |
230 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.connect_timeout), | |
231 NULL }, | |
232 | |
233 { ngx_string("fastcgi_send_timeout"), | |
234 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
235 ngx_conf_set_msec_slot, | |
236 NGX_HTTP_LOC_CONF_OFFSET, | |
237 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_timeout), | |
238 NULL }, | |
239 | |
240 { ngx_string("fastcgi_send_lowat"), | |
241 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
242 ngx_conf_set_size_slot, | |
243 NGX_HTTP_LOC_CONF_OFFSET, | |
244 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_lowat), | |
245 &ngx_http_fastcgi_lowat_post }, | |
246 | |
581 | 247 { ngx_string("fastcgi_buffer_size"), |
248 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
249 ngx_conf_set_size_slot, | |
250 NGX_HTTP_LOC_CONF_OFFSET, | |
251 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size), | |
252 NULL }, | |
253 | |
479 | 254 { ngx_string("fastcgi_header_buffer_size"), |
255 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
256 ngx_conf_set_size_slot, | |
257 NGX_HTTP_LOC_CONF_OFFSET, | |
581 | 258 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size), |
259 &ngx_conf_deprecated_fastcgi_header_buffer_size }, | |
479 | 260 |
509 | 261 { ngx_string("fastcgi_pass_request_headers"), |
262 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
263 ngx_conf_set_flag_slot, | |
264 NGX_HTTP_LOC_CONF_OFFSET, | |
265 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_headers), | |
266 NULL }, | |
267 | |
268 { ngx_string("fastcgi_pass_request_body"), | |
269 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
270 ngx_conf_set_flag_slot, | |
271 NGX_HTTP_LOC_CONF_OFFSET, | |
272 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_body), | |
273 NULL }, | |
274 | |
657 | 275 { ngx_string("fastcgi_intercept_errors"), |
276 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
277 ngx_conf_set_flag_slot, | |
278 NGX_HTTP_LOC_CONF_OFFSET, | |
279 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.intercept_errors), | |
280 NULL }, | |
281 | |
487 | 282 { ngx_string("fastcgi_redirect_errors"), |
283 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
284 ngx_conf_set_flag_slot, | |
285 NGX_HTTP_LOC_CONF_OFFSET, | |
657 | 286 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.intercept_errors), |
287 &ngx_conf_deprecated_fastcgi_redirect_errors }, | |
487 | 288 |
479 | 289 { ngx_string("fastcgi_read_timeout"), |
290 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
291 ngx_conf_set_msec_slot, | |
292 NGX_HTTP_LOC_CONF_OFFSET, | |
293 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.read_timeout), | |
294 NULL }, | |
295 | |
296 { ngx_string("fastcgi_buffers"), | |
297 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
298 ngx_conf_set_bufs_slot, | |
299 NGX_HTTP_LOC_CONF_OFFSET, | |
300 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.bufs), | |
301 NULL }, | |
302 | |
303 { ngx_string("fastcgi_busy_buffers_size"), | |
304 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
305 ngx_conf_set_size_slot, | |
306 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 307 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.busy_buffers_size_conf), |
479 | 308 NULL }, |
309 | |
310 { ngx_string("fastcgi_temp_path"), | |
311 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
312 ngx_conf_set_path_slot, | |
313 NGX_HTTP_LOC_CONF_OFFSET, | |
314 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_path), | |
315 (void *) ngx_garbage_collector_temp_handler }, | |
316 | |
317 { ngx_string("fastcgi_max_temp_file_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, | |
529 | 321 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.max_temp_file_size_conf), |
479 | 322 NULL }, |
323 | |
324 { ngx_string("fastcgi_temp_file_write_size"), | |
325 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
326 ngx_conf_set_size_slot, | |
327 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 328 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_file_write_size_conf), |
479 | 329 NULL }, |
330 | |
331 { ngx_string("fastcgi_next_upstream"), | |
547 | 332 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
479 | 333 ngx_conf_set_bitmask_slot, |
334 NGX_HTTP_LOC_CONF_OFFSET, | |
335 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream), | |
336 &ngx_http_fastcgi_next_upstream_masks }, | |
337 | |
561 | 338 { ngx_string("fastcgi_upstream_max_fails"), |
339 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
884 | 340 ngx_http_fastcgi_upstream_max_fails_unsupported, |
341 0, | |
342 0, | |
561 | 343 NULL }, |
344 | |
345 { ngx_string("fastcgi_upstream_fail_timeout"), | |
346 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
884 | 347 ngx_http_fastcgi_upstream_fail_timeout_unsupported, |
348 0, | |
349 0, | |
561 | 350 NULL }, |
351 | |
509 | 352 { ngx_string("fastcgi_param"), |
353 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
649 | 354 ngx_conf_set_keyval_slot, |
485 | 355 NGX_HTTP_LOC_CONF_OFFSET, |
509 | 356 offsetof(ngx_http_fastcgi_loc_conf_t, params_source), |
485 | 357 NULL }, |
358 | |
649 | 359 { ngx_string("fastcgi_pass_header"), |
360 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
361 ngx_conf_set_str_array_slot, | |
362 NGX_HTTP_LOC_CONF_OFFSET, | |
363 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_headers), | |
364 NULL }, | |
365 | |
366 { ngx_string("fastcgi_hide_header"), | |
367 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
368 ngx_conf_set_str_array_slot, | |
369 NGX_HTTP_LOC_CONF_OFFSET, | |
370 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.hide_headers), | |
371 NULL }, | |
372 | |
1228 | 373 { ngx_string("fastcgi_catch_stderr"), |
374 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
375 ngx_conf_set_str_array_slot, | |
376 NGX_HTTP_LOC_CONF_OFFSET, | |
377 offsetof(ngx_http_fastcgi_loc_conf_t, catch_stderr), | |
378 NULL }, | |
379 | |
479 | 380 ngx_null_command |
381 }; | |
382 | |
383 | |
667 | 384 static ngx_http_module_t ngx_http_fastcgi_module_ctx = { |
509 | 385 ngx_http_fastcgi_add_variables, /* preconfiguration */ |
386 NULL, /* postconfiguration */ | |
479 | 387 |
388 NULL, /* create main configuration */ | |
389 NULL, /* init main configuration */ | |
390 | |
391 NULL, /* create server configuration */ | |
392 NULL, /* merge server configuration */ | |
393 | |
394 ngx_http_fastcgi_create_loc_conf, /* create location configuration */ | |
395 ngx_http_fastcgi_merge_loc_conf /* merge location configuration */ | |
396 }; | |
397 | |
398 | |
399 ngx_module_t ngx_http_fastcgi_module = { | |
509 | 400 NGX_MODULE_V1, |
479 | 401 &ngx_http_fastcgi_module_ctx, /* module context */ |
402 ngx_http_fastcgi_commands, /* module directives */ | |
403 NGX_HTTP_MODULE, /* module type */ | |
541 | 404 NULL, /* init master */ |
479 | 405 NULL, /* init module */ |
541 | 406 NULL, /* init process */ |
407 NULL, /* init thread */ | |
408 NULL, /* exit thread */ | |
409 NULL, /* exit process */ | |
410 NULL, /* exit master */ | |
411 NGX_MODULE_V1_PADDING | |
479 | 412 }; |
413 | |
414 | |
649 | 415 static ngx_str_t ngx_http_fastcgi_hide_headers[] = { |
416 ngx_string("Status"), | |
417 ngx_string("X-Accel-Expires"), | |
418 ngx_string("X-Accel-Redirect"), | |
419 ngx_string("X-Accel-Limit-Rate"), | |
420 ngx_string("X-Accel-Buffer"), | |
421 ngx_null_string | |
422 }; | |
423 | |
424 | |
487 | 425 static ngx_int_t |
426 ngx_http_fastcgi_handler(ngx_http_request_t *r) | |
479 | 427 { |
428 ngx_int_t rc; | |
429 ngx_http_upstream_t *u; | |
430 ngx_http_fastcgi_loc_conf_t *flcf; | |
431 | |
777
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
432 if (r->subrequest_in_memory) { |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
433 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
434 "ngx_http_fastcgi_module does not support " |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
435 "subrequest in memeory"); |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
436 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
437 } |
4ab852b691f5
<!--#include virtual=... set=... -->
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
438 |
479 | 439 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
440 | |
501 | 441 u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t)); |
442 if (u == NULL) { | |
479 | 443 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
444 } | |
445 | |
446 u->peer.log = r->connection->log; | |
447 u->peer.log_error = NGX_ERROR_ERR; | |
448 #if (NGX_THREADS) | |
449 u->peer.lock = &r->connection->lock; | |
450 #endif | |
451 | |
452 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module; | |
453 | |
454 u->conf = &flcf->upstream; | |
455 | |
456 u->create_request = ngx_http_fastcgi_create_request; | |
457 u->reinit_request = ngx_http_fastcgi_reinit_request; | |
458 u->process_header = ngx_http_fastcgi_process_header; | |
459 u->abort_request = ngx_http_fastcgi_abort_request; | |
460 u->finalize_request = ngx_http_fastcgi_finalize_request; | |
461 | |
649 | 462 u->buffering = 1; |
463 | |
581 | 464 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t)); |
465 if (u->pipe == NULL) { | |
466 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
467 } | |
468 | |
469 u->pipe->input_filter = ngx_http_fastcgi_input_filter; | |
470 u->pipe->input_ctx = r; | |
479 | 471 |
472 r->upstream = u; | |
473 | |
474 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); | |
475 | |
476 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
477 return rc; | |
478 } | |
479 | |
480 return NGX_DONE; | |
481 } | |
482 | |
483 | |
487 | 484 static ngx_int_t |
485 ngx_http_fastcgi_create_request(ngx_http_request_t *r) | |
479 | 486 { |
509 | 487 off_t file_pos; |
488 u_char ch, *pos; | |
489 size_t size, len, key_len, val_len, padding; | |
490 ngx_uint_t i, n, next; | |
491 ngx_buf_t *b; | |
492 ngx_chain_t *cl, *body; | |
493 ngx_list_part_t *part; | |
494 ngx_table_elt_t *header; | |
495 ngx_http_script_code_pt code; | |
496 ngx_http_script_engine_t e, le; | |
497 ngx_http_fastcgi_header_t *h; | |
498 ngx_http_fastcgi_loc_conf_t *flcf; | |
499 ngx_http_script_len_code_pt lcode; | |
479 | 500 |
509 | 501 len = 0; |
485 | 502 |
479 | 503 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
504 | |
509 | 505 if (flcf->params_len) { |
506 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
479 | 507 |
1565 | 508 ngx_http_script_flush_no_cacheable_variables(r, flcf->flushes); |
573 | 509 le.flushed = 1; |
510 | |
509 | 511 le.ip = flcf->params_len->elts; |
512 le.request = r; | |
479 | 513 |
509 | 514 while (*(uintptr_t *) le.ip) { |
487 | 515 |
509 | 516 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
517 key_len = lcode(&le); | |
479 | 518 |
509 | 519 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { |
520 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
521 } | |
522 le.ip += sizeof(uintptr_t); | |
479 | 523 |
537 | 524 len += 1 + key_len + ((val_len > 127) ? 4 : 1) + val_len; |
485 | 525 } |
526 } | |
527 | |
509 | 528 if (flcf->upstream.pass_request_headers) { |
485 | 529 |
509 | 530 part = &r->headers_in.headers.part; |
531 header = part->elts; | |
532 | |
533 for (i = 0; /* void */; i++) { | |
479 | 534 |
509 | 535 if (i >= part->nelts) { |
536 if (part->next == NULL) { | |
537 break; | |
538 } | |
479 | 539 |
509 | 540 part = part->next; |
541 header = part->elts; | |
542 i = 0; | |
479 | 543 } |
544 | |
509 | 545 len += ((sizeof("HTTP_") - 1 + header[i].key.len > 127) ? 4 : 1) |
546 + ((header[i].value.len > 127) ? 4 : 1) | |
547 + sizeof("HTTP_") - 1 + header[i].key.len + header[i].value.len; | |
479 | 548 } |
549 } | |
550 | |
551 | |
552 if (len > 65535) { | |
553 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
554 "fastcgi: the request record is too big"); | |
555 return NGX_ERROR; | |
556 } | |
557 | |
558 | |
559 padding = 8 - len % 8; | |
560 padding = (padding == 8) ? 0 : padding; | |
561 | |
562 | |
563 size = sizeof(ngx_http_fastcgi_header_t) | |
564 + sizeof(ngx_http_fastcgi_begin_request_t) | |
565 | |
566 + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */ | |
567 + len + padding | |
568 + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */ | |
569 | |
570 + sizeof(ngx_http_fastcgi_header_t); /* NGX_HTTP_FASTCGI_STDIN */ | |
571 | |
572 | |
501 | 573 b = ngx_create_temp_buf(r->pool, size); |
574 if (b == NULL) { | |
479 | 575 return NGX_ERROR; |
576 } | |
577 | |
501 | 578 cl = ngx_alloc_chain_link(r->pool); |
579 if (cl == NULL) { | |
479 | 580 return NGX_ERROR; |
581 } | |
582 | |
583 cl->buf = b; | |
584 | |
509 | 585 ngx_memcpy(b->pos, &ngx_http_fastcgi_request_start, |
586 sizeof(ngx_http_fastcgi_request_start_t)); | |
479 | 587 |
588 h = (ngx_http_fastcgi_header_t *) | |
589 (b->pos + sizeof(ngx_http_fastcgi_header_t) | |
590 + sizeof(ngx_http_fastcgi_begin_request_t)); | |
591 | |
592 h->content_length_hi = (u_char) ((len >> 8) & 0xff); | |
593 h->content_length_lo = (u_char) (len & 0xff); | |
594 h->padding_length = (u_char) padding; | |
595 h->reserved = 0; | |
596 | |
597 b->last = b->pos + sizeof(ngx_http_fastcgi_header_t) | |
598 + sizeof(ngx_http_fastcgi_begin_request_t) | |
599 + sizeof(ngx_http_fastcgi_header_t); | |
600 | |
601 | |
509 | 602 if (flcf->params_len) { |
603 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
479 | 604 |
509 | 605 e.ip = flcf->params->elts; |
606 e.pos = b->last; | |
607 e.request = r; | |
573 | 608 e.flushed = 1; |
479 | 609 |
509 | 610 le.ip = flcf->params_len->elts; |
479 | 611 |
509 | 612 while (*(uintptr_t *) le.ip) { |
479 | 613 |
509 | 614 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
615 key_len = (u_char) lcode(&le); | |
479 | 616 |
509 | 617 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { |
618 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
619 } | |
620 le.ip += sizeof(uintptr_t); | |
479 | 621 |
537 | 622 *e.pos++ = (u_char) key_len; |
479 | 623 |
537 | 624 if (val_len > 127) { |
625 *e.pos++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80); | |
626 *e.pos++ = (u_char) ((val_len >> 16) & 0xff); | |
627 *e.pos++ = (u_char) ((val_len >> 8) & 0xff); | |
628 *e.pos++ = (u_char) (val_len & 0xff); | |
479 | 629 |
537 | 630 } else { |
631 *e.pos++ = (u_char) val_len; | |
509 | 632 } |
479 | 633 |
509 | 634 while (*(uintptr_t *) e.ip) { |
635 code = *(ngx_http_script_code_pt *) e.ip; | |
636 code((ngx_http_script_engine_t *) &e); | |
637 } | |
638 e.ip += sizeof(uintptr_t); | |
479 | 639 } |
640 | |
509 | 641 b->last = e.pos; |
487 | 642 } |
643 | |
644 | |
509 | 645 if (flcf->upstream.pass_request_headers) { |
479 | 646 |
509 | 647 part = &r->headers_in.headers.part; |
648 header = part->elts; | |
479 | 649 |
509 | 650 for (i = 0; /* void */; i++) { |
491 | 651 |
509 | 652 if (i >= part->nelts) { |
653 if (part->next == NULL) { | |
577 | 654 break; |
509 | 655 } |
577 | 656 |
509 | 657 part = part->next; |
658 header = part->elts; | |
659 i = 0; | |
660 } | |
479 | 661 |
509 | 662 len = sizeof("HTTP_") - 1 + header[i].key.len; |
663 if (len > 127) { | |
664 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
665 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
666 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
667 *b->last++ = (u_char) (len & 0xff); | |
577 | 668 |
509 | 669 } else { |
670 *b->last++ = (u_char) len; | |
487 | 671 } |
672 | |
509 | 673 len = header[i].value.len; |
674 if (len > 127) { | |
675 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
676 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
677 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
678 *b->last++ = (u_char) (len & 0xff); | |
487 | 679 |
509 | 680 } else { |
681 *b->last++ = (u_char) len; | |
479 | 682 } |
683 | |
509 | 684 b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1); |
479 | 685 |
509 | 686 for (n = 0; n < header[i].key.len; n++) { |
687 ch = header[i].key.data[n]; | |
479 | 688 |
509 | 689 if (ch >= 'a' && ch <= 'z') { |
690 ch &= ~0x20; | |
479 | 691 |
509 | 692 } else if (ch == '-') { |
693 ch = '_'; | |
694 } | |
479 | 695 |
509 | 696 *b->last++ = ch; |
479 | 697 } |
698 | |
573 | 699 b->last = ngx_copy(b->last, header[i].value.data, |
700 header[i].value.len); | |
479 | 701 } |
702 } | |
703 | |
704 | |
705 if (padding) { | |
706 ngx_memzero(b->last, padding); | |
707 b->last += padding; | |
708 } | |
709 | |
710 | |
711 h = (ngx_http_fastcgi_header_t *) b->last; | |
712 b->last += sizeof(ngx_http_fastcgi_header_t); | |
713 | |
714 h->version = 1; | |
715 h->type = NGX_HTTP_FASTCGI_PARAMS; | |
716 h->request_id_hi = 0; | |
717 h->request_id_lo = 1; | |
718 h->content_length_hi = 0; | |
719 h->content_length_lo = 0; | |
720 h->padding_length = 0; | |
721 h->reserved = 0; | |
722 | |
723 h = (ngx_http_fastcgi_header_t *) b->last; | |
724 b->last += sizeof(ngx_http_fastcgi_header_t); | |
725 | |
509 | 726 if (flcf->upstream.pass_request_body) { |
727 body = r->upstream->request_bufs; | |
728 r->upstream->request_bufs = cl; | |
479 | 729 |
730 #if (NGX_SUPPRESS_WARN) | |
509 | 731 file_pos = 0; |
732 pos = NULL; | |
479 | 733 #endif |
734 | |
509 | 735 while (body) { |
479 | 736 |
509 | 737 if (body->buf->in_file) { |
738 file_pos = body->buf->file_pos; | |
479 | 739 |
509 | 740 } else { |
741 pos = body->buf->pos; | |
479 | 742 } |
743 | |
509 | 744 next = 0; |
479 | 745 |
509 | 746 do { |
747 b = ngx_alloc_buf(r->pool); | |
748 if (b == NULL) { | |
749 return NGX_ERROR; | |
479 | 750 } |
751 | |
509 | 752 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); |
753 | |
754 if (body->buf->in_file) { | |
755 b->file_pos = file_pos; | |
756 file_pos += 32 * 1024; | |
479 | 757 |
1142
e479e0b02e5a
fix "zero size buf" if request body file is multiple of 32K and FastCGI is used
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
758 if (file_pos >= body->buf->file_last) { |
509 | 759 file_pos = body->buf->file_last; |
760 next = 1; | |
761 } | |
762 | |
763 b->file_last = file_pos; | |
764 len = (ngx_uint_t) (file_pos - b->file_pos); | |
765 | |
766 } else { | |
767 b->pos = pos; | |
768 pos += 32 * 1024; | |
479 | 769 |
1142
e479e0b02e5a
fix "zero size buf" if request body file is multiple of 32K and FastCGI is used
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
770 if (pos >= body->buf->last) { |
509 | 771 pos = body->buf->last; |
772 next = 1; | |
773 } | |
774 | |
775 b->last = pos; | |
776 len = (ngx_uint_t) (pos - b->pos); | |
777 } | |
479 | 778 |
509 | 779 padding = 8 - len % 8; |
780 padding = (padding == 8) ? 0 : padding; | |
479 | 781 |
509 | 782 h->version = 1; |
783 h->type = NGX_HTTP_FASTCGI_STDIN; | |
784 h->request_id_hi = 0; | |
785 h->request_id_lo = 1; | |
786 h->content_length_hi = (u_char) ((len >> 8) & 0xff); | |
787 h->content_length_lo = (u_char) (len & 0xff); | |
788 h->padding_length = (u_char) padding; | |
789 h->reserved = 0; | |
479 | 790 |
509 | 791 cl->next = ngx_alloc_chain_link(r->pool); |
792 if (cl->next == NULL) { | |
793 return NGX_ERROR; | |
794 } | |
479 | 795 |
509 | 796 cl = cl->next; |
797 cl->buf = b; | |
798 | |
799 b = ngx_create_temp_buf(r->pool, | |
800 sizeof(ngx_http_fastcgi_header_t) | |
801 + padding); | |
802 if (b == NULL) { | |
803 return NGX_ERROR; | |
804 } | |
479 | 805 |
509 | 806 if (padding) { |
807 ngx_memzero(b->last, padding); | |
808 b->last += padding; | |
809 } | |
810 | |
811 h = (ngx_http_fastcgi_header_t *) b->last; | |
812 b->last += sizeof(ngx_http_fastcgi_header_t); | |
479 | 813 |
509 | 814 cl->next = ngx_alloc_chain_link(r->pool); |
815 if (cl->next == NULL) { | |
816 return NGX_ERROR; | |
817 } | |
818 | |
819 cl = cl->next; | |
820 cl->buf = b; | |
479 | 821 |
509 | 822 } while (!next); |
479 | 823 |
509 | 824 body = body->next; |
825 } | |
479 | 826 |
509 | 827 } else { |
828 r->upstream->request_bufs = cl; | |
479 | 829 } |
830 | |
831 h->version = 1; | |
832 h->type = NGX_HTTP_FASTCGI_STDIN; | |
833 h->request_id_hi = 0; | |
834 h->request_id_lo = 1; | |
835 h->content_length_hi = 0; | |
836 h->content_length_lo = 0; | |
837 h->padding_length = 0; | |
838 h->reserved = 0; | |
839 | |
840 cl->next = NULL; | |
841 | |
842 return NGX_OK; | |
843 } | |
844 | |
845 | |
487 | 846 static ngx_int_t |
847 ngx_http_fastcgi_reinit_request(ngx_http_request_t *r) | |
479 | 848 { |
849 ngx_http_fastcgi_ctx_t *f; | |
850 | |
851 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); | |
852 | |
853 if (f == NULL) { | |
854 return NGX_OK; | |
855 } | |
856 | |
857 f->state = ngx_http_fastcgi_st_version; | |
615 | 858 f->fastcgi_stdout = 0; |
479 | 859 |
860 return NGX_OK; | |
861 } | |
862 | |
863 | |
507 | 864 static ngx_int_t |
865 ngx_http_fastcgi_process_header(ngx_http_request_t *r) | |
479 | 866 { |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
867 u_char *p, *start, *last, *part_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
868 size_t size; |
1228 | 869 ngx_str_t *status_line, line, *pattern; |
509 | 870 ngx_int_t rc, status; |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
871 ngx_buf_t buf; |
649 | 872 ngx_uint_t i; |
509 | 873 ngx_table_elt_t *h; |
874 ngx_http_upstream_t *u; | |
875 ngx_http_fastcgi_ctx_t *f; | |
876 ngx_http_upstream_header_t *hh; | |
1228 | 877 ngx_http_fastcgi_loc_conf_t *flcf; |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
878 ngx_http_fastcgi_split_part_t *part; |
509 | 879 ngx_http_upstream_main_conf_t *umcf; |
479 | 880 |
881 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); | |
882 | |
509 | 883 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); |
884 | |
479 | 885 if (f == NULL) { |
501 | 886 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t)); |
887 if (f == NULL) { | |
479 | 888 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
889 } | |
890 | |
891 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module); | |
892 } | |
893 | |
894 u = r->upstream; | |
895 | |
896 for ( ;; ) { | |
897 | |
898 if (f->state < ngx_http_fastcgi_st_data) { | |
899 | |
581 | 900 f->pos = u->buffer.pos; |
901 f->last = u->buffer.last; | |
479 | 902 |
903 rc = ngx_http_fastcgi_process_record(r, f); | |
904 | |
581 | 905 u->buffer.pos = f->pos; |
906 u->buffer.last = f->last; | |
479 | 907 |
908 if (rc == NGX_AGAIN) { | |
909 return NGX_AGAIN; | |
910 } | |
911 | |
912 if (rc == NGX_ERROR) { | |
913 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
914 } | |
915 | |
491 | 916 if (f->type != NGX_HTTP_FASTCGI_STDOUT |
917 && f->type != NGX_HTTP_FASTCGI_STDERR) | |
918 { | |
479 | 919 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
920 "upstream sent unexpected FastCGI record: %d", | |
921 f->type); | |
922 | |
923 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
924 } | |
925 | |
491 | 926 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) { |
479 | 927 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
928 "upstream closed prematurely FastCGI stdout"); | |
929 | |
930 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
931 } | |
932 } | |
933 | |
934 if (f->state == ngx_http_fastcgi_st_padding) { | |
935 | |
581 | 936 if (u->buffer.pos + f->padding < u->buffer.last) { |
479 | 937 f->state = ngx_http_fastcgi_st_version; |
581 | 938 u->buffer.pos += f->padding; |
479 | 939 |
940 continue; | |
941 } | |
942 | |
581 | 943 if (u->buffer.pos + f->padding == u->buffer.last) { |
479 | 944 f->state = ngx_http_fastcgi_st_version; |
581 | 945 u->buffer.pos = u->buffer.last; |
479 | 946 |
947 return NGX_AGAIN; | |
948 } | |
949 | |
581 | 950 f->padding -= u->buffer.last - u->buffer.pos; |
951 u->buffer.pos = u->buffer.last; | |
479 | 952 |
953 return NGX_AGAIN; | |
954 } | |
955 | |
491 | 956 |
479 | 957 /* f->state == ngx_http_fastcgi_st_data */ |
958 | |
491 | 959 if (f->type == NGX_HTTP_FASTCGI_STDERR) { |
960 | |
961 if (f->length) { | |
581 | 962 line.data = u->buffer.pos; |
491 | 963 |
581 | 964 if (u->buffer.pos + f->length <= u->buffer.last) { |
491 | 965 line.len = f->length; |
581 | 966 u->buffer.pos += f->length; |
491 | 967 f->length = 0; |
968 f->state = ngx_http_fastcgi_st_padding; | |
969 | |
577 | 970 } else { |
581 | 971 line.len = u->buffer.last - u->buffer.pos; |
972 f->length -= u->buffer.last - u->buffer.pos; | |
973 u->buffer.pos = u->buffer.last; | |
491 | 974 } |
975 | |
976 while (line.data[line.len - 1] == LF | |
977 || line.data[line.len - 1] == CR | |
978 || line.data[line.len - 1] == '.' | |
979 || line.data[line.len - 1] == ' ') | |
980 { | |
981 line.len--; | |
982 } | |
983 | |
984 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
985 "FastCGI sent in stderr: \"%V\"", &line); | |
986 | |
1228 | 987 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
988 | |
989 if (flcf->catch_stderr) { | |
990 pattern = flcf->catch_stderr->elts; | |
991 | |
992 line.data[line.len - 1] = '\0'; | |
993 | |
994 for (i = 0; i < flcf->catch_stderr->nelts; i++) { | |
995 if (ngx_strstr(line.data, pattern[i].data)) { | |
996 return NGX_HTTP_BAD_GATEWAY; | |
997 } | |
998 } | |
999 } | |
1000 | |
581 | 1001 if (u->buffer.pos == u->buffer.last) { |
615 | 1002 |
1003 if (!f->fastcgi_stdout) { | |
1004 | |
1005 /* | |
1006 * the special handling the large number | |
1007 * of the PHP warnings to not allocate memory | |
1008 */ | |
1009 | |
1010 u->buffer.pos = u->buffer.start; | |
1011 u->buffer.last = u->buffer.start; | |
1012 } | |
1013 | |
491 | 1014 return NGX_AGAIN; |
1015 } | |
1016 | |
1017 } else { | |
1018 f->state = ngx_http_fastcgi_st_version; | |
1019 } | |
1020 | |
1021 continue; | |
1022 } | |
1023 | |
1024 | |
1025 /* f->type == NGX_HTTP_FASTCGI_STDOUT */ | |
1026 | |
615 | 1027 f->fastcgi_stdout = 1; |
1028 | |
581 | 1029 start = u->buffer.pos; |
479 | 1030 |
581 | 1031 if (u->buffer.pos + f->length < u->buffer.last) { |
479 | 1032 |
1033 /* | |
581 | 1034 * set u->buffer.last to the end of the FastCGI record data |
479 | 1035 * for ngx_http_parse_header_line() |
1036 */ | |
1037 | |
581 | 1038 last = u->buffer.last; |
1039 u->buffer.last = u->buffer.pos + f->length; | |
479 | 1040 |
1041 } else { | |
1042 last = NULL; | |
1043 } | |
1044 | |
1045 for ( ;; ) { | |
1046 | |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1047 part_start = u->buffer.pos; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1048 |
581 | 1049 rc = ngx_http_parse_header_line(r, &u->buffer); |
479 | 1050 |
1051 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1052 "http fastcgi parser: %d", rc); | |
1053 | |
1054 if (rc == NGX_AGAIN) { | |
1055 break; | |
1056 } | |
1057 | |
1058 if (rc == NGX_OK) { | |
1059 | |
1060 /* a header line has been parsed successfully */ | |
1061 | |
509 | 1062 h = ngx_list_push(&u->headers_in.headers); |
501 | 1063 if (h == NULL) { |
479 | 1064 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1065 } | |
1066 | |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1067 if (f->split_parts && f->split_parts->nelts) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1068 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1069 part = f->split_parts->elts; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1070 size = u->buffer.pos - part_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1071 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1072 for (i = 0; i < f->split_parts->nelts; i++) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1073 size += part[i].end - part[i].start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1074 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1075 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1076 p = ngx_palloc(r->pool, size); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1077 if (p == NULL) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1078 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1079 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1080 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1081 buf.pos = p; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1082 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1083 for (i = 0; i < f->split_parts->nelts; i++) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1084 p = ngx_cpymem(p, part[i].start, |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1085 part[i].end - part[i].start); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1086 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1087 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1088 p = ngx_cpymem(p, part_start, u->buffer.pos - part_start); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1089 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1090 buf.last = p; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1091 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1092 f->split_parts->nelts = 0; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1093 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1094 rc = ngx_http_parse_header_line(r, &buf); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1095 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1096 h->key.len = r->header_name_end - r->header_name_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1097 h->key.data = r->header_name_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1098 h->key.data[h->key.len] = '\0'; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1099 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1100 h->value.len = r->header_end - r->header_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1101 h->value.data = r->header_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1102 h->value.data[h->value.len] = '\0'; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1103 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1104 h->lowcase_key = ngx_palloc(r->pool, h->key.len); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1105 if (h->lowcase_key == NULL) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1106 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1107 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1108 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1109 } else { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1110 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1111 h->key.len = r->header_name_end - r->header_name_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1112 h->value.len = r->header_end - r->header_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1113 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1114 h->key.data = ngx_palloc(r->pool, |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1115 h->key.len + 1 + h->value.len + 1 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1116 + h->key.len); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1117 if (h->key.data == NULL) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1118 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1119 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1120 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1121 h->value.data = h->key.data + h->key.len + 1; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1122 h->lowcase_key = h->key.data + h->key.len + 1 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1123 + h->value.len + 1; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1124 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1125 ngx_cpystrn(h->key.data, r->header_name_start, |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1126 h->key.len + 1); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1127 ngx_cpystrn(h->value.data, r->header_start, |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1128 h->value.len + 1); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1129 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1130 |
509 | 1131 h->hash = r->header_hash; |
1132 | |
649 | 1133 if (h->key.len == r->lowcase_index) { |
1134 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); | |
1135 | |
1136 } else { | |
1137 for (i = 0; i < h->key.len; i++) { | |
1488
0e66eabd18b5
the "proxy_hide_header" and "fastcgi_hide_header" directives did not
Igor Sysoev <igor@sysoev.ru>
parents:
1452
diff
changeset
|
1138 h->lowcase_key[i] = ngx_tolower(h->key.data[i]); |
479 | 1139 } |
1140 } | |
1141 | |
649 | 1142 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, |
1143 h->lowcase_key, h->key.len); | |
1144 | |
1145 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) { | |
1146 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1147 } | |
1148 | |
479 | 1149 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1150 "http fastcgi header: \"%V: %V\"", | |
1151 &h->key, &h->value); | |
1152 | |
615 | 1153 if (u->buffer.pos < u->buffer.last) { |
1154 continue; | |
1155 } | |
1156 | |
1157 /* the end of the FastCGI record */ | |
1158 | |
1159 break; | |
479 | 1160 } |
1161 | |
1162 if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | |
1163 | |
1164 /* a whole header has been parsed successfully */ | |
1165 | |
1166 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1167 "http fastcgi header done"); | |
1168 | |
509 | 1169 if (u->headers_in.status) { |
1170 status_line = &u->headers_in.status->value; | |
479 | 1171 |
1172 status = ngx_atoi(status_line->data, 3); | |
1173 | |
1174 if (status == NGX_ERROR) { | |
1175 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1176 } | |
1177 | |
529 | 1178 u->headers_in.status_n = status; |
1179 u->headers_in.status_line = *status_line; | |
479 | 1180 |
1181 } else { | |
529 | 1182 u->headers_in.status_n = 200; |
1183 u->headers_in.status_line.len = sizeof("200 OK") - 1; | |
1184 u->headers_in.status_line.data = (u_char *) "200 OK"; | |
479 | 1185 } |
1186 | |
529 | 1187 u->state->status = u->headers_in.status_n; |
479 | 1188 #if 0 |
1565 | 1189 if (u->cacheable) { |
1190 u->cacheable = ngx_http_upstream_is_cacheable(r); | |
479 | 1191 } |
1192 #endif | |
1193 | |
1194 break; | |
1195 } | |
1196 | |
1197 /* there was error while a header line parsing */ | |
1198 | |
1199 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
619 | 1200 "upstream sent invalid header"); |
479 | 1201 |
1202 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1203 } | |
1204 | |
1205 if (last) { | |
581 | 1206 u->buffer.last = last; |
479 | 1207 } |
1208 | |
581 | 1209 f->length -= u->buffer.pos - start; |
479 | 1210 |
1211 if (f->length == 0) { | |
1212 if (f->padding) { | |
1213 f->state = ngx_http_fastcgi_st_padding; | |
1214 } else { | |
1215 f->state = ngx_http_fastcgi_st_version; | |
1216 } | |
1217 } | |
1218 | |
615 | 1219 if (rc == NGX_HTTP_PARSE_HEADER_DONE) { |
1220 return NGX_OK; | |
1221 } | |
1222 | |
1274 | 1223 if (rc == NGX_OK) { |
615 | 1224 return NGX_AGAIN; |
1225 } | |
1226 | |
1274 | 1227 /* rc == NGX_AGAIN */ |
1228 | |
1276
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1229 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1230 "upstream split a header line in FastCGI records"); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1231 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1232 if (f->split_parts == NULL) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1233 f->split_parts = ngx_array_create(r->pool, 1, |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1234 sizeof(ngx_http_fastcgi_split_part_t)); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1235 if (f->split_parts == NULL) { |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1236 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1237 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1238 } |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1239 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1240 part = ngx_array_push(f->split_parts); |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1241 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1242 part->start = part_start; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1243 part->end = u->buffer.last; |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1244 |
1494a23b1ed4
fix headers split in FastCGI records
Igor Sysoev <igor@sysoev.ru>
parents:
1274
diff
changeset
|
1245 return NGX_AGAIN; |
479 | 1246 } |
1247 } | |
1248 | |
1249 | |
487 | 1250 static ngx_int_t |
1251 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) | |
479 | 1252 { |
1253 ngx_int_t rc; | |
483 | 1254 ngx_buf_t *b, **prev; |
479 | 1255 ngx_str_t line; |
1256 ngx_chain_t *cl; | |
1257 ngx_http_request_t *r; | |
1258 ngx_http_fastcgi_ctx_t *f; | |
1259 | |
1260 if (buf->pos == buf->last) { | |
1261 return NGX_OK; | |
1262 } | |
1263 | |
1264 r = p->input_ctx; | |
1265 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); | |
1266 | |
1267 b = NULL; | |
483 | 1268 prev = &buf->shadow; |
479 | 1269 |
1270 f->pos = buf->pos; | |
1271 f->last = buf->last; | |
1272 | |
1273 for ( ;; ) { | |
1274 if (f->state < ngx_http_fastcgi_st_data) { | |
1275 | |
1276 rc = ngx_http_fastcgi_process_record(r, f); | |
1277 | |
1278 if (rc == NGX_AGAIN) { | |
1279 break; | |
1280 } | |
1281 | |
1282 if (rc == NGX_ERROR) { | |
1283 return NGX_ERROR; | |
1284 } | |
1285 | |
1286 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) { | |
1287 f->state = ngx_http_fastcgi_st_version; | |
1288 p->upstream_done = 1; | |
1289 | |
1290 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0, | |
1291 "http fastcgi closed stdout"); | |
1292 | |
1293 continue; | |
1294 } | |
1295 | |
1296 if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) { | |
1297 f->state = ngx_http_fastcgi_st_version; | |
1298 p->upstream_done = 1; | |
1299 | |
1300 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0, | |
1301 "http fastcgi sent end request"); | |
1302 | |
1303 break; | |
1304 } | |
1305 } | |
1306 | |
1307 | |
1308 if (f->state == ngx_http_fastcgi_st_padding) { | |
1309 | |
1310 if (f->pos + f->padding < f->last) { | |
1311 f->state = ngx_http_fastcgi_st_version; | |
1312 f->pos += f->padding; | |
1313 | |
1314 continue; | |
1315 } | |
1316 | |
1317 if (f->pos + f->padding == f->last) { | |
1318 f->state = ngx_http_fastcgi_st_version; | |
1319 | |
1320 break; | |
1321 } | |
1322 | |
1323 f->padding -= f->last - f->pos; | |
1324 | |
1325 break; | |
1326 } | |
1327 | |
1328 | |
1329 /* f->state == ngx_http_fastcgi_st_data */ | |
1330 | |
1331 if (f->type == NGX_HTTP_FASTCGI_STDERR) { | |
1332 | |
1333 if (f->length) { | |
639 | 1334 |
1335 if (f->pos == f->last) { | |
1336 break; | |
1337 } | |
1338 | |
479 | 1339 line.data = f->pos; |
1340 | |
1341 if (f->pos + f->length <= f->last) { | |
1342 line.len = f->length; | |
1343 f->pos += f->length; | |
491 | 1344 f->length = 0; |
1345 f->state = ngx_http_fastcgi_st_padding; | |
479 | 1346 |
577 | 1347 } else { |
479 | 1348 line.len = f->last - f->pos; |
1349 f->length -= f->last - f->pos; | |
1350 f->pos = f->last; | |
1351 } | |
1352 | |
491 | 1353 while (line.data[line.len - 1] == LF |
1354 || line.data[line.len - 1] == CR | |
1355 || line.data[line.len - 1] == '.' | |
1356 || line.data[line.len - 1] == ' ') | |
1357 { | |
1358 line.len--; | |
1359 } | |
479 | 1360 |
1361 ngx_log_error(NGX_LOG_ERR, p->log, 0, | |
491 | 1362 "FastCGI sent in stderr: \"%V\"", &line); |
479 | 1363 |
1364 if (f->pos == f->last) { | |
1365 break; | |
1366 } | |
491 | 1367 |
1368 } else { | |
1369 f->state = ngx_http_fastcgi_st_version; | |
479 | 1370 } |
1371 | |
1372 continue; | |
1373 } | |
1374 | |
1375 | |
1376 /* f->type == NGX_HTTP_FASTCGI_STDOUT */ | |
1377 | |
639 | 1378 if (f->pos == f->last) { |
1379 break; | |
1380 } | |
1381 | |
479 | 1382 if (p->free) { |
1383 b = p->free->buf; | |
1384 p->free = p->free->next; | |
1385 | |
1386 } else { | |
501 | 1387 b = ngx_alloc_buf(p->pool); |
1388 if (b == NULL) { | |
479 | 1389 return NGX_ERROR; |
1390 } | |
1391 } | |
1392 | |
1393 ngx_memzero(b, sizeof(ngx_buf_t)); | |
1394 | |
1395 b->pos = f->pos; | |
483 | 1396 b->start = buf->start; |
1397 b->end = buf->end; | |
479 | 1398 b->tag = p->tag; |
1399 b->temporary = 1; | |
1400 b->recycled = 1; | |
483 | 1401 |
1402 *prev = b; | |
1403 prev = &b->shadow; | |
479 | 1404 |
501 | 1405 cl = ngx_alloc_chain_link(p->pool); |
1406 if (cl == NULL) { | |
479 | 1407 return NGX_ERROR; |
1408 } | |
1409 | |
1410 cl->buf = b; | |
1411 cl->next = NULL; | |
1412 | |
501 | 1413 if (p->in) { |
1414 *p->last_in = cl; | |
1415 } else { | |
1416 p->in = cl; | |
1417 } | |
1418 p->last_in = &cl->next; | |
1419 | |
1420 | |
483 | 1421 /* STUB */ b->num = buf->num; |
1422 | |
1030
5a86fcc480c6
add debug logging for FastCGI zero size buf alert
Igor Sysoev <igor@sysoev.ru>
parents:
906
diff
changeset
|
1423 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, |
1037 | 1424 "input buf #%d %p", b->num, b->pos); |
479 | 1425 |
1426 if (f->pos + f->length < f->last) { | |
1427 | |
1428 if (f->padding) { | |
1429 f->state = ngx_http_fastcgi_st_padding; | |
1430 } else { | |
1431 f->state = ngx_http_fastcgi_st_version; | |
1432 } | |
1433 | |
1434 f->pos += f->length; | |
1435 b->last = f->pos; | |
1436 | |
1437 continue; | |
1438 } | |
1439 | |
1440 if (f->pos + f->length == f->last) { | |
1441 | |
1442 if (f->padding) { | |
1443 f->state = ngx_http_fastcgi_st_padding; | |
1444 } else { | |
1445 f->state = ngx_http_fastcgi_st_version; | |
1446 } | |
1447 | |
1448 b->last = f->last; | |
1449 | |
1450 break; | |
1451 } | |
1452 | |
1453 f->length -= f->last - f->pos; | |
1454 | |
1455 b->last = f->last; | |
1456 | |
1457 break; | |
1458 | |
1459 } | |
1460 | |
1461 if (b) { | |
483 | 1462 b->shadow = buf; |
479 | 1463 b->last_shadow = 1; |
483 | 1464 |
1030
5a86fcc480c6
add debug logging for FastCGI zero size buf alert
Igor Sysoev <igor@sysoev.ru>
parents:
906
diff
changeset
|
1465 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, |
1037 | 1466 "input buf %p %z", b->pos, b->last - b->pos); |
1030
5a86fcc480c6
add debug logging for FastCGI zero size buf alert
Igor Sysoev <igor@sysoev.ru>
parents:
906
diff
changeset
|
1467 |
483 | 1468 return NGX_OK; |
1469 } | |
1470 | |
1471 /* there is no data record in the buf, add it to free chain */ | |
1472 | |
1473 if (ngx_event_pipe_add_free_buf(p, buf) != NGX_OK) { | |
1474 return NGX_ERROR; | |
479 | 1475 } |
1476 | |
1477 return NGX_OK; | |
1478 } | |
1479 | |
1480 | |
487 | 1481 static ngx_int_t |
1482 ngx_http_fastcgi_process_record(ngx_http_request_t *r, | |
1483 ngx_http_fastcgi_ctx_t *f) | |
479 | 1484 { |
1485 u_char ch, *p; | |
1486 ngx_http_fastcgi_state_e state; | |
1487 | |
1488 state = f->state; | |
1489 | |
1490 for (p = f->pos; p < f->last; p++) { | |
1491 | |
1492 ch = *p; | |
1493 | |
1494 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1495 "http fastcgi record byte: %02Xd", ch); | |
1496 | |
1497 switch (state) { | |
1498 | |
1499 case ngx_http_fastcgi_st_version: | |
1500 if (ch != 1) { | |
1501 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1502 "upstream sent unsupported FastCGI " | |
1503 "protocol version: %d", ch); | |
1504 return NGX_ERROR; | |
1505 } | |
1506 state = ngx_http_fastcgi_st_type; | |
1507 break; | |
1508 | |
1509 case ngx_http_fastcgi_st_type: | |
1510 switch (ch) { | |
1511 case NGX_HTTP_FASTCGI_STDOUT: | |
1512 case NGX_HTTP_FASTCGI_STDERR: | |
1513 case NGX_HTTP_FASTCGI_END_REQUEST: | |
1514 f->type = (ngx_uint_t) ch; | |
1515 break; | |
1516 default: | |
1517 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1518 "upstream sent invalid FastCGI " | |
1519 "record type: %d", ch); | |
1520 return NGX_ERROR; | |
1521 | |
1522 } | |
1523 state = ngx_http_fastcgi_st_request_id_hi; | |
1524 break; | |
1525 | |
1526 /* we support the single request per connection */ | |
1527 | |
1528 case ngx_http_fastcgi_st_request_id_hi: | |
1529 if (ch != 0) { | |
1530 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1531 "upstream sent unexpected FastCGI " | |
1532 "request id high byte: %d", ch); | |
1533 return NGX_ERROR; | |
1534 } | |
1535 state = ngx_http_fastcgi_st_request_id_lo; | |
1536 break; | |
1537 | |
1538 case ngx_http_fastcgi_st_request_id_lo: | |
1539 if (ch != 1) { | |
1540 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1541 "upstream sent unexpected FastCGI " | |
1542 "request id low byte: %d", ch); | |
1543 return NGX_ERROR; | |
1544 } | |
1545 state = ngx_http_fastcgi_st_content_length_hi; | |
1546 break; | |
1547 | |
1548 case ngx_http_fastcgi_st_content_length_hi: | |
1549 f->length = ch << 8; | |
1550 state = ngx_http_fastcgi_st_content_length_lo; | |
1551 break; | |
1552 | |
1553 case ngx_http_fastcgi_st_content_length_lo: | |
1554 f->length |= (size_t) ch; | |
1555 state = ngx_http_fastcgi_st_padding_length; | |
1556 break; | |
1557 | |
1558 case ngx_http_fastcgi_st_padding_length: | |
1559 f->padding = (size_t) ch; | |
1560 state = ngx_http_fastcgi_st_reserved; | |
1561 break; | |
1562 | |
1563 case ngx_http_fastcgi_st_reserved: | |
1564 state = ngx_http_fastcgi_st_data; | |
1565 | |
1566 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1567 "http fastcgi record length: %z", f->length); | |
1568 | |
1569 f->pos = p + 1; | |
1570 f->state = state; | |
1571 | |
1572 return NGX_OK; | |
1573 | |
1574 /* suppress warning */ | |
1575 case ngx_http_fastcgi_st_data: | |
1576 case ngx_http_fastcgi_st_padding: | |
1577 break; | |
1578 } | |
1579 } | |
1580 | |
1581 f->state = state; | |
1582 | |
1583 return NGX_AGAIN; | |
1584 } | |
1585 | |
1586 | |
487 | 1587 static void |
1588 ngx_http_fastcgi_abort_request(ngx_http_request_t *r) | |
479 | 1589 { |
1590 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1591 "abort http fastcgi request"); | |
1592 | |
1593 return; | |
1594 } | |
1595 | |
1596 | |
487 | 1597 static void |
1598 ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
479 | 1599 { |
1600 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1601 "finalize http fastcgi request"); | |
1602 | |
1603 return; | |
1604 } | |
1605 | |
1606 | |
509 | 1607 static ngx_int_t |
1608 ngx_http_fastcgi_add_variables(ngx_conf_t *cf) | |
479 | 1609 { |
509 | 1610 ngx_http_variable_t *var; |
479 | 1611 |
583 | 1612 var = ngx_http_add_variable(cf, &ngx_http_fastcgi_script_name, |
1565 | 1613 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE); |
509 | 1614 if (var == NULL) { |
1615 return NGX_ERROR; | |
479 | 1616 } |
1617 | |
637 | 1618 var->get_handler = ngx_http_fastcgi_script_name_variable; |
485 | 1619 |
509 | 1620 return NGX_OK; |
479 | 1621 } |
1622 | |
1623 | |
487 | 1624 static void * |
1625 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) | |
479 | 1626 { |
1627 ngx_http_fastcgi_loc_conf_t *conf; | |
1628 | |
501 | 1629 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t)); |
1630 if (conf == NULL) { | |
479 | 1631 return NGX_CONF_ERROR; |
1632 } | |
1633 | |
1634 /* | |
1635 * set by ngx_pcalloc(): | |
1636 * | |
1637 * conf->upstream.bufs.num = 0; | |
1638 * conf->upstream.next_upstream = 0; | |
1639 * conf->upstream.temp_path = NULL; | |
649 | 1640 * conf->upstream.hide_headers_hash = { NULL, 0 }; |
1641 * conf->upstream.hide_headers = NULL; | |
1642 * conf->upstream.pass_headers = NULL; | |
509 | 1643 * conf->upstream.schema = { 0, NULL }; |
1644 * conf->upstream.uri = { 0, NULL }; | |
1645 * conf->upstream.location = NULL; | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1646 * conf->upstream.store_lengths = NULL; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1647 * conf->upstream.store_values = NULL; |
509 | 1648 * |
479 | 1649 * conf->index.len = 0; |
1650 * conf->index.data = NULL; | |
1651 */ | |
1652 | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1653 conf->upstream.store = NGX_CONF_UNSET; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1654 conf->upstream.store_access = NGX_CONF_UNSET_UINT; |
581 | 1655 conf->upstream.buffering = NGX_CONF_UNSET; |
629 | 1656 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; |
581 | 1657 |
479 | 1658 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
1659 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
507 | 1660 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; |
1661 | |
479 | 1662 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; |
581 | 1663 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; |
529 | 1664 |
1665 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | |
577 | 1666 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; |
529 | 1667 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; |
509 | 1668 |
1669 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1670 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
1671 | |
657 | 1672 conf->upstream.intercept_errors = NGX_CONF_UNSET; |
479 | 1673 |
1674 /* "fastcgi_cyclic_temp_file" is disabled */ | |
1675 conf->upstream.cyclic_temp_file = 0; | |
1676 | |
1452
cd586e963db0
change ngx_conf_merge_ptr_value() and update fastcgi_catch_stderr
Igor Sysoev <igor@sysoev.ru>
parents:
1295
diff
changeset
|
1677 conf->catch_stderr = NGX_CONF_UNSET_PTR; |
cd586e963db0
change ngx_conf_merge_ptr_value() and update fastcgi_catch_stderr
Igor Sysoev <igor@sysoev.ru>
parents:
1295
diff
changeset
|
1678 |
479 | 1679 return conf; |
1680 } | |
1681 | |
1682 | |
487 | 1683 static char * |
1684 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
479 | 1685 { |
1686 ngx_http_fastcgi_loc_conf_t *prev = parent; | |
1687 ngx_http_fastcgi_loc_conf_t *conf = child; | |
1688 | |
509 | 1689 u_char *p; |
1690 size_t size; | |
1691 uintptr_t *code; | |
649 | 1692 ngx_str_t *header; |
1693 ngx_uint_t i, j; | |
1694 ngx_array_t hide_headers; | |
1695 ngx_keyval_t *src; | |
1696 ngx_hash_key_t *hk; | |
1697 ngx_hash_init_t hash; | |
509 | 1698 ngx_http_script_compile_t sc; |
1699 ngx_http_script_copy_code_t *copy; | |
479 | 1700 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1701 if (conf->upstream.store != 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1702 ngx_conf_merge_value(conf->upstream.store, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1703 prev->upstream.store, 0); |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1704 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1705 if (conf->upstream.store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1706 conf->upstream.store_lengths = prev->upstream.store_lengths; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1707 conf->upstream.store_values = prev->upstream.store_values; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1708 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1709 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1710 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1711 ngx_conf_merge_uint_value(conf->upstream.store_access, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1712 prev->upstream.store_access, 0600); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1276
diff
changeset
|
1713 |
581 | 1714 ngx_conf_merge_value(conf->upstream.buffering, |
1715 prev->upstream.buffering, 1); | |
1716 | |
629 | 1717 ngx_conf_merge_value(conf->upstream.ignore_client_abort, |
1718 prev->upstream.ignore_client_abort, 0); | |
1719 | |
479 | 1720 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
1721 prev->upstream.connect_timeout, 60000); | |
507 | 1722 |
479 | 1723 ngx_conf_merge_msec_value(conf->upstream.send_timeout, |
1724 prev->upstream.send_timeout, 60000); | |
1725 | |
1726 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1727 prev->upstream.read_timeout, 60000); | |
1728 | |
507 | 1729 ngx_conf_merge_size_value(conf->upstream.send_lowat, |
1730 prev->upstream.send_lowat, 0); | |
479 | 1731 |
581 | 1732 ngx_conf_merge_size_value(conf->upstream.buffer_size, |
1733 prev->upstream.buffer_size, | |
479 | 1734 (size_t) ngx_pagesize); |
1735 | |
507 | 1736 |
479 | 1737 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, |
1738 8, ngx_pagesize); | |
1739 | |
1740 if (conf->upstream.bufs.num < 2) { | |
1741 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1742 "there must be at least 2 \"fastcgi_buffers\""); | |
1743 return NGX_CONF_ERROR; | |
1744 } | |
1745 | |
1746 | |
581 | 1747 size = conf->upstream.buffer_size; |
479 | 1748 if (size < conf->upstream.bufs.size) { |
1749 size = conf->upstream.bufs.size; | |
1750 } | |
1751 | |
1752 | |
529 | 1753 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, |
1754 prev->upstream.busy_buffers_size_conf, | |
479 | 1755 NGX_CONF_UNSET_SIZE); |
1756 | |
529 | 1757 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { |
479 | 1758 conf->upstream.busy_buffers_size = 2 * size; |
529 | 1759 } else { |
1760 conf->upstream.busy_buffers_size = | |
1761 conf->upstream.busy_buffers_size_conf; | |
1762 } | |
479 | 1763 |
529 | 1764 if (conf->upstream.busy_buffers_size < size) { |
479 | 1765 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1766 "\"fastcgi_busy_buffers_size\" must be equal or bigger than " | |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1097
diff
changeset
|
1767 "maximum of the value of \"fastcgi_buffer_size\" and " |
479 | 1768 "one of the \"fastcgi_buffers\""); |
1769 | |
1770 return NGX_CONF_ERROR; | |
529 | 1771 } |
479 | 1772 |
529 | 1773 if (conf->upstream.busy_buffers_size |
1774 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
479 | 1775 { |
1776 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1777 "\"fastcgi_busy_buffers_size\" must be less than " | |
1778 "the size of all \"fastcgi_buffers\" minus one buffer"); | |
1779 | |
1780 return NGX_CONF_ERROR; | |
1781 } | |
1782 | |
1783 | |
529 | 1784 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, |
1785 prev->upstream.temp_file_write_size_conf, | |
479 | 1786 NGX_CONF_UNSET_SIZE); |
1787 | |
529 | 1788 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { |
479 | 1789 conf->upstream.temp_file_write_size = 2 * size; |
529 | 1790 } else { |
1791 conf->upstream.temp_file_write_size = | |
1792 conf->upstream.temp_file_write_size_conf; | |
1793 } | |
479 | 1794 |
529 | 1795 if (conf->upstream.temp_file_write_size < size) { |
479 | 1796 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1797 "\"fastcgi_temp_file_write_size\" must be equal or bigger than " | |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1097
diff
changeset
|
1798 "maximum of the value of \"fastcgi_buffer_size\" and " |
479 | 1799 "one of the \"fastcgi_buffers\""); |
1800 | |
1801 return NGX_CONF_ERROR; | |
1802 } | |
1803 | |
1804 | |
529 | 1805 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, |
1806 prev->upstream.max_temp_file_size_conf, | |
479 | 1807 NGX_CONF_UNSET_SIZE); |
1808 | |
529 | 1809 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { |
479 | 1810 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; |
529 | 1811 } else { |
1812 conf->upstream.max_temp_file_size = | |
1813 conf->upstream.max_temp_file_size_conf; | |
1814 } | |
479 | 1815 |
529 | 1816 if (conf->upstream.max_temp_file_size != 0 |
1817 && conf->upstream.max_temp_file_size < size) | |
479 | 1818 { |
1819 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1820 "\"fastcgi_max_temp_file_size\" must be equal to zero to disable " | |
1821 "the temporary files usage or must be equal or bigger than " | |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1097
diff
changeset
|
1822 "maximum of the value of \"fastcgi_buffer_size\" and " |
479 | 1823 "one of the \"fastcgi_buffers\""); |
1824 | |
1825 return NGX_CONF_ERROR; | |
1826 } | |
1827 | |
1828 | |
1829 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
487 | 1830 prev->upstream.next_upstream, |
1831 (NGX_CONF_BITMASK_SET | |
1832 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1833 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
479 | 1834 |
665 | 1835 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { |
1836 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1837 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1838 } | |
1839 | |
479 | 1840 ngx_conf_merge_path_value(conf->upstream.temp_path, |
1841 prev->upstream.temp_path, | |
1842 NGX_HTTP_FASTCGI_TEMP_PATH, 1, 2, 0, | |
1843 ngx_garbage_collector_temp_handler, cf); | |
1844 | |
509 | 1845 ngx_conf_merge_value(conf->upstream.pass_request_headers, |
1846 prev->upstream.pass_request_headers, 1); | |
1847 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1848 prev->upstream.pass_request_body, 1); | |
1849 | |
657 | 1850 ngx_conf_merge_value(conf->upstream.intercept_errors, |
1851 prev->upstream.intercept_errors, 0); | |
509 | 1852 |
1228 | 1853 ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL); |
1854 | |
507 | 1855 |
479 | 1856 ngx_conf_merge_str_value(conf->index, prev->index, ""); |
1857 | |
649 | 1858 if (conf->upstream.hide_headers == NULL |
1859 && conf->upstream.pass_headers == NULL) | |
1860 { | |
1861 conf->upstream.hide_headers = prev->upstream.hide_headers; | |
1862 conf->upstream.pass_headers = prev->upstream.pass_headers; | |
1863 conf->upstream.hide_headers_hash = prev->upstream.hide_headers_hash; | |
1864 | |
1865 if (conf->upstream.hide_headers_hash.buckets) { | |
1866 goto peers; | |
1867 } | |
1868 | |
1869 } else { | |
1870 if (conf->upstream.hide_headers == NULL) { | |
1871 conf->upstream.hide_headers = prev->upstream.hide_headers; | |
1872 } | |
1873 | |
1874 if (conf->upstream.pass_headers == NULL) { | |
1875 conf->upstream.pass_headers = prev->upstream.pass_headers; | |
1876 } | |
1877 } | |
1878 | |
1879 if (ngx_array_init(&hide_headers, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | |
1880 != NGX_OK) | |
1881 { | |
1882 return NGX_CONF_ERROR; | |
1883 } | |
1884 | |
1885 for (header = ngx_http_fastcgi_hide_headers; header->len; header++) { | |
1886 hk = ngx_array_push(&hide_headers); | |
1887 if (hk == NULL) { | |
1888 return NGX_CONF_ERROR; | |
1889 } | |
1890 | |
1891 hk->key = *header; | |
1892 hk->key_hash = ngx_hash_key_lc(header->data, header->len); | |
1893 hk->value = (void *) 1; | |
1894 } | |
1895 | |
1896 if (conf->upstream.hide_headers) { | |
1897 | |
1898 header = conf->upstream.hide_headers->elts; | |
1899 | |
1900 for (i = 0; i < conf->upstream.hide_headers->nelts; i++) { | |
1901 | |
1902 hk = hide_headers.elts; | |
1903 | |
1904 for (j = 0; j < hide_headers.nelts; j++) { | |
1905 if (ngx_strcasecmp(header[i].data, hk[j].key.data) == 0) { | |
1906 goto exist; | |
1907 } | |
1908 } | |
1909 | |
1910 hk = ngx_array_push(&hide_headers); | |
1911 if (hk == NULL) { | |
1912 return NGX_CONF_ERROR; | |
1913 } | |
1914 | |
1915 hk->key = header[i]; | |
1916 hk->key_hash = ngx_hash_key_lc(header[i].data, header[i].len); | |
1917 hk->value = (void *) 1; | |
1918 | |
1919 exist: | |
1920 | |
1921 continue; | |
1922 } | |
1923 } | |
1924 | |
1925 if (conf->upstream.pass_headers) { | |
1926 | |
1927 hk = hide_headers.elts; | |
1928 header = conf->upstream.pass_headers->elts; | |
1929 | |
1930 for (i = 0; i < conf->upstream.pass_headers->nelts; i++) { | |
1931 | |
1932 for (j = 0; j < hide_headers.nelts; j++) { | |
1933 | |
1934 if (hk[j].key.data == NULL) { | |
1935 continue; | |
1936 } | |
1937 | |
1938 if (ngx_strcasecmp(header[i].data, hk[j].key.data) == 0) { | |
1939 hk[j].key.data = NULL; | |
1940 break; | |
1941 } | |
1942 } | |
1943 } | |
1944 } | |
1945 | |
1946 hash.hash = &conf->upstream.hide_headers_hash; | |
1947 hash.key = ngx_hash_key_lc; | |
1948 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
1949 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 1950 hash.name = "fastcgi_hide_headers_hash"; |
1951 hash.pool = cf->pool; | |
1952 hash.temp_pool = NULL; | |
1953 | |
1954 if (ngx_hash_init(&hash, hide_headers.elts, hide_headers.nelts) != NGX_OK) { | |
1955 return NGX_CONF_ERROR; | |
1956 } | |
1957 | |
1958 peers: | |
1959 | |
884 | 1960 if (conf->upstream.upstream == NULL) { |
1961 conf->upstream.upstream = prev->upstream.upstream; | |
629 | 1962 conf->upstream.schema = prev->upstream.schema; |
507 | 1963 } |
1964 | |
509 | 1965 if (conf->params_source == NULL) { |
573 | 1966 conf->flushes = prev->flushes; |
509 | 1967 conf->params_len = prev->params_len; |
1968 conf->params = prev->params; | |
573 | 1969 conf->params_source = prev->params_source; |
509 | 1970 |
1971 if (conf->params_source == NULL) { | |
1972 return NGX_CONF_OK; | |
1973 } | |
1974 } | |
1975 | |
1976 conf->params_len = ngx_array_create(cf->pool, 64, 1); | |
1977 if (conf->params_len == NULL) { | |
1978 return NGX_CONF_ERROR; | |
1979 } | |
573 | 1980 |
509 | 1981 conf->params = ngx_array_create(cf->pool, 512, 1); |
1982 if (conf->params == NULL) { | |
1983 return NGX_CONF_ERROR; | |
1984 } | |
1985 | |
1986 src = conf->params_source->elts; | |
1987 for (i = 0; i < conf->params_source->nelts; i++) { | |
1988 | |
1989 if (ngx_http_script_variables_count(&src[i].value) == 0) { | |
1990 copy = ngx_array_push_n(conf->params_len, | |
1991 sizeof(ngx_http_script_copy_code_t)); | |
1992 if (copy == NULL) { | |
1993 return NGX_CONF_ERROR; | |
1994 } | |
1995 | |
1996 copy->code = (ngx_http_script_code_pt) | |
1997 ngx_http_script_copy_len_code; | |
1998 copy->len = src[i].key.len; | |
1999 | |
2000 | |
2001 copy = ngx_array_push_n(conf->params_len, | |
2002 sizeof(ngx_http_script_copy_code_t)); | |
2003 if (copy == NULL) { | |
2004 return NGX_CONF_ERROR; | |
2005 } | |
2006 | |
2007 copy->code = (ngx_http_script_code_pt) | |
2008 ngx_http_script_copy_len_code; | |
2009 copy->len = src[i].value.len; | |
2010 | |
2011 | |
2012 size = (sizeof(ngx_http_script_copy_code_t) | |
2013 + src[i].key.len + src[i].value.len | |
2014 + sizeof(uintptr_t) - 1) | |
2015 & ~(sizeof(uintptr_t) - 1); | |
2016 | |
2017 copy = ngx_array_push_n(conf->params, size); | |
2018 if (copy == NULL) { | |
2019 return NGX_CONF_ERROR; | |
2020 } | |
577 | 2021 |
509 | 2022 copy->code = ngx_http_script_copy_code; |
2023 copy->len = src[i].key.len + src[i].value.len; | |
2024 | |
2025 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2026 | |
2027 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2028 ngx_memcpy(p, src[i].value.data, src[i].value.len); | |
2029 | |
2030 } else { | |
2031 copy = ngx_array_push_n(conf->params_len, | |
2032 sizeof(ngx_http_script_copy_code_t)); | |
2033 if (copy == NULL) { | |
2034 return NGX_CONF_ERROR; | |
2035 } | |
2036 | |
2037 copy->code = (ngx_http_script_code_pt) | |
2038 ngx_http_script_copy_len_code; | |
2039 copy->len = src[i].key.len; | |
2040 | |
2041 | |
2042 size = (sizeof(ngx_http_script_copy_code_t) | |
2043 + src[i].key.len + sizeof(uintptr_t) - 1) | |
2044 & ~(sizeof(uintptr_t) - 1); | |
2045 | |
2046 copy = ngx_array_push_n(conf->params, size); | |
2047 if (copy == NULL) { | |
2048 return NGX_CONF_ERROR; | |
2049 } | |
577 | 2050 |
509 | 2051 copy->code = ngx_http_script_copy_code; |
2052 copy->len = src[i].key.len; | |
2053 | |
2054 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2055 ngx_memcpy(p, src[i].key.data, src[i].key.len); | |
2056 | |
2057 | |
2058 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2059 | |
2060 sc.cf = cf; | |
2061 sc.source = &src[i].value; | |
573 | 2062 sc.flushes = &conf->flushes; |
509 | 2063 sc.lengths = &conf->params_len; |
2064 sc.values = &conf->params; | |
2065 | |
2066 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2067 return NGX_CONF_ERROR; | |
2068 } | |
2069 } | |
2070 | |
2071 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
2072 if (code == NULL) { | |
2073 return NGX_CONF_ERROR; | |
2074 } | |
2075 | |
2076 *code = (uintptr_t) NULL; | |
2077 | |
2078 | |
2079 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | |
2080 if (code == NULL) { | |
2081 return NGX_CONF_ERROR; | |
2082 } | |
2083 | |
2084 *code = (uintptr_t) NULL; | |
2085 } | |
2086 | |
2087 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
2088 if (code == NULL) { | |
2089 return NGX_CONF_ERROR; | |
2090 } | |
2091 | |
2092 *code = (uintptr_t) NULL; | |
2093 | |
479 | 2094 return NGX_CONF_OK; |
2095 } | |
509 | 2096 |
2097 | |
573 | 2098 static ngx_int_t |
2099 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, | |
2100 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 2101 { |
2102 u_char *p; | |
2103 ngx_http_fastcgi_loc_conf_t *flcf; | |
2104 | |
1097
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2105 if (r->uri.len) { |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2106 v->valid = 1; |
1565 | 2107 v->no_cacheable = 0; |
1097
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2108 v->not_found = 0; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2109 |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2110 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2111 |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2112 if (r->uri.data[r->uri.len - 1] != '/') { |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2113 v->len = r->uri.len; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2114 v->data = r->uri.data; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2115 return NGX_OK; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2116 } |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2117 |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2118 v->len = r->uri.len + flcf->index.len; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2119 |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2120 v->data = ngx_palloc(r->pool, v->len); |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2121 if (v->data == NULL) { |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2122 return NGX_ERROR; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2123 } |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2124 |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2125 p = ngx_copy(v->data, r->uri.data, r->uri.len); |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2126 ngx_memcpy(p, flcf->index.data, flcf->index.len); |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2127 |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2128 } else { |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2129 v->len = 0; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2130 v->valid = 1; |
1565 | 2131 v->no_cacheable = 0; |
1097
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2132 v->not_found = 0; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2133 v->data = NULL; |
df8cdf626c87
fix segfault when $fastcgi_script_name is used in access_log
Igor Sysoev <igor@sysoev.ru>
parents:
1037
diff
changeset
|
2134 |
573 | 2135 return NGX_OK; |
509 | 2136 } |
2137 | |
573 | 2138 return NGX_OK; |
509 | 2139 } |
2140 | |
2141 | |
2142 static char * | |
2143 ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2144 { | |
2145 ngx_http_fastcgi_loc_conf_t *lcf = conf; | |
2146 | |
651 | 2147 ngx_url_t u; |
509 | 2148 ngx_str_t *value; |
2149 ngx_http_core_loc_conf_t *clcf; | |
2150 | |
555 | 2151 if (lcf->upstream.schema.len) { |
2152 return "is duplicate"; | |
2153 } | |
2154 | |
509 | 2155 value = cf->args->elts; |
2156 | |
651 | 2157 ngx_memzero(&u, sizeof(ngx_url_t)); |
2158 | |
2159 u.url = value[1]; | |
884 | 2160 u.no_resolve = 1; |
2161 | |
2162 lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); | |
2163 if (lcf->upstream.upstream == NULL) { | |
509 | 2164 return NGX_CONF_ERROR; |
2165 } | |
2166 | |
2167 lcf->upstream.schema.len = sizeof("fastcgi://") - 1; | |
2168 lcf->upstream.schema.data = (u_char *) "fastcgi://"; | |
2169 | |
2170 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
2171 | |
2172 clcf->handler = ngx_http_fastcgi_handler; | |
2173 | |
573 | 2174 lcf->upstream.location = clcf->name; |
509 | 2175 |
2176 if (clcf->name.data[clcf->name.len - 1] == '/') { | |
2177 clcf->auto_redirect = 1; | |
2178 } | |
2179 | |
2180 return NGX_CONF_OK; | |
2181 } | |
2182 | |
2183 | |
2184 static char * | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2185 ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2186 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2187 ngx_http_fastcgi_loc_conf_t *flcf = conf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2188 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2189 ngx_str_t *value; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2190 ngx_http_script_compile_t sc; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2191 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2192 if (flcf->upstream.store != NGX_CONF_UNSET || flcf->upstream.store_lengths) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2193 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2194 return "is duplicate"; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2195 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2196 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2197 value = cf->args->elts; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2198 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2199 if (ngx_strcmp(value[1].data, "on") == 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2200 flcf->upstream.store = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2201 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2202 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2203 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2204 if (ngx_strcmp(value[1].data, "off") == 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2205 flcf->upstream.store = 0; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2206 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2207 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2208 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2209 /* include the terminating '\0' into script */ |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2210 value[1].len++; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2211 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2212 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2213 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2214 sc.cf = cf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2215 sc.source = &value[1]; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2216 sc.lengths = &flcf->upstream.store_lengths; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2217 sc.values = &flcf->upstream.store_values; |
1563
022ec9420f80
style fix: remove double semicolons
Igor Sysoev <igor@sysoev.ru>
parents:
1488
diff
changeset
|
2218 sc.variables = ngx_http_script_variables_count(&value[1]); |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2219 sc.complete_lengths = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2220 sc.complete_values = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2221 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2222 if (ngx_http_script_compile(&sc) != NGX_OK) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2223 return NGX_CONF_ERROR; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2224 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2225 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2226 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2227 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2228 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2229 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2230 static char * |
509 | 2231 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data) |
2232 { | |
2233 #if (NGX_FREEBSD) | |
2234 ssize_t *np = data; | |
2235 | |
673 | 2236 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) { |
509 | 2237 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2238 "\"fastcgi_send_lowat\" must be less than %d " | |
2239 "(sysctl net.inet.tcp.sendspace)", | |
2240 ngx_freebsd_net_inet_tcp_sendspace); | |
2241 | |
2242 return NGX_CONF_ERROR; | |
2243 } | |
2244 | |
2245 #elif !(NGX_HAVE_SO_SNDLOWAT) | |
2246 ssize_t *np = data; | |
2247 | |
2248 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2249 "\"fastcgi_send_lowat\" is not supported, ignored"); | |
2250 | |
2251 *np = 0; | |
2252 | |
2253 #endif | |
2254 | |
2255 return NGX_CONF_OK; | |
2256 } | |
884 | 2257 |
2258 | |
2259 static char * | |
2260 ngx_http_fastcgi_upstream_max_fails_unsupported(ngx_conf_t *cf, | |
2261 ngx_command_t *cmd, void *conf) | |
2262 { | |
2263 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2264 "\"fastcgi_upstream_max_fails\" is not supported, " | |
2265 "use the \"max_fails\" parameter of the \"server\" directive ", | |
2266 "inside the \"upstream\" block"); | |
2267 | |
2268 return NGX_CONF_ERROR; | |
2269 } | |
2270 | |
2271 | |
2272 static char * | |
2273 ngx_http_fastcgi_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
2274 ngx_command_t *cmd, void *conf) | |
2275 { | |
2276 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2277 "\"fastcgi_upstream_fail_timeout\" is not supported, " | |
2278 "use the \"fail_timeout\" parameter of the \"server\" directive ", | |
2279 "inside the \"upstream\" block"); | |
2280 | |
2281 return NGX_CONF_ERROR; | |
2282 } |