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