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