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