50
|
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
|
|
11
|
|
12 typedef struct {
|
200
|
13 ngx_http_upstream_conf_t upstream;
|
|
14
|
|
15 ngx_str_t index;
|
|
16
|
|
17 ngx_array_t *flushes;
|
|
18 ngx_array_t *params_len;
|
|
19 ngx_array_t *params;
|
|
20 ngx_array_t *params_source;
|
306
|
21 ngx_array_t *catch_stderr;
|
430
|
22
|
|
23 ngx_array_t *fastcgi_lengths;
|
|
24 ngx_array_t *fastcgi_values;
|
438
|
25
|
576
|
26 ngx_hash_t headers_hash;
|
|
27 ngx_uint_t header_params;
|
|
28
|
640
|
29 ngx_flag_t keep_conn;
|
|
30
|
466
|
31 #if (NGX_HTTP_CACHE)
|
|
32 ngx_http_complex_value_t cache_key;
|
|
33 #endif
|
|
34
|
438
|
35 #if (NGX_PCRE)
|
|
36 ngx_regex_t *split_regex;
|
|
37 ngx_str_t split_name;
|
|
38 #endif
|
50
|
39 } ngx_http_fastcgi_loc_conf_t;
|
|
40
|
|
41
|
|
42 typedef enum {
|
|
43 ngx_http_fastcgi_st_version = 0,
|
|
44 ngx_http_fastcgi_st_type,
|
|
45 ngx_http_fastcgi_st_request_id_hi,
|
|
46 ngx_http_fastcgi_st_request_id_lo,
|
|
47 ngx_http_fastcgi_st_content_length_hi,
|
|
48 ngx_http_fastcgi_st_content_length_lo,
|
|
49 ngx_http_fastcgi_st_padding_length,
|
|
50 ngx_http_fastcgi_st_reserved,
|
|
51 ngx_http_fastcgi_st_data,
|
64
|
52 ngx_http_fastcgi_st_padding
|
50
|
53 } ngx_http_fastcgi_state_e;
|
|
54
|
|
55
|
|
56 typedef struct {
|
316
|
57 u_char *start;
|
|
58 u_char *end;
|
|
59 } ngx_http_fastcgi_split_part_t;
|
|
60
|
|
61
|
|
62 typedef struct {
|
200
|
63 ngx_http_fastcgi_state_e state;
|
|
64 u_char *pos;
|
|
65 u_char *last;
|
|
66 ngx_uint_t type;
|
|
67 size_t length;
|
|
68 size_t padding;
|
|
69
|
564
|
70 unsigned fastcgi_stdout:1;
|
|
71 unsigned large_stderr:1;
|
316
|
72
|
|
73 ngx_array_t *split_parts;
|
438
|
74
|
|
75 ngx_str_t script_name;
|
|
76 ngx_str_t path_info;
|
50
|
77 } ngx_http_fastcgi_ctx_t;
|
|
78
|
|
79
|
|
80 #define NGX_HTTP_FASTCGI_RESPONDER 1
|
|
81
|
640
|
82 #define NGX_HTTP_FASTCGI_KEEP_CONN 1
|
|
83
|
50
|
84 #define NGX_HTTP_FASTCGI_BEGIN_REQUEST 1
|
|
85 #define NGX_HTTP_FASTCGI_ABORT_REQUEST 2
|
|
86 #define NGX_HTTP_FASTCGI_END_REQUEST 3
|
|
87 #define NGX_HTTP_FASTCGI_PARAMS 4
|
|
88 #define NGX_HTTP_FASTCGI_STDIN 5
|
|
89 #define NGX_HTTP_FASTCGI_STDOUT 6
|
|
90 #define NGX_HTTP_FASTCGI_STDERR 7
|
|
91 #define NGX_HTTP_FASTCGI_DATA 8
|
|
92
|
|
93
|
|
94 typedef struct {
|
|
95 u_char version;
|
|
96 u_char type;
|
|
97 u_char request_id_hi;
|
|
98 u_char request_id_lo;
|
|
99 u_char content_length_hi;
|
|
100 u_char content_length_lo;
|
|
101 u_char padding_length;
|
|
102 u_char reserved;
|
|
103 } ngx_http_fastcgi_header_t;
|
|
104
|
|
105
|
|
106 typedef struct {
|
|
107 u_char role_hi;
|
|
108 u_char role_lo;
|
|
109 u_char flags;
|
|
110 u_char reserved[5];
|
|
111 } ngx_http_fastcgi_begin_request_t;
|
|
112
|
|
113
|
58
|
114 typedef struct {
|
|
115 u_char version;
|
|
116 u_char type;
|
|
117 u_char request_id_hi;
|
|
118 u_char request_id_lo;
|
|
119 } ngx_http_fastcgi_header_small_t;
|
|
120
|
|
121
|
|
122 typedef struct {
|
|
123 ngx_http_fastcgi_header_t h0;
|
|
124 ngx_http_fastcgi_begin_request_t br;
|
|
125 ngx_http_fastcgi_header_small_t h1;
|
|
126 } ngx_http_fastcgi_request_start_t;
|
|
127
|
|
128
|
430
|
129 static ngx_int_t ngx_http_fastcgi_eval(ngx_http_request_t *r,
|
|
130 ngx_http_fastcgi_loc_conf_t *flcf);
|
466
|
131 #if (NGX_HTTP_CACHE)
|
|
132 static ngx_int_t ngx_http_fastcgi_create_key(ngx_http_request_t *r);
|
|
133 #endif
|
50
|
134 static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r);
|
|
135 static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r);
|
|
136 static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r);
|
640
|
137 static ngx_int_t ngx_http_fastcgi_input_filter_init(void *data);
|
50
|
138 static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
|
|
139 ngx_buf_t *buf);
|
|
140 static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
|
|
141 ngx_http_fastcgi_ctx_t *f);
|
|
142 static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r);
|
|
143 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
|
|
144 ngx_int_t rc);
|
|
145
|
58
|
146 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf);
|
|
147 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
|
|
148 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
|
|
149 void *parent, void *child);
|
648
|
150 static ngx_int_t ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
|
|
151 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev);
|
|
152
|
122
|
153 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
|
|
154 ngx_http_variable_value_t *v, uintptr_t data);
|
438
|
155 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
|
156 ngx_http_variable_value_t *v, uintptr_t data);
|
440
|
157 static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r,
|
|
158 ngx_http_fastcgi_loc_conf_t *flcf);
|
58
|
159
|
50
|
160 static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
161 void *conf);
|
438
|
162 static char *ngx_http_fastcgi_split_path_info(ngx_conf_t *cf,
|
|
163 ngx_command_t *cmd, void *conf);
|
320
|
164 static char *ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
165 void *conf);
|
466
|
166 #if (NGX_HTTP_CACHE)
|
|
167 static char *ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
168 void *conf);
|
|
169 static char *ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
170 void *conf);
|
|
171 #endif
|
|
172
|
50
|
173 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
|
|
174 void *data);
|
|
175
|
|
176
|
58
|
177 static ngx_conf_post_t ngx_http_fastcgi_lowat_post =
|
|
178 { ngx_http_fastcgi_lowat_check };
|
50
|
179
|
|
180
|
|
181 static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = {
|
|
182 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
|
|
183 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
|
|
184 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
|
|
185 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
|
172
|
186 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
|
50
|
187 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
|
498
|
188 { ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
|
214
|
189 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
|
50
|
190 { ngx_null_string, 0 }
|
|
191 };
|
|
192
|
|
193
|
466
|
194 ngx_module_t ngx_http_fastcgi_module;
|
|
195
|
|
196
|
50
|
197 static ngx_command_t ngx_http_fastcgi_commands[] = {
|
|
198
|
|
199 { ngx_string("fastcgi_pass"),
|
178
|
200 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
50
|
201 ngx_http_fastcgi_pass,
|
|
202 NGX_HTTP_LOC_CONF_OFFSET,
|
|
203 0,
|
|
204 NULL },
|
|
205
|
|
206 { ngx_string("fastcgi_index"),
|
|
207 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
208 ngx_conf_set_str_slot,
|
|
209 NGX_HTTP_LOC_CONF_OFFSET,
|
|
210 offsetof(ngx_http_fastcgi_loc_conf_t, index),
|
|
211 NULL },
|
|
212
|
438
|
213 { ngx_string("fastcgi_split_path_info"),
|
|
214 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
215 ngx_http_fastcgi_split_path_info,
|
|
216 NGX_HTTP_LOC_CONF_OFFSET,
|
|
217 0,
|
|
218 NULL },
|
|
219
|
318
|
220 { ngx_string("fastcgi_store"),
|
320
|
221 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
222 ngx_http_fastcgi_store,
|
|
223 NGX_HTTP_LOC_CONF_OFFSET,
|
|
224 0,
|
|
225 NULL },
|
|
226
|
|
227 { ngx_string("fastcgi_store_access"),
|
318
|
228 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
|
|
229 ngx_conf_set_access_slot,
|
|
230 NGX_HTTP_LOC_CONF_OFFSET,
|
320
|
231 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.store_access),
|
318
|
232 NULL },
|
|
233
|
178
|
234 { ngx_string("fastcgi_ignore_client_abort"),
|
|
235 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
236 ngx_conf_set_flag_slot,
|
|
237 NGX_HTTP_LOC_CONF_OFFSET,
|
|
238 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_client_abort),
|
|
239 NULL },
|
|
240
|
540
|
241 { ngx_string("fastcgi_bind"),
|
|
242 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
558
|
243 ngx_http_upstream_bind_set_slot,
|
540
|
244 NGX_HTTP_LOC_CONF_OFFSET,
|
|
245 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.local),
|
|
246 NULL },
|
|
247
|
50
|
248 { ngx_string("fastcgi_connect_timeout"),
|
|
249 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
250 ngx_conf_set_msec_slot,
|
|
251 NGX_HTTP_LOC_CONF_OFFSET,
|
|
252 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.connect_timeout),
|
|
253 NULL },
|
|
254
|
|
255 { ngx_string("fastcgi_send_timeout"),
|
|
256 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
257 ngx_conf_set_msec_slot,
|
|
258 NGX_HTTP_LOC_CONF_OFFSET,
|
|
259 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_timeout),
|
|
260 NULL },
|
|
261
|
|
262 { ngx_string("fastcgi_send_lowat"),
|
|
263 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
264 ngx_conf_set_size_slot,
|
|
265 NGX_HTTP_LOC_CONF_OFFSET,
|
|
266 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.send_lowat),
|
|
267 &ngx_http_fastcgi_lowat_post },
|
|
268
|
130
|
269 { ngx_string("fastcgi_buffer_size"),
|
|
270 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
271 ngx_conf_set_size_slot,
|
|
272 NGX_HTTP_LOC_CONF_OFFSET,
|
|
273 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.buffer_size),
|
|
274 NULL },
|
|
275
|
58
|
276 { ngx_string("fastcgi_pass_request_headers"),
|
|
277 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
278 ngx_conf_set_flag_slot,
|
|
279 NGX_HTTP_LOC_CONF_OFFSET,
|
|
280 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_headers),
|
|
281 NULL },
|
|
282
|
|
283 { ngx_string("fastcgi_pass_request_body"),
|
|
284 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
285 ngx_conf_set_flag_slot,
|
|
286 NGX_HTTP_LOC_CONF_OFFSET,
|
|
287 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_body),
|
|
288 NULL },
|
|
289
|
206
|
290 { ngx_string("fastcgi_intercept_errors"),
|
|
291 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
292 ngx_conf_set_flag_slot,
|
|
293 NGX_HTTP_LOC_CONF_OFFSET,
|
|
294 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.intercept_errors),
|
|
295 NULL },
|
|
296
|
50
|
297 { ngx_string("fastcgi_read_timeout"),
|
|
298 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
299 ngx_conf_set_msec_slot,
|
|
300 NGX_HTTP_LOC_CONF_OFFSET,
|
|
301 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.read_timeout),
|
|
302 NULL },
|
|
303
|
|
304 { ngx_string("fastcgi_buffers"),
|
|
305 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
|
306 ngx_conf_set_bufs_slot,
|
|
307 NGX_HTTP_LOC_CONF_OFFSET,
|
|
308 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.bufs),
|
|
309 NULL },
|
|
310
|
|
311 { ngx_string("fastcgi_busy_buffers_size"),
|
|
312 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
313 ngx_conf_set_size_slot,
|
|
314 NGX_HTTP_LOC_CONF_OFFSET,
|
78
|
315 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.busy_buffers_size_conf),
|
50
|
316 NULL },
|
|
317
|
466
|
318 #if (NGX_HTTP_CACHE)
|
|
319
|
|
320 { ngx_string("fastcgi_cache"),
|
592
|
321 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
466
|
322 ngx_http_fastcgi_cache,
|
|
323 NGX_HTTP_LOC_CONF_OFFSET,
|
|
324 0,
|
|
325 NULL },
|
|
326
|
|
327 { ngx_string("fastcgi_cache_key"),
|
592
|
328 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
466
|
329 ngx_http_fastcgi_cache_key,
|
|
330 NGX_HTTP_LOC_CONF_OFFSET,
|
|
331 0,
|
|
332 NULL },
|
|
333
|
|
334 { ngx_string("fastcgi_cache_path"),
|
|
335 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
|
|
336 ngx_http_file_cache_set_slot,
|
|
337 0,
|
|
338 0,
|
|
339 &ngx_http_fastcgi_module },
|
|
340
|
588
|
341 { ngx_string("fastcgi_cache_bypass"),
|
|
342 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
343 ngx_http_set_predicate_slot,
|
|
344 NGX_HTTP_LOC_CONF_OFFSET,
|
|
345 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_bypass),
|
|
346 NULL },
|
|
347
|
572
|
348 { ngx_string("fastcgi_no_cache"),
|
|
349 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
588
|
350 ngx_http_set_predicate_slot,
|
572
|
351 NGX_HTTP_LOC_CONF_OFFSET,
|
|
352 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.no_cache),
|
|
353 NULL },
|
|
354
|
466
|
355 { ngx_string("fastcgi_cache_valid"),
|
|
356 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
357 ngx_http_file_cache_valid_set_slot,
|
|
358 NGX_HTTP_LOC_CONF_OFFSET,
|
|
359 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_valid),
|
|
360 NULL },
|
|
361
|
482
|
362 { ngx_string("fastcgi_cache_min_uses"),
|
466
|
363 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
364 ngx_conf_set_num_slot,
|
|
365 NGX_HTTP_LOC_CONF_OFFSET,
|
|
366 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_min_uses),
|
|
367 NULL },
|
|
368
|
|
369 { ngx_string("fastcgi_cache_use_stale"),
|
|
370 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
371 ngx_conf_set_bitmask_slot,
|
|
372 NGX_HTTP_LOC_CONF_OFFSET,
|
|
373 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_use_stale),
|
|
374 &ngx_http_fastcgi_next_upstream_masks },
|
|
375
|
494
|
376 { ngx_string("fastcgi_cache_methods"),
|
|
377 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
378 ngx_conf_set_bitmask_slot,
|
|
379 NGX_HTTP_LOC_CONF_OFFSET,
|
|
380 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_methods),
|
|
381 &ngx_http_upstream_cache_method_mask },
|
|
382
|
466
|
383 #endif
|
|
384
|
50
|
385 { ngx_string("fastcgi_temp_path"),
|
|
386 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
|
|
387 ngx_conf_set_path_slot,
|
|
388 NGX_HTTP_LOC_CONF_OFFSET,
|
|
389 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_path),
|
464
|
390 NULL },
|
50
|
391
|
|
392 { ngx_string("fastcgi_max_temp_file_size"),
|
|
393 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
394 ngx_conf_set_size_slot,
|
|
395 NGX_HTTP_LOC_CONF_OFFSET,
|
78
|
396 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.max_temp_file_size_conf),
|
50
|
397 NULL },
|
|
398
|
|
399 { ngx_string("fastcgi_temp_file_write_size"),
|
|
400 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
401 ngx_conf_set_size_slot,
|
|
402 NGX_HTTP_LOC_CONF_OFFSET,
|
78
|
403 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.temp_file_write_size_conf),
|
50
|
404 NULL },
|
|
405
|
|
406 { ngx_string("fastcgi_next_upstream"),
|
96
|
407 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
50
|
408 ngx_conf_set_bitmask_slot,
|
|
409 NGX_HTTP_LOC_CONF_OFFSET,
|
|
410 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream),
|
|
411 &ngx_http_fastcgi_next_upstream_masks },
|
|
412
|
58
|
413 { ngx_string("fastcgi_param"),
|
|
414 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
|
198
|
415 ngx_conf_set_keyval_slot,
|
50
|
416 NGX_HTTP_LOC_CONF_OFFSET,
|
58
|
417 offsetof(ngx_http_fastcgi_loc_conf_t, params_source),
|
50
|
418 NULL },
|
|
419
|
198
|
420 { ngx_string("fastcgi_pass_header"),
|
592
|
421 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
198
|
422 ngx_conf_set_str_array_slot,
|
|
423 NGX_HTTP_LOC_CONF_OFFSET,
|
|
424 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_headers),
|
|
425 NULL },
|
|
426
|
|
427 { ngx_string("fastcgi_hide_header"),
|
592
|
428 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
198
|
429 ngx_conf_set_str_array_slot,
|
|
430 NGX_HTTP_LOC_CONF_OFFSET,
|
|
431 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.hide_headers),
|
|
432 NULL },
|
|
433
|
484
|
434 { ngx_string("fastcgi_ignore_headers"),
|
|
435 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
436 ngx_conf_set_bitmask_slot,
|
|
437 NGX_HTTP_LOC_CONF_OFFSET,
|
|
438 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_headers),
|
584
|
439 &ngx_http_upstream_ignore_headers_masks },
|
484
|
440
|
306
|
441 { ngx_string("fastcgi_catch_stderr"),
|
648
|
442 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
306
|
443 ngx_conf_set_str_array_slot,
|
|
444 NGX_HTTP_LOC_CONF_OFFSET,
|
|
445 offsetof(ngx_http_fastcgi_loc_conf_t, catch_stderr),
|
|
446 NULL },
|
|
447
|
640
|
448 { ngx_string("fastcgi_keep_conn"),
|
|
449 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
450 ngx_conf_set_flag_slot,
|
|
451 NGX_HTTP_LOC_CONF_OFFSET,
|
|
452 offsetof(ngx_http_fastcgi_loc_conf_t, keep_conn),
|
|
453 NULL },
|
|
454
|
50
|
455 ngx_null_command
|
|
456 };
|
|
457
|
|
458
|
216
|
459 static ngx_http_module_t ngx_http_fastcgi_module_ctx = {
|
58
|
460 ngx_http_fastcgi_add_variables, /* preconfiguration */
|
|
461 NULL, /* postconfiguration */
|
50
|
462
|
|
463 NULL, /* create main configuration */
|
|
464 NULL, /* init main configuration */
|
|
465
|
|
466 NULL, /* create server configuration */
|
|
467 NULL, /* merge server configuration */
|
|
468
|
|
469 ngx_http_fastcgi_create_loc_conf, /* create location configuration */
|
|
470 ngx_http_fastcgi_merge_loc_conf /* merge location configuration */
|
|
471 };
|
|
472
|
|
473
|
|
474 ngx_module_t ngx_http_fastcgi_module = {
|
58
|
475 NGX_MODULE_V1,
|
50
|
476 &ngx_http_fastcgi_module_ctx, /* module context */
|
|
477 ngx_http_fastcgi_commands, /* module directives */
|
|
478 NGX_HTTP_MODULE, /* module type */
|
90
|
479 NULL, /* init master */
|
50
|
480 NULL, /* init module */
|
90
|
481 NULL, /* init process */
|
|
482 NULL, /* init thread */
|
|
483 NULL, /* exit thread */
|
|
484 NULL, /* exit process */
|
|
485 NULL, /* exit master */
|
|
486 NGX_MODULE_V1_PADDING
|
50
|
487 };
|
|
488
|
|
489
|
364
|
490 static ngx_http_fastcgi_request_start_t ngx_http_fastcgi_request_start = {
|
|
491 { 1, /* version */
|
|
492 NGX_HTTP_FASTCGI_BEGIN_REQUEST, /* type */
|
|
493 0, /* request_id_hi */
|
|
494 1, /* request_id_lo */
|
|
495 0, /* content_length_hi */
|
|
496 sizeof(ngx_http_fastcgi_begin_request_t), /* content_length_lo */
|
|
497 0, /* padding_length */
|
|
498 0 }, /* reserved */
|
|
499
|
|
500 { 0, /* role_hi */
|
|
501 NGX_HTTP_FASTCGI_RESPONDER, /* role_lo */
|
|
502 0, /* NGX_HTTP_FASTCGI_KEEP_CONN */ /* flags */
|
|
503 { 0, 0, 0, 0, 0 } }, /* reserved[5] */
|
|
504
|
|
505 { 1, /* version */
|
|
506 NGX_HTTP_FASTCGI_PARAMS, /* type */
|
|
507 0, /* request_id_hi */
|
|
508 1 }, /* request_id_lo */
|
|
509
|
|
510 };
|
|
511
|
|
512
|
438
|
513 static ngx_http_variable_t ngx_http_fastcgi_vars[] = {
|
|
514
|
|
515 { ngx_string("fastcgi_script_name"), NULL,
|
|
516 ngx_http_fastcgi_script_name_variable, 0,
|
|
517 NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
518
|
|
519 { ngx_string("fastcgi_path_info"), NULL,
|
|
520 ngx_http_fastcgi_path_info_variable, 0,
|
|
521 NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
522
|
|
523 { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
|
524 };
|
364
|
525
|
|
526
|
198
|
527 static ngx_str_t ngx_http_fastcgi_hide_headers[] = {
|
|
528 ngx_string("Status"),
|
|
529 ngx_string("X-Accel-Expires"),
|
|
530 ngx_string("X-Accel-Redirect"),
|
|
531 ngx_string("X-Accel-Limit-Rate"),
|
364
|
532 ngx_string("X-Accel-Buffering"),
|
|
533 ngx_string("X-Accel-Charset"),
|
198
|
534 ngx_null_string
|
|
535 };
|
|
536
|
|
537
|
536
|
538 #if (NGX_HTTP_CACHE)
|
|
539
|
576
|
540 static ngx_keyval_t ngx_http_fastcgi_cache_headers[] = {
|
|
541 { ngx_string("HTTP_IF_MODIFIED_SINCE"), ngx_string("") },
|
|
542 { ngx_string("HTTP_IF_UNMODIFIED_SINCE"), ngx_string("") },
|
|
543 { ngx_string("HTTP_IF_NONE_MATCH"), ngx_string("") },
|
|
544 { ngx_string("HTTP_IF_MATCH"), ngx_string("") },
|
|
545 { ngx_string("HTTP_RANGE"), ngx_string("") },
|
|
546 { ngx_string("HTTP_IF_RANGE"), ngx_string("") },
|
|
547 { ngx_null_string, ngx_null_string }
|
|
548 };
|
|
549
|
536
|
550 #endif
|
|
551
|
|
552
|
464
|
553 static ngx_path_init_t ngx_http_fastcgi_temp_path = {
|
|
554 ngx_string(NGX_HTTP_FASTCGI_TEMP_PATH), { 1, 2, 0 }
|
|
555 };
|
|
556
|
|
557
|
50
|
558 static ngx_int_t
|
|
559 ngx_http_fastcgi_handler(ngx_http_request_t *r)
|
|
560 {
|
|
561 ngx_int_t rc;
|
|
562 ngx_http_upstream_t *u;
|
438
|
563 ngx_http_fastcgi_ctx_t *f;
|
50
|
564 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
565
|
248
|
566 if (r->subrequest_in_memory) {
|
|
567 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
568 "ngx_http_fastcgi_module does not support "
|
346
|
569 "subrequest in memory");
|
248
|
570 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
571 }
|
|
572
|
510
|
573 if (ngx_http_upstream_create(r) != NGX_OK) {
|
|
574 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
575 }
|
|
576
|
438
|
577 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
|
578 if (f == NULL) {
|
510
|
579 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
438
|
580 }
|
|
581
|
|
582 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
50
|
583
|
430
|
584 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
585
|
|
586 if (flcf->fastcgi_lengths) {
|
|
587 if (ngx_http_fastcgi_eval(r, flcf) != NGX_OK) {
|
|
588 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
589 }
|
|
590 }
|
|
591
|
510
|
592 u = r->upstream;
|
|
593
|
570
|
594 ngx_str_set(&u->schema, "fastcgi://");
|
50
|
595 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module;
|
|
596
|
|
597 u->conf = &flcf->upstream;
|
|
598
|
466
|
599 #if (NGX_HTTP_CACHE)
|
|
600 u->create_key = ngx_http_fastcgi_create_key;
|
|
601 #endif
|
50
|
602 u->create_request = ngx_http_fastcgi_create_request;
|
|
603 u->reinit_request = ngx_http_fastcgi_reinit_request;
|
|
604 u->process_header = ngx_http_fastcgi_process_header;
|
|
605 u->abort_request = ngx_http_fastcgi_abort_request;
|
|
606 u->finalize_request = ngx_http_fastcgi_finalize_request;
|
|
607
|
198
|
608 u->buffering = 1;
|
|
609
|
130
|
610 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t));
|
|
611 if (u->pipe == NULL) {
|
|
612 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
613 }
|
|
614
|
|
615 u->pipe->input_filter = ngx_http_fastcgi_input_filter;
|
|
616 u->pipe->input_ctx = r;
|
50
|
617
|
640
|
618 u->input_filter_init = ngx_http_fastcgi_input_filter_init;
|
|
619
|
50
|
620 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
|
|
621
|
|
622 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
|
623 return rc;
|
|
624 }
|
|
625
|
|
626 return NGX_DONE;
|
|
627 }
|
|
628
|
|
629
|
|
630 static ngx_int_t
|
430
|
631 ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
|
|
632 {
|
578
|
633 ngx_url_t url;
|
|
634 ngx_http_upstream_t *u;
|
|
635
|
|
636 ngx_memzero(&url, sizeof(ngx_url_t));
|
|
637
|
|
638 if (ngx_http_script_run(r, &url.url, flcf->fastcgi_lengths->elts, 0,
|
430
|
639 flcf->fastcgi_values->elts)
|
|
640 == NULL)
|
|
641 {
|
|
642 return NGX_ERROR;
|
|
643 }
|
|
644
|
578
|
645 url.no_resolve = 1;
|
|
646
|
|
647 if (ngx_parse_url(r->pool, &url) != NGX_OK) {
|
|
648 if (url.err) {
|
430
|
649 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
578
|
650 "%s in upstream \"%V\"", url.err, &url.url);
|
430
|
651 }
|
|
652
|
|
653 return NGX_ERROR;
|
|
654 }
|
|
655
|
578
|
656 u = r->upstream;
|
|
657
|
|
658 u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));
|
|
659 if (u->resolved == NULL) {
|
|
660 return NGX_ERROR;
|
|
661 }
|
|
662
|
|
663 if (url.addrs && url.addrs[0].sockaddr) {
|
|
664 u->resolved->sockaddr = url.addrs[0].sockaddr;
|
|
665 u->resolved->socklen = url.addrs[0].socklen;
|
|
666 u->resolved->naddrs = 1;
|
|
667 u->resolved->host = url.addrs[0].name;
|
434
|
668
|
|
669 } else {
|
578
|
670 u->resolved->host = url.host;
|
|
671 u->resolved->port = url.port;
|
618
|
672 u->resolved->no_port = url.no_port;
|
434
|
673 }
|
430
|
674
|
|
675 return NGX_OK;
|
|
676 }
|
|
677
|
|
678
|
466
|
679 #if (NGX_HTTP_CACHE)
|
|
680
|
|
681 static ngx_int_t
|
|
682 ngx_http_fastcgi_create_key(ngx_http_request_t *r)
|
|
683 {
|
|
684 ngx_str_t *key;
|
|
685 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
686
|
|
687 key = ngx_array_push(&r->cache->keys);
|
|
688 if (key == NULL) {
|
|
689 return NGX_ERROR;
|
|
690 }
|
|
691
|
|
692 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
693
|
|
694 if (ngx_http_complex_value(r, &flcf->cache_key, key) != NGX_OK) {
|
|
695 return NGX_ERROR;
|
|
696 }
|
|
697
|
|
698 return NGX_OK;
|
|
699 }
|
|
700
|
|
701 #endif
|
|
702
|
|
703
|
430
|
704 static ngx_int_t
|
50
|
705 ngx_http_fastcgi_create_request(ngx_http_request_t *r)
|
|
706 {
|
58
|
707 off_t file_pos;
|
576
|
708 u_char ch, *pos, *lowcase_key;
|
|
709 size_t size, len, key_len, val_len, padding,
|
|
710 allocated;
|
|
711 ngx_uint_t i, n, next, hash, header_params;
|
58
|
712 ngx_buf_t *b;
|
|
713 ngx_chain_t *cl, *body;
|
|
714 ngx_list_part_t *part;
|
576
|
715 ngx_table_elt_t *header, **ignored;
|
58
|
716 ngx_http_script_code_pt code;
|
|
717 ngx_http_script_engine_t e, le;
|
|
718 ngx_http_fastcgi_header_t *h;
|
|
719 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
720 ngx_http_script_len_code_pt lcode;
|
50
|
721
|
58
|
722 len = 0;
|
576
|
723 header_params = 0;
|
|
724 ignored = NULL;
|
50
|
725
|
|
726 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
727
|
58
|
728 if (flcf->params_len) {
|
|
729 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
|
50
|
730
|
340
|
731 ngx_http_script_flush_no_cacheable_variables(r, flcf->flushes);
|
122
|
732 le.flushed = 1;
|
|
733
|
58
|
734 le.ip = flcf->params_len->elts;
|
|
735 le.request = r;
|
50
|
736
|
58
|
737 while (*(uintptr_t *) le.ip) {
|
50
|
738
|
58
|
739 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
740 key_len = lcode(&le);
|
50
|
741
|
58
|
742 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
|
743 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
744 }
|
|
745 le.ip += sizeof(uintptr_t);
|
50
|
746
|
86
|
747 len += 1 + key_len + ((val_len > 127) ? 4 : 1) + val_len;
|
50
|
748 }
|
|
749 }
|
|
750
|
58
|
751 if (flcf->upstream.pass_request_headers) {
|
50
|
752
|
576
|
753 allocated = 0;
|
|
754 lowcase_key = NULL;
|
|
755
|
|
756 if (flcf->header_params) {
|
634
|
757 n = 0;
|
|
758 part = &r->headers_in.headers.part;
|
|
759
|
|
760 while (part) {
|
|
761 n += part->nelts;
|
|
762 part = part->next;
|
|
763 }
|
|
764
|
|
765 ignored = ngx_palloc(r->pool, n * sizeof(void *));
|
576
|
766 if (ignored == NULL) {
|
|
767 return NGX_ERROR;
|
|
768 }
|
|
769 }
|
|
770
|
58
|
771 part = &r->headers_in.headers.part;
|
|
772 header = part->elts;
|
|
773
|
|
774 for (i = 0; /* void */; i++) {
|
50
|
775
|
58
|
776 if (i >= part->nelts) {
|
|
777 if (part->next == NULL) {
|
|
778 break;
|
|
779 }
|
50
|
780
|
58
|
781 part = part->next;
|
|
782 header = part->elts;
|
|
783 i = 0;
|
50
|
784 }
|
|
785
|
576
|
786 if (flcf->header_params) {
|
|
787 if (allocated < header[i].key.len) {
|
|
788 allocated = header[i].key.len + 16;
|
|
789 lowcase_key = ngx_pnalloc(r->pool, allocated);
|
|
790 if (lowcase_key == NULL) {
|
|
791 return NGX_ERROR;
|
|
792 }
|
|
793 }
|
|
794
|
|
795 hash = 0;
|
|
796
|
|
797 for (n = 0; n < header[i].key.len; n++) {
|
|
798 ch = header[i].key.data[n];
|
|
799
|
|
800 if (ch >= 'A' && ch <= 'Z') {
|
|
801 ch |= 0x20;
|
|
802
|
|
803 } else if (ch == '-') {
|
|
804 ch = '_';
|
|
805 }
|
|
806
|
|
807 hash = ngx_hash(hash, ch);
|
|
808 lowcase_key[n] = ch;
|
|
809 }
|
|
810
|
|
811 if (ngx_hash_find(&flcf->headers_hash, hash, lowcase_key, n)) {
|
|
812 ignored[header_params++] = &header[i];
|
|
813 continue;
|
|
814 }
|
|
815
|
|
816 n += sizeof("HTTP_") - 1;
|
|
817
|
|
818 } else {
|
|
819 n = sizeof("HTTP_") - 1 + header[i].key.len;
|
|
820 }
|
|
821
|
|
822 len += ((n > 127) ? 4 : 1) + ((header[i].value.len > 127) ? 4 : 1)
|
|
823 + n + header[i].value.len;
|
50
|
824 }
|
|
825 }
|
|
826
|
|
827
|
|
828 if (len > 65535) {
|
|
829 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
354
|
830 "fastcgi request record is too big: %uz", len);
|
50
|
831 return NGX_ERROR;
|
|
832 }
|
|
833
|
|
834
|
|
835 padding = 8 - len % 8;
|
|
836 padding = (padding == 8) ? 0 : padding;
|
|
837
|
|
838
|
|
839 size = sizeof(ngx_http_fastcgi_header_t)
|
|
840 + sizeof(ngx_http_fastcgi_begin_request_t)
|
|
841
|
|
842 + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */
|
|
843 + len + padding
|
|
844 + sizeof(ngx_http_fastcgi_header_t) /* NGX_HTTP_FASTCGI_PARAMS */
|
|
845
|
|
846 + sizeof(ngx_http_fastcgi_header_t); /* NGX_HTTP_FASTCGI_STDIN */
|
|
847
|
|
848
|
|
849 b = ngx_create_temp_buf(r->pool, size);
|
|
850 if (b == NULL) {
|
|
851 return NGX_ERROR;
|
|
852 }
|
|
853
|
|
854 cl = ngx_alloc_chain_link(r->pool);
|
|
855 if (cl == NULL) {
|
|
856 return NGX_ERROR;
|
|
857 }
|
|
858
|
|
859 cl->buf = b;
|
|
860
|
640
|
861 ngx_http_fastcgi_request_start.br.flags =
|
|
862 flcf->keep_conn ? NGX_HTTP_FASTCGI_KEEP_CONN : 0;
|
|
863
|
58
|
864 ngx_memcpy(b->pos, &ngx_http_fastcgi_request_start,
|
|
865 sizeof(ngx_http_fastcgi_request_start_t));
|
50
|
866
|
|
867 h = (ngx_http_fastcgi_header_t *)
|
|
868 (b->pos + sizeof(ngx_http_fastcgi_header_t)
|
|
869 + sizeof(ngx_http_fastcgi_begin_request_t));
|
|
870
|
|
871 h->content_length_hi = (u_char) ((len >> 8) & 0xff);
|
|
872 h->content_length_lo = (u_char) (len & 0xff);
|
|
873 h->padding_length = (u_char) padding;
|
|
874 h->reserved = 0;
|
|
875
|
|
876 b->last = b->pos + sizeof(ngx_http_fastcgi_header_t)
|
|
877 + sizeof(ngx_http_fastcgi_begin_request_t)
|
|
878 + sizeof(ngx_http_fastcgi_header_t);
|
|
879
|
|
880
|
58
|
881 if (flcf->params_len) {
|
|
882 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
|
50
|
883
|
58
|
884 e.ip = flcf->params->elts;
|
|
885 e.pos = b->last;
|
|
886 e.request = r;
|
122
|
887 e.flushed = 1;
|
50
|
888
|
58
|
889 le.ip = flcf->params_len->elts;
|
50
|
890
|
58
|
891 while (*(uintptr_t *) le.ip) {
|
50
|
892
|
58
|
893 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
894 key_len = (u_char) lcode(&le);
|
50
|
895
|
58
|
896 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
|
|
897 lcode = *(ngx_http_script_len_code_pt *) le.ip;
|
|
898 }
|
|
899 le.ip += sizeof(uintptr_t);
|
50
|
900
|
86
|
901 *e.pos++ = (u_char) key_len;
|
50
|
902
|
86
|
903 if (val_len > 127) {
|
|
904 *e.pos++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80);
|
|
905 *e.pos++ = (u_char) ((val_len >> 16) & 0xff);
|
|
906 *e.pos++ = (u_char) ((val_len >> 8) & 0xff);
|
|
907 *e.pos++ = (u_char) (val_len & 0xff);
|
50
|
908
|
86
|
909 } else {
|
|
910 *e.pos++ = (u_char) val_len;
|
58
|
911 }
|
50
|
912
|
58
|
913 while (*(uintptr_t *) e.ip) {
|
|
914 code = *(ngx_http_script_code_pt *) e.ip;
|
|
915 code((ngx_http_script_engine_t *) &e);
|
|
916 }
|
|
917 e.ip += sizeof(uintptr_t);
|
370
|
918
|
|
919 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
920 "fastcgi param: \"%*s: %*s\"",
|
|
921 key_len, e.pos - (key_len + val_len),
|
|
922 val_len, e.pos - val_len);
|
50
|
923 }
|
|
924
|
58
|
925 b->last = e.pos;
|
50
|
926 }
|
|
927
|
|
928
|
58
|
929 if (flcf->upstream.pass_request_headers) {
|
50
|
930
|
58
|
931 part = &r->headers_in.headers.part;
|
|
932 header = part->elts;
|
50
|
933
|
58
|
934 for (i = 0; /* void */; i++) {
|
50
|
935
|
58
|
936 if (i >= part->nelts) {
|
|
937 if (part->next == NULL) {
|
126
|
938 break;
|
58
|
939 }
|
126
|
940
|
58
|
941 part = part->next;
|
|
942 header = part->elts;
|
|
943 i = 0;
|
|
944 }
|
50
|
945
|
576
|
946 for (n = 0; n < header_params; n++) {
|
|
947 if (&header[i] == ignored[n]) {
|
|
948 goto next;
|
|
949 }
|
|
950 }
|
|
951
|
|
952 key_len = sizeof("HTTP_") - 1 + header[i].key.len;
|
|
953 if (key_len > 127) {
|
|
954 *b->last++ = (u_char) (((key_len >> 24) & 0x7f) | 0x80);
|
|
955 *b->last++ = (u_char) ((key_len >> 16) & 0xff);
|
|
956 *b->last++ = (u_char) ((key_len >> 8) & 0xff);
|
|
957 *b->last++ = (u_char) (key_len & 0xff);
|
126
|
958
|
58
|
959 } else {
|
576
|
960 *b->last++ = (u_char) key_len;
|
50
|
961 }
|
|
962
|
576
|
963 val_len = header[i].value.len;
|
|
964 if (val_len > 127) {
|
|
965 *b->last++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80);
|
|
966 *b->last++ = (u_char) ((val_len >> 16) & 0xff);
|
|
967 *b->last++ = (u_char) ((val_len >> 8) & 0xff);
|
|
968 *b->last++ = (u_char) (val_len & 0xff);
|
50
|
969
|
58
|
970 } else {
|
576
|
971 *b->last++ = (u_char) val_len;
|
50
|
972 }
|
|
973
|
58
|
974 b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1);
|
50
|
975
|
58
|
976 for (n = 0; n < header[i].key.len; n++) {
|
|
977 ch = header[i].key.data[n];
|
50
|
978
|
58
|
979 if (ch >= 'a' && ch <= 'z') {
|
|
980 ch &= ~0x20;
|
50
|
981
|
58
|
982 } else if (ch == '-') {
|
|
983 ch = '_';
|
|
984 }
|
50
|
985
|
58
|
986 *b->last++ = ch;
|
50
|
987 }
|
|
988
|
576
|
989 b->last = ngx_copy(b->last, header[i].value.data, val_len);
|
|
990
|
|
991 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
992 "fastcgi param: \"%*s: %*s\"",
|
|
993 key_len, b->last - (key_len + val_len),
|
|
994 val_len, b->last - val_len);
|
|
995 next:
|
|
996
|
|
997 continue;
|
50
|
998 }
|
|
999 }
|
|
1000
|
|
1001
|
|
1002 if (padding) {
|
|
1003 ngx_memzero(b->last, padding);
|
|
1004 b->last += padding;
|
|
1005 }
|
|
1006
|
|
1007
|
|
1008 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
1009 b->last += sizeof(ngx_http_fastcgi_header_t);
|
|
1010
|
|
1011 h->version = 1;
|
|
1012 h->type = NGX_HTTP_FASTCGI_PARAMS;
|
|
1013 h->request_id_hi = 0;
|
|
1014 h->request_id_lo = 1;
|
|
1015 h->content_length_hi = 0;
|
|
1016 h->content_length_lo = 0;
|
|
1017 h->padding_length = 0;
|
|
1018 h->reserved = 0;
|
|
1019
|
|
1020 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
1021 b->last += sizeof(ngx_http_fastcgi_header_t);
|
|
1022
|
58
|
1023 if (flcf->upstream.pass_request_body) {
|
|
1024 body = r->upstream->request_bufs;
|
|
1025 r->upstream->request_bufs = cl;
|
50
|
1026
|
|
1027 #if (NGX_SUPPRESS_WARN)
|
58
|
1028 file_pos = 0;
|
|
1029 pos = NULL;
|
50
|
1030 #endif
|
|
1031
|
58
|
1032 while (body) {
|
50
|
1033
|
58
|
1034 if (body->buf->in_file) {
|
|
1035 file_pos = body->buf->file_pos;
|
50
|
1036
|
58
|
1037 } else {
|
|
1038 pos = body->buf->pos;
|
50
|
1039 }
|
|
1040
|
58
|
1041 next = 0;
|
50
|
1042
|
58
|
1043 do {
|
|
1044 b = ngx_alloc_buf(r->pool);
|
|
1045 if (b == NULL) {
|
|
1046 return NGX_ERROR;
|
50
|
1047 }
|
|
1048
|
58
|
1049 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t));
|
|
1050
|
|
1051 if (body->buf->in_file) {
|
|
1052 b->file_pos = file_pos;
|
|
1053 file_pos += 32 * 1024;
|
50
|
1054
|
292
|
1055 if (file_pos >= body->buf->file_last) {
|
58
|
1056 file_pos = body->buf->file_last;
|
|
1057 next = 1;
|
|
1058 }
|
|
1059
|
|
1060 b->file_last = file_pos;
|
|
1061 len = (ngx_uint_t) (file_pos - b->file_pos);
|
|
1062
|
|
1063 } else {
|
|
1064 b->pos = pos;
|
|
1065 pos += 32 * 1024;
|
50
|
1066
|
292
|
1067 if (pos >= body->buf->last) {
|
58
|
1068 pos = body->buf->last;
|
|
1069 next = 1;
|
|
1070 }
|
|
1071
|
|
1072 b->last = pos;
|
|
1073 len = (ngx_uint_t) (pos - b->pos);
|
|
1074 }
|
50
|
1075
|
58
|
1076 padding = 8 - len % 8;
|
|
1077 padding = (padding == 8) ? 0 : padding;
|
50
|
1078
|
58
|
1079 h->version = 1;
|
|
1080 h->type = NGX_HTTP_FASTCGI_STDIN;
|
|
1081 h->request_id_hi = 0;
|
|
1082 h->request_id_lo = 1;
|
|
1083 h->content_length_hi = (u_char) ((len >> 8) & 0xff);
|
|
1084 h->content_length_lo = (u_char) (len & 0xff);
|
|
1085 h->padding_length = (u_char) padding;
|
|
1086 h->reserved = 0;
|
50
|
1087
|
58
|
1088 cl->next = ngx_alloc_chain_link(r->pool);
|
|
1089 if (cl->next == NULL) {
|
|
1090 return NGX_ERROR;
|
|
1091 }
|
50
|
1092
|
58
|
1093 cl = cl->next;
|
|
1094 cl->buf = b;
|
|
1095
|
|
1096 b = ngx_create_temp_buf(r->pool,
|
|
1097 sizeof(ngx_http_fastcgi_header_t)
|
|
1098 + padding);
|
|
1099 if (b == NULL) {
|
|
1100 return NGX_ERROR;
|
|
1101 }
|
50
|
1102
|
58
|
1103 if (padding) {
|
|
1104 ngx_memzero(b->last, padding);
|
|
1105 b->last += padding;
|
|
1106 }
|
|
1107
|
|
1108 h = (ngx_http_fastcgi_header_t *) b->last;
|
|
1109 b->last += sizeof(ngx_http_fastcgi_header_t);
|
50
|
1110
|
58
|
1111 cl->next = ngx_alloc_chain_link(r->pool);
|
|
1112 if (cl->next == NULL) {
|
|
1113 return NGX_ERROR;
|
|
1114 }
|
|
1115
|
|
1116 cl = cl->next;
|
|
1117 cl->buf = b;
|
50
|
1118
|
58
|
1119 } while (!next);
|
50
|
1120
|
58
|
1121 body = body->next;
|
|
1122 }
|
50
|
1123
|
58
|
1124 } else {
|
|
1125 r->upstream->request_bufs = cl;
|
50
|
1126 }
|
|
1127
|
|
1128 h->version = 1;
|
|
1129 h->type = NGX_HTTP_FASTCGI_STDIN;
|
|
1130 h->request_id_hi = 0;
|
|
1131 h->request_id_lo = 1;
|
|
1132 h->content_length_hi = 0;
|
|
1133 h->content_length_lo = 0;
|
|
1134 h->padding_length = 0;
|
|
1135 h->reserved = 0;
|
|
1136
|
|
1137 cl->next = NULL;
|
|
1138
|
|
1139 return NGX_OK;
|
|
1140 }
|
|
1141
|
|
1142
|
|
1143 static ngx_int_t
|
|
1144 ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
|
|
1145 {
|
|
1146 ngx_http_fastcgi_ctx_t *f;
|
|
1147
|
|
1148 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
1149
|
|
1150 if (f == NULL) {
|
|
1151 return NGX_OK;
|
|
1152 }
|
|
1153
|
|
1154 f->state = ngx_http_fastcgi_st_version;
|
164
|
1155 f->fastcgi_stdout = 0;
|
564
|
1156 f->large_stderr = 0;
|
50
|
1157
|
|
1158 return NGX_OK;
|
|
1159 }
|
|
1160
|
|
1161
|
56
|
1162 static ngx_int_t
|
|
1163 ngx_http_fastcgi_process_header(ngx_http_request_t *r)
|
50
|
1164 {
|
514
|
1165 u_char *p, *msg, *start, *last,
|
|
1166 *part_start, *part_end;
|
316
|
1167 size_t size;
|
514
|
1168 ngx_str_t *status_line, *pattern;
|
58
|
1169 ngx_int_t rc, status;
|
316
|
1170 ngx_buf_t buf;
|
198
|
1171 ngx_uint_t i;
|
58
|
1172 ngx_table_elt_t *h;
|
|
1173 ngx_http_upstream_t *u;
|
|
1174 ngx_http_fastcgi_ctx_t *f;
|
|
1175 ngx_http_upstream_header_t *hh;
|
306
|
1176 ngx_http_fastcgi_loc_conf_t *flcf;
|
316
|
1177 ngx_http_fastcgi_split_part_t *part;
|
58
|
1178 ngx_http_upstream_main_conf_t *umcf;
|
50
|
1179
|
|
1180 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
1181
|
58
|
1182 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
|
|
1183
|
50
|
1184 u = r->upstream;
|
|
1185
|
|
1186 for ( ;; ) {
|
|
1187
|
|
1188 if (f->state < ngx_http_fastcgi_st_data) {
|
|
1189
|
130
|
1190 f->pos = u->buffer.pos;
|
|
1191 f->last = u->buffer.last;
|
50
|
1192
|
|
1193 rc = ngx_http_fastcgi_process_record(r, f);
|
|
1194
|
130
|
1195 u->buffer.pos = f->pos;
|
|
1196 u->buffer.last = f->last;
|
50
|
1197
|
|
1198 if (rc == NGX_AGAIN) {
|
|
1199 return NGX_AGAIN;
|
|
1200 }
|
|
1201
|
|
1202 if (rc == NGX_ERROR) {
|
|
1203 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1204 }
|
|
1205
|
|
1206 if (f->type != NGX_HTTP_FASTCGI_STDOUT
|
|
1207 && f->type != NGX_HTTP_FASTCGI_STDERR)
|
|
1208 {
|
|
1209 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1210 "upstream sent unexpected FastCGI record: %d",
|
|
1211 f->type);
|
|
1212
|
|
1213 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1214 }
|
|
1215
|
|
1216 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
|
|
1217 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1218 "upstream closed prematurely FastCGI stdout");
|
|
1219
|
|
1220 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1221 }
|
|
1222 }
|
|
1223
|
|
1224 if (f->state == ngx_http_fastcgi_st_padding) {
|
|
1225
|
130
|
1226 if (u->buffer.pos + f->padding < u->buffer.last) {
|
50
|
1227 f->state = ngx_http_fastcgi_st_version;
|
130
|
1228 u->buffer.pos += f->padding;
|
50
|
1229
|
|
1230 continue;
|
|
1231 }
|
|
1232
|
130
|
1233 if (u->buffer.pos + f->padding == u->buffer.last) {
|
50
|
1234 f->state = ngx_http_fastcgi_st_version;
|
130
|
1235 u->buffer.pos = u->buffer.last;
|
50
|
1236
|
|
1237 return NGX_AGAIN;
|
|
1238 }
|
|
1239
|
130
|
1240 f->padding -= u->buffer.last - u->buffer.pos;
|
|
1241 u->buffer.pos = u->buffer.last;
|
50
|
1242
|
|
1243 return NGX_AGAIN;
|
|
1244 }
|
|
1245
|
|
1246
|
|
1247 /* f->state == ngx_http_fastcgi_st_data */
|
|
1248
|
|
1249 if (f->type == NGX_HTTP_FASTCGI_STDERR) {
|
|
1250
|
|
1251 if (f->length) {
|
514
|
1252 msg = u->buffer.pos;
|
50
|
1253
|
130
|
1254 if (u->buffer.pos + f->length <= u->buffer.last) {
|
|
1255 u->buffer.pos += f->length;
|
50
|
1256 f->length = 0;
|
|
1257 f->state = ngx_http_fastcgi_st_padding;
|
|
1258
|
126
|
1259 } else {
|
130
|
1260 f->length -= u->buffer.last - u->buffer.pos;
|
|
1261 u->buffer.pos = u->buffer.last;
|
50
|
1262 }
|
|
1263
|
514
|
1264 for (p = u->buffer.pos - 1; msg < p; p--) {
|
|
1265 if (*p != LF && *p != CR && *p != '.' && *p != ' ') {
|
|
1266 break;
|
|
1267 }
|
50
|
1268 }
|
|
1269
|
514
|
1270 p++;
|
|
1271
|
50
|
1272 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
514
|
1273 "FastCGI sent in stderr: \"%*s\"", p - msg, msg);
|
50
|
1274
|
306
|
1275 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
1276
|
|
1277 if (flcf->catch_stderr) {
|
|
1278 pattern = flcf->catch_stderr->elts;
|
|
1279
|
|
1280 for (i = 0; i < flcf->catch_stderr->nelts; i++) {
|
514
|
1281 if (ngx_strnstr(msg, (char *) pattern[i].data,
|
|
1282 p - msg)
|
|
1283 != NULL)
|
|
1284 {
|
356
|
1285 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
306
|
1286 }
|
|
1287 }
|
|
1288 }
|
|
1289
|
130
|
1290 if (u->buffer.pos == u->buffer.last) {
|
164
|
1291
|
|
1292 if (!f->fastcgi_stdout) {
|
|
1293
|
|
1294 /*
|
|
1295 * the special handling the large number
|
|
1296 * of the PHP warnings to not allocate memory
|
|
1297 */
|
|
1298
|
564
|
1299 #if (NGX_HTTP_CACHE)
|
|
1300 if (r->cache) {
|
|
1301 u->buffer.pos = u->buffer.start
|
|
1302 + r->cache->header_start;
|
|
1303 } else {
|
|
1304 u->buffer.pos = u->buffer.start;
|
|
1305 }
|
612
|
1306 #else
|
|
1307 u->buffer.pos = u->buffer.start;
|
564
|
1308 #endif
|
|
1309 u->buffer.last = u->buffer.pos;
|
|
1310 f->large_stderr = 1;
|
164
|
1311 }
|
|
1312
|
50
|
1313 return NGX_AGAIN;
|
|
1314 }
|
|
1315
|
|
1316 } else {
|
|
1317 f->state = ngx_http_fastcgi_st_version;
|
|
1318 }
|
|
1319
|
|
1320 continue;
|
|
1321 }
|
|
1322
|
|
1323
|
|
1324 /* f->type == NGX_HTTP_FASTCGI_STDOUT */
|
|
1325
|
564
|
1326 #if (NGX_HTTP_CACHE)
|
|
1327
|
566
|
1328 if (f->large_stderr && r->cache) {
|
568
|
1329 u_char *start;
|
|
1330 ssize_t len;
|
|
1331 ngx_http_fastcgi_header_t *fh;
|
564
|
1332
|
|
1333 start = u->buffer.start + r->cache->header_start;
|
|
1334
|
|
1335 len = u->buffer.pos - start - 2 * sizeof(ngx_http_fastcgi_header_t);
|
|
1336
|
|
1337 /*
|
|
1338 * A tail of large stderr output before HTTP header is placed
|
|
1339 * in a cache file without a FastCGI record header.
|
|
1340 * To workaround it we put a dummy FastCGI record header at the
|
|
1341 * start of the stderr output or update r->cache_header_start,
|
|
1342 * if there is no enough place for the record header.
|
|
1343 */
|
|
1344
|
|
1345 if (len >= 0) {
|
|
1346 fh = (ngx_http_fastcgi_header_t *) start;
|
|
1347 fh->version = 1;
|
|
1348 fh->type = NGX_HTTP_FASTCGI_STDERR;
|
|
1349 fh->request_id_hi = 0;
|
|
1350 fh->request_id_lo = 1;
|
|
1351 fh->content_length_hi = (u_char) ((len >> 8) & 0xff);
|
|
1352 fh->content_length_lo = (u_char) (len & 0xff);
|
|
1353 fh->padding_length = 0;
|
|
1354 fh->reserved = 0;
|
|
1355
|
|
1356 } else {
|
|
1357 r->cache->header_start += u->buffer.pos - start
|
|
1358 - sizeof(ngx_http_fastcgi_header_t);
|
|
1359 }
|
|
1360
|
|
1361 f->large_stderr = 0;
|
|
1362 }
|
|
1363
|
|
1364 #endif
|
|
1365
|
164
|
1366 f->fastcgi_stdout = 1;
|
|
1367
|
130
|
1368 start = u->buffer.pos;
|
50
|
1369
|
130
|
1370 if (u->buffer.pos + f->length < u->buffer.last) {
|
50
|
1371
|
|
1372 /*
|
130
|
1373 * set u->buffer.last to the end of the FastCGI record data
|
50
|
1374 * for ngx_http_parse_header_line()
|
|
1375 */
|
|
1376
|
130
|
1377 last = u->buffer.last;
|
|
1378 u->buffer.last = u->buffer.pos + f->length;
|
50
|
1379
|
|
1380 } else {
|
|
1381 last = NULL;
|
|
1382 }
|
|
1383
|
|
1384 for ( ;; ) {
|
|
1385
|
316
|
1386 part_start = u->buffer.pos;
|
512
|
1387 part_end = u->buffer.last;
|
316
|
1388
|
412
|
1389 rc = ngx_http_parse_header_line(r, &u->buffer, 1);
|
50
|
1390
|
|
1391 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1392 "http fastcgi parser: %d", rc);
|
|
1393
|
|
1394 if (rc == NGX_AGAIN) {
|
|
1395 break;
|
|
1396 }
|
|
1397
|
|
1398 if (rc == NGX_OK) {
|
|
1399
|
|
1400 /* a header line has been parsed successfully */
|
|
1401
|
58
|
1402 h = ngx_list_push(&u->headers_in.headers);
|
50
|
1403 if (h == NULL) {
|
356
|
1404 return NGX_ERROR;
|
50
|
1405 }
|
|
1406
|
316
|
1407 if (f->split_parts && f->split_parts->nelts) {
|
|
1408
|
|
1409 part = f->split_parts->elts;
|
|
1410 size = u->buffer.pos - part_start;
|
|
1411
|
|
1412 for (i = 0; i < f->split_parts->nelts; i++) {
|
|
1413 size += part[i].end - part[i].start;
|
|
1414 }
|
|
1415
|
382
|
1416 p = ngx_pnalloc(r->pool, size);
|
316
|
1417 if (p == NULL) {
|
356
|
1418 return NGX_ERROR;
|
316
|
1419 }
|
|
1420
|
|
1421 buf.pos = p;
|
|
1422
|
|
1423 for (i = 0; i < f->split_parts->nelts; i++) {
|
|
1424 p = ngx_cpymem(p, part[i].start,
|
|
1425 part[i].end - part[i].start);
|
|
1426 }
|
|
1427
|
|
1428 p = ngx_cpymem(p, part_start, u->buffer.pos - part_start);
|
|
1429
|
|
1430 buf.last = p;
|
|
1431
|
|
1432 f->split_parts->nelts = 0;
|
|
1433
|
412
|
1434 rc = ngx_http_parse_header_line(r, &buf, 1);
|
316
|
1435
|
|
1436 h->key.len = r->header_name_end - r->header_name_start;
|
|
1437 h->key.data = r->header_name_start;
|
|
1438 h->key.data[h->key.len] = '\0';
|
|
1439
|
|
1440 h->value.len = r->header_end - r->header_start;
|
|
1441 h->value.data = r->header_start;
|
|
1442 h->value.data[h->value.len] = '\0';
|
|
1443
|
382
|
1444 h->lowcase_key = ngx_pnalloc(r->pool, h->key.len);
|
316
|
1445 if (h->lowcase_key == NULL) {
|
356
|
1446 return NGX_ERROR;
|
316
|
1447 }
|
|
1448
|
|
1449 } else {
|
|
1450
|
|
1451 h->key.len = r->header_name_end - r->header_name_start;
|
|
1452 h->value.len = r->header_end - r->header_start;
|
|
1453
|
382
|
1454 h->key.data = ngx_pnalloc(r->pool,
|
|
1455 h->key.len + 1 + h->value.len + 1
|
|
1456 + h->key.len);
|
316
|
1457 if (h->key.data == NULL) {
|
356
|
1458 return NGX_ERROR;
|
316
|
1459 }
|
|
1460
|
|
1461 h->value.data = h->key.data + h->key.len + 1;
|
|
1462 h->lowcase_key = h->key.data + h->key.len + 1
|
|
1463 + h->value.len + 1;
|
|
1464
|
|
1465 ngx_cpystrn(h->key.data, r->header_name_start,
|
|
1466 h->key.len + 1);
|
|
1467 ngx_cpystrn(h->value.data, r->header_start,
|
|
1468 h->value.len + 1);
|
|
1469 }
|
|
1470
|
58
|
1471 h->hash = r->header_hash;
|
|
1472
|
198
|
1473 if (h->key.len == r->lowcase_index) {
|
|
1474 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
|
|
1475
|
|
1476 } else {
|
392
|
1477 ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
|
50
|
1478 }
|
|
1479
|
198
|
1480 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
|
|
1481 h->lowcase_key, h->key.len);
|
|
1482
|
|
1483 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
|
356
|
1484 return NGX_ERROR;
|
198
|
1485 }
|
|
1486
|
50
|
1487 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1488 "http fastcgi header: \"%V: %V\"",
|
|
1489 &h->key, &h->value);
|
|
1490
|
164
|
1491 if (u->buffer.pos < u->buffer.last) {
|
|
1492 continue;
|
|
1493 }
|
|
1494
|
|
1495 /* the end of the FastCGI record */
|
|
1496
|
|
1497 break;
|
50
|
1498 }
|
|
1499
|
|
1500 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
1501
|
|
1502 /* a whole header has been parsed successfully */
|
|
1503
|
|
1504 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1505 "http fastcgi header done");
|
|
1506
|
58
|
1507 if (u->headers_in.status) {
|
|
1508 status_line = &u->headers_in.status->value;
|
50
|
1509
|
|
1510 status = ngx_atoi(status_line->data, 3);
|
|
1511
|
|
1512 if (status == NGX_ERROR) {
|
356
|
1513 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1514 "upstream sent invalid status \"%V\"",
|
|
1515 status_line);
|
|
1516 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
50
|
1517 }
|
|
1518
|
78
|
1519 u->headers_in.status_n = status;
|
|
1520 u->headers_in.status_line = *status_line;
|
50
|
1521
|
392
|
1522 } else if (u->headers_in.location) {
|
|
1523 u->headers_in.status_n = 302;
|
570
|
1524 ngx_str_set(&u->headers_in.status_line,
|
|
1525 "302 Moved Temporarily");
|
392
|
1526
|
50
|
1527 } else {
|
78
|
1528 u->headers_in.status_n = 200;
|
570
|
1529 ngx_str_set(&u->headers_in.status_line, "200 OK");
|
50
|
1530 }
|
|
1531
|
466
|
1532 if (u->state) {
|
|
1533 u->state->status = u->headers_in.status_n;
|
50
|
1534 }
|
|
1535
|
|
1536 break;
|
|
1537 }
|
|
1538
|
|
1539 /* there was error while a header line parsing */
|
|
1540
|
|
1541 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
168
|
1542 "upstream sent invalid header");
|
50
|
1543
|
|
1544 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
|
|
1545 }
|
|
1546
|
|
1547 if (last) {
|
130
|
1548 u->buffer.last = last;
|
50
|
1549 }
|
|
1550
|
130
|
1551 f->length -= u->buffer.pos - start;
|
50
|
1552
|
|
1553 if (f->length == 0) {
|
|
1554 if (f->padding) {
|
|
1555 f->state = ngx_http_fastcgi_st_padding;
|
|
1556 } else {
|
|
1557 f->state = ngx_http_fastcgi_st_version;
|
|
1558 }
|
|
1559 }
|
|
1560
|
164
|
1561 if (rc == NGX_HTTP_PARSE_HEADER_DONE) {
|
|
1562 return NGX_OK;
|
|
1563 }
|
|
1564
|
316
|
1565 if (rc == NGX_OK) {
|
374
|
1566 continue;
|
164
|
1567 }
|
|
1568
|
316
|
1569 /* rc == NGX_AGAIN */
|
|
1570
|
|
1571 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1572 "upstream split a header line in FastCGI records");
|
|
1573
|
|
1574 if (f->split_parts == NULL) {
|
|
1575 f->split_parts = ngx_array_create(r->pool, 1,
|
|
1576 sizeof(ngx_http_fastcgi_split_part_t));
|
|
1577 if (f->split_parts == NULL) {
|
356
|
1578 return NGX_ERROR;
|
316
|
1579 }
|
164
|
1580 }
|
316
|
1581
|
|
1582 part = ngx_array_push(f->split_parts);
|
|
1583
|
|
1584 part->start = part_start;
|
512
|
1585 part->end = part_end;
|
|
1586
|
|
1587 if (u->buffer.pos < u->buffer.last) {
|
|
1588 continue;
|
|
1589 }
|
316
|
1590
|
|
1591 return NGX_AGAIN;
|
50
|
1592 }
|
|
1593 }
|
|
1594
|
|
1595
|
|
1596 static ngx_int_t
|
640
|
1597 ngx_http_fastcgi_input_filter_init(void *data)
|
|
1598 {
|
|
1599 ngx_http_request_t *r = data;
|
|
1600 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
1601
|
|
1602 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
1603
|
|
1604 r->upstream->pipe->length = flcf->keep_conn ?
|
|
1605 (off_t) sizeof(ngx_http_fastcgi_header_t) : -1;
|
|
1606
|
|
1607 return NGX_OK;
|
|
1608 }
|
|
1609
|
|
1610
|
|
1611 static ngx_int_t
|
50
|
1612 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
|
|
1613 {
|
640
|
1614 u_char *m, *msg;
|
|
1615 ngx_int_t rc;
|
|
1616 ngx_buf_t *b, **prev;
|
|
1617 ngx_chain_t *cl;
|
|
1618 ngx_http_request_t *r;
|
|
1619 ngx_http_fastcgi_ctx_t *f;
|
|
1620 ngx_http_fastcgi_loc_conf_t *flcf;
|
50
|
1621
|
|
1622 if (buf->pos == buf->last) {
|
|
1623 return NGX_OK;
|
|
1624 }
|
|
1625
|
|
1626 r = p->input_ctx;
|
|
1627 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
640
|
1628 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
50
|
1629
|
|
1630 b = NULL;
|
|
1631 prev = &buf->shadow;
|
|
1632
|
|
1633 f->pos = buf->pos;
|
|
1634 f->last = buf->last;
|
|
1635
|
|
1636 for ( ;; ) {
|
|
1637 if (f->state < ngx_http_fastcgi_st_data) {
|
|
1638
|
|
1639 rc = ngx_http_fastcgi_process_record(r, f);
|
|
1640
|
|
1641 if (rc == NGX_AGAIN) {
|
|
1642 break;
|
|
1643 }
|
|
1644
|
|
1645 if (rc == NGX_ERROR) {
|
|
1646 return NGX_ERROR;
|
|
1647 }
|
|
1648
|
|
1649 if (f->type == NGX_HTTP_FASTCGI_STDOUT && f->length == 0) {
|
|
1650 f->state = ngx_http_fastcgi_st_version;
|
640
|
1651
|
|
1652 if (!flcf->keep_conn) {
|
|
1653 p->upstream_done = 1;
|
|
1654 }
|
50
|
1655
|
|
1656 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
|
|
1657 "http fastcgi closed stdout");
|
|
1658
|
|
1659 continue;
|
|
1660 }
|
|
1661
|
|
1662 if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) {
|
|
1663 f->state = ngx_http_fastcgi_st_version;
|
|
1664 p->upstream_done = 1;
|
|
1665
|
640
|
1666 if (flcf->keep_conn) {
|
|
1667 r->upstream->keepalive = 1;
|
|
1668 }
|
|
1669
|
50
|
1670 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
|
|
1671 "http fastcgi sent end request");
|
|
1672
|
|
1673 break;
|
|
1674 }
|
|
1675 }
|
|
1676
|
|
1677
|
|
1678 if (f->state == ngx_http_fastcgi_st_padding) {
|
|
1679
|
|
1680 if (f->pos + f->padding < f->last) {
|
|
1681 f->state = ngx_http_fastcgi_st_version;
|
|
1682 f->pos += f->padding;
|
|
1683
|
|
1684 continue;
|
|
1685 }
|
|
1686
|
|
1687 if (f->pos + f->padding == f->last) {
|
|
1688 f->state = ngx_http_fastcgi_st_version;
|
|
1689
|
|
1690 break;
|
|
1691 }
|
|
1692
|
|
1693 f->padding -= f->last - f->pos;
|
|
1694
|
|
1695 break;
|
|
1696 }
|
|
1697
|
|
1698
|
|
1699 /* f->state == ngx_http_fastcgi_st_data */
|
|
1700
|
|
1701 if (f->type == NGX_HTTP_FASTCGI_STDERR) {
|
|
1702
|
|
1703 if (f->length) {
|
188
|
1704
|
|
1705 if (f->pos == f->last) {
|
|
1706 break;
|
|
1707 }
|
|
1708
|
514
|
1709 msg = f->pos;
|
50
|
1710
|
|
1711 if (f->pos + f->length <= f->last) {
|
|
1712 f->pos += f->length;
|
|
1713 f->length = 0;
|
|
1714 f->state = ngx_http_fastcgi_st_padding;
|
|
1715
|
126
|
1716 } else {
|
50
|
1717 f->length -= f->last - f->pos;
|
|
1718 f->pos = f->last;
|
|
1719 }
|
|
1720
|
514
|
1721 for (m = f->pos - 1; msg < m; m--) {
|
|
1722 if (*m != LF && *m != CR && *m != '.' && *m != ' ') {
|
|
1723 break;
|
|
1724 }
|
50
|
1725 }
|
|
1726
|
|
1727 ngx_log_error(NGX_LOG_ERR, p->log, 0,
|
514
|
1728 "FastCGI sent in stderr: \"%*s\"",
|
|
1729 m + 1 - msg, msg);
|
50
|
1730
|
|
1731 if (f->pos == f->last) {
|
|
1732 break;
|
|
1733 }
|
|
1734
|
|
1735 } else {
|
|
1736 f->state = ngx_http_fastcgi_st_version;
|
|
1737 }
|
|
1738
|
|
1739 continue;
|
|
1740 }
|
|
1741
|
|
1742
|
|
1743 /* f->type == NGX_HTTP_FASTCGI_STDOUT */
|
|
1744
|
188
|
1745 if (f->pos == f->last) {
|
|
1746 break;
|
|
1747 }
|
|
1748
|
50
|
1749 if (p->free) {
|
640
|
1750 cl = p->free;
|
|
1751 b = cl->buf;
|
|
1752 p->free = cl->next;
|
|
1753 ngx_free_chain(p->pool, cl);
|
50
|
1754
|
|
1755 } else {
|
|
1756 b = ngx_alloc_buf(p->pool);
|
|
1757 if (b == NULL) {
|
|
1758 return NGX_ERROR;
|
|
1759 }
|
|
1760 }
|
|
1761
|
|
1762 ngx_memzero(b, sizeof(ngx_buf_t));
|
|
1763
|
|
1764 b->pos = f->pos;
|
|
1765 b->start = buf->start;
|
|
1766 b->end = buf->end;
|
|
1767 b->tag = p->tag;
|
|
1768 b->temporary = 1;
|
|
1769 b->recycled = 1;
|
|
1770
|
|
1771 *prev = b;
|
|
1772 prev = &b->shadow;
|
|
1773
|
|
1774 cl = ngx_alloc_chain_link(p->pool);
|
|
1775 if (cl == NULL) {
|
|
1776 return NGX_ERROR;
|
|
1777 }
|
|
1778
|
|
1779 cl->buf = b;
|
|
1780 cl->next = NULL;
|
|
1781
|
|
1782 if (p->in) {
|
|
1783 *p->last_in = cl;
|
|
1784 } else {
|
|
1785 p->in = cl;
|
|
1786 }
|
|
1787 p->last_in = &cl->next;
|
|
1788
|
|
1789
|
|
1790 /* STUB */ b->num = buf->num;
|
|
1791
|
274
|
1792 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
|
276
|
1793 "input buf #%d %p", b->num, b->pos);
|
50
|
1794
|
|
1795 if (f->pos + f->length < f->last) {
|
|
1796
|
|
1797 if (f->padding) {
|
|
1798 f->state = ngx_http_fastcgi_st_padding;
|
|
1799 } else {
|
|
1800 f->state = ngx_http_fastcgi_st_version;
|
|
1801 }
|
|
1802
|
|
1803 f->pos += f->length;
|
|
1804 b->last = f->pos;
|
|
1805
|
|
1806 continue;
|
|
1807 }
|
|
1808
|
|
1809 if (f->pos + f->length == f->last) {
|
|
1810
|
|
1811 if (f->padding) {
|
|
1812 f->state = ngx_http_fastcgi_st_padding;
|
|
1813 } else {
|
|
1814 f->state = ngx_http_fastcgi_st_version;
|
|
1815 }
|
|
1816
|
|
1817 b->last = f->last;
|
|
1818
|
|
1819 break;
|
|
1820 }
|
|
1821
|
|
1822 f->length -= f->last - f->pos;
|
|
1823
|
|
1824 b->last = f->last;
|
|
1825
|
|
1826 break;
|
|
1827
|
|
1828 }
|
|
1829
|
640
|
1830 if (flcf->keep_conn) {
|
|
1831
|
|
1832 /* set p->length, minimal amount of data we want to see */
|
|
1833
|
|
1834 if (f->state < ngx_http_fastcgi_st_data) {
|
|
1835 p->length = 1;
|
|
1836
|
|
1837 } else if (f->state == ngx_http_fastcgi_st_padding) {
|
|
1838 p->length = f->padding;
|
|
1839
|
|
1840 } else {
|
|
1841 /* ngx_http_fastcgi_st_data */
|
|
1842
|
|
1843 p->length = f->length;
|
|
1844 }
|
|
1845 }
|
|
1846
|
50
|
1847 if (b) {
|
|
1848 b->shadow = buf;
|
|
1849 b->last_shadow = 1;
|
|
1850
|
274
|
1851 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
|
276
|
1852 "input buf %p %z", b->pos, b->last - b->pos);
|
274
|
1853
|
50
|
1854 return NGX_OK;
|
|
1855 }
|
|
1856
|
|
1857 /* there is no data record in the buf, add it to free chain */
|
|
1858
|
|
1859 if (ngx_event_pipe_add_free_buf(p, buf) != NGX_OK) {
|
|
1860 return NGX_ERROR;
|
|
1861 }
|
|
1862
|
|
1863 return NGX_OK;
|
|
1864 }
|
|
1865
|
|
1866
|
|
1867 static ngx_int_t
|
|
1868 ngx_http_fastcgi_process_record(ngx_http_request_t *r,
|
|
1869 ngx_http_fastcgi_ctx_t *f)
|
|
1870 {
|
|
1871 u_char ch, *p;
|
|
1872 ngx_http_fastcgi_state_e state;
|
|
1873
|
|
1874 state = f->state;
|
|
1875
|
|
1876 for (p = f->pos; p < f->last; p++) {
|
|
1877
|
|
1878 ch = *p;
|
|
1879
|
|
1880 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1881 "http fastcgi record byte: %02Xd", ch);
|
|
1882
|
|
1883 switch (state) {
|
|
1884
|
|
1885 case ngx_http_fastcgi_st_version:
|
|
1886 if (ch != 1) {
|
|
1887 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1888 "upstream sent unsupported FastCGI "
|
|
1889 "protocol version: %d", ch);
|
|
1890 return NGX_ERROR;
|
|
1891 }
|
|
1892 state = ngx_http_fastcgi_st_type;
|
|
1893 break;
|
|
1894
|
|
1895 case ngx_http_fastcgi_st_type:
|
|
1896 switch (ch) {
|
|
1897 case NGX_HTTP_FASTCGI_STDOUT:
|
|
1898 case NGX_HTTP_FASTCGI_STDERR:
|
|
1899 case NGX_HTTP_FASTCGI_END_REQUEST:
|
|
1900 f->type = (ngx_uint_t) ch;
|
|
1901 break;
|
|
1902 default:
|
|
1903 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1904 "upstream sent invalid FastCGI "
|
|
1905 "record type: %d", ch);
|
|
1906 return NGX_ERROR;
|
|
1907
|
|
1908 }
|
|
1909 state = ngx_http_fastcgi_st_request_id_hi;
|
|
1910 break;
|
|
1911
|
|
1912 /* we support the single request per connection */
|
|
1913
|
|
1914 case ngx_http_fastcgi_st_request_id_hi:
|
|
1915 if (ch != 0) {
|
|
1916 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1917 "upstream sent unexpected FastCGI "
|
|
1918 "request id high byte: %d", ch);
|
|
1919 return NGX_ERROR;
|
|
1920 }
|
|
1921 state = ngx_http_fastcgi_st_request_id_lo;
|
|
1922 break;
|
|
1923
|
|
1924 case ngx_http_fastcgi_st_request_id_lo:
|
|
1925 if (ch != 1) {
|
|
1926 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1927 "upstream sent unexpected FastCGI "
|
|
1928 "request id low byte: %d", ch);
|
|
1929 return NGX_ERROR;
|
|
1930 }
|
|
1931 state = ngx_http_fastcgi_st_content_length_hi;
|
|
1932 break;
|
|
1933
|
|
1934 case ngx_http_fastcgi_st_content_length_hi:
|
|
1935 f->length = ch << 8;
|
|
1936 state = ngx_http_fastcgi_st_content_length_lo;
|
|
1937 break;
|
|
1938
|
|
1939 case ngx_http_fastcgi_st_content_length_lo:
|
|
1940 f->length |= (size_t) ch;
|
|
1941 state = ngx_http_fastcgi_st_padding_length;
|
|
1942 break;
|
|
1943
|
|
1944 case ngx_http_fastcgi_st_padding_length:
|
|
1945 f->padding = (size_t) ch;
|
|
1946 state = ngx_http_fastcgi_st_reserved;
|
|
1947 break;
|
|
1948
|
|
1949 case ngx_http_fastcgi_st_reserved:
|
|
1950 state = ngx_http_fastcgi_st_data;
|
|
1951
|
|
1952 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1953 "http fastcgi record length: %z", f->length);
|
|
1954
|
|
1955 f->pos = p + 1;
|
|
1956 f->state = state;
|
|
1957
|
|
1958 return NGX_OK;
|
|
1959
|
|
1960 /* suppress warning */
|
|
1961 case ngx_http_fastcgi_st_data:
|
|
1962 case ngx_http_fastcgi_st_padding:
|
|
1963 break;
|
|
1964 }
|
|
1965 }
|
|
1966
|
|
1967 f->state = state;
|
|
1968
|
|
1969 return NGX_AGAIN;
|
|
1970 }
|
|
1971
|
|
1972
|
|
1973 static void
|
|
1974 ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
|
|
1975 {
|
|
1976 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1977 "abort http fastcgi request");
|
|
1978
|
|
1979 return;
|
|
1980 }
|
|
1981
|
|
1982
|
|
1983 static void
|
|
1984 ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
|
|
1985 {
|
|
1986 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
1987 "finalize http fastcgi request");
|
|
1988
|
|
1989 return;
|
|
1990 }
|
|
1991
|
|
1992
|
58
|
1993 static ngx_int_t
|
|
1994 ngx_http_fastcgi_add_variables(ngx_conf_t *cf)
|
50
|
1995 {
|
438
|
1996 ngx_http_variable_t *var, *v;
|
|
1997
|
|
1998 for (v = ngx_http_fastcgi_vars; v->name.len; v++) {
|
|
1999 var = ngx_http_add_variable(cf, &v->name, v->flags);
|
|
2000 if (var == NULL) {
|
|
2001 return NGX_ERROR;
|
|
2002 }
|
|
2003
|
|
2004 var->get_handler = v->get_handler;
|
|
2005 var->data = v->data;
|
50
|
2006 }
|
|
2007
|
58
|
2008 return NGX_OK;
|
50
|
2009 }
|
|
2010
|
|
2011
|
|
2012 static void *
|
|
2013 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
|
|
2014 {
|
|
2015 ngx_http_fastcgi_loc_conf_t *conf;
|
|
2016
|
|
2017 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));
|
|
2018 if (conf == NULL) {
|
496
|
2019 return NULL;
|
50
|
2020 }
|
|
2021
|
|
2022 /*
|
|
2023 * set by ngx_pcalloc():
|
|
2024 *
|
|
2025 * conf->upstream.bufs.num = 0;
|
484
|
2026 * conf->upstream.ignore_headers = 0;
|
50
|
2027 * conf->upstream.next_upstream = 0;
|
494
|
2028 * conf->upstream.cache_use_stale = 0;
|
|
2029 * conf->upstream.cache_methods = 0;
|
50
|
2030 * conf->upstream.temp_path = NULL;
|
198
|
2031 * conf->upstream.hide_headers_hash = { NULL, 0 };
|
58
|
2032 * conf->upstream.uri = { 0, NULL };
|
|
2033 * conf->upstream.location = NULL;
|
320
|
2034 * conf->upstream.store_lengths = NULL;
|
|
2035 * conf->upstream.store_values = NULL;
|
58
|
2036 *
|
570
|
2037 * conf->index.len = { 0, NULL };
|
50
|
2038 */
|
|
2039
|
320
|
2040 conf->upstream.store = NGX_CONF_UNSET;
|
|
2041 conf->upstream.store_access = NGX_CONF_UNSET_UINT;
|
130
|
2042 conf->upstream.buffering = NGX_CONF_UNSET;
|
178
|
2043 conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
|
130
|
2044
|
50
|
2045 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
|
|
2046 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
|
56
|
2047 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
|
|
2048
|
50
|
2049 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
|
130
|
2050 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
|
78
|
2051
|
|
2052 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
|
126
|
2053 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
|
78
|
2054 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
|
58
|
2055
|
|
2056 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
|
|
2057 conf->upstream.pass_request_body = NGX_CONF_UNSET;
|
|
2058
|
466
|
2059 #if (NGX_HTTP_CACHE)
|
|
2060 conf->upstream.cache = NGX_CONF_UNSET_PTR;
|
|
2061 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
|
588
|
2062 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
|
572
|
2063 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
|
466
|
2064 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
|
|
2065 #endif
|
|
2066
|
356
|
2067 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
|
|
2068 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
|
|
2069
|
206
|
2070 conf->upstream.intercept_errors = NGX_CONF_UNSET;
|
50
|
2071
|
|
2072 /* "fastcgi_cyclic_temp_file" is disabled */
|
|
2073 conf->upstream.cyclic_temp_file = 0;
|
|
2074
|
332
|
2075 conf->catch_stderr = NGX_CONF_UNSET_PTR;
|
|
2076
|
640
|
2077 conf->keep_conn = NGX_CONF_UNSET;
|
|
2078
|
632
|
2079 ngx_str_set(&conf->upstream.module, "fastcgi");
|
|
2080
|
50
|
2081 return conf;
|
|
2082 }
|
|
2083
|
|
2084
|
|
2085 static char *
|
|
2086 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
2087 {
|
|
2088 ngx_http_fastcgi_loc_conf_t *prev = parent;
|
|
2089 ngx_http_fastcgi_loc_conf_t *conf = child;
|
|
2090
|
58
|
2091 size_t size;
|
198
|
2092 ngx_hash_init_t hash;
|
592
|
2093 ngx_http_core_loc_conf_t *clcf;
|
50
|
2094
|
320
|
2095 if (conf->upstream.store != 0) {
|
|
2096 ngx_conf_merge_value(conf->upstream.store,
|
496
|
2097 prev->upstream.store, 0);
|
320
|
2098
|
|
2099 if (conf->upstream.store_lengths == NULL) {
|
|
2100 conf->upstream.store_lengths = prev->upstream.store_lengths;
|
|
2101 conf->upstream.store_values = prev->upstream.store_values;
|
|
2102 }
|
|
2103 }
|
|
2104
|
|
2105 ngx_conf_merge_uint_value(conf->upstream.store_access,
|
|
2106 prev->upstream.store_access, 0600);
|
318
|
2107
|
130
|
2108 ngx_conf_merge_value(conf->upstream.buffering,
|
|
2109 prev->upstream.buffering, 1);
|
|
2110
|
178
|
2111 ngx_conf_merge_value(conf->upstream.ignore_client_abort,
|
|
2112 prev->upstream.ignore_client_abort, 0);
|
|
2113
|
50
|
2114 ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
|
|
2115 prev->upstream.connect_timeout, 60000);
|
56
|
2116
|
50
|
2117 ngx_conf_merge_msec_value(conf->upstream.send_timeout,
|
|
2118 prev->upstream.send_timeout, 60000);
|
|
2119
|
|
2120 ngx_conf_merge_msec_value(conf->upstream.read_timeout,
|
|
2121 prev->upstream.read_timeout, 60000);
|
|
2122
|
56
|
2123 ngx_conf_merge_size_value(conf->upstream.send_lowat,
|
|
2124 prev->upstream.send_lowat, 0);
|
50
|
2125
|
130
|
2126 ngx_conf_merge_size_value(conf->upstream.buffer_size,
|
|
2127 prev->upstream.buffer_size,
|
50
|
2128 (size_t) ngx_pagesize);
|
|
2129
|
56
|
2130
|
50
|
2131 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
|
|
2132 8, ngx_pagesize);
|
|
2133
|
|
2134 if (conf->upstream.bufs.num < 2) {
|
|
2135 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2136 "there must be at least 2 \"fastcgi_buffers\"");
|
|
2137 return NGX_CONF_ERROR;
|
|
2138 }
|
|
2139
|
|
2140
|
130
|
2141 size = conf->upstream.buffer_size;
|
50
|
2142 if (size < conf->upstream.bufs.size) {
|
|
2143 size = conf->upstream.bufs.size;
|
|
2144 }
|
|
2145
|
|
2146
|
78
|
2147 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,
|
|
2148 prev->upstream.busy_buffers_size_conf,
|
50
|
2149 NGX_CONF_UNSET_SIZE);
|
|
2150
|
78
|
2151 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
2152 conf->upstream.busy_buffers_size = 2 * size;
|
78
|
2153 } else {
|
|
2154 conf->upstream.busy_buffers_size =
|
|
2155 conf->upstream.busy_buffers_size_conf;
|
|
2156 }
|
50
|
2157
|
78
|
2158 if (conf->upstream.busy_buffers_size < size) {
|
50
|
2159 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2160 "\"fastcgi_busy_buffers_size\" must be equal or bigger than "
|
288
|
2161 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
2162 "one of the \"fastcgi_buffers\"");
|
|
2163
|
|
2164 return NGX_CONF_ERROR;
|
78
|
2165 }
|
50
|
2166
|
78
|
2167 if (conf->upstream.busy_buffers_size
|
|
2168 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)
|
50
|
2169 {
|
|
2170 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2171 "\"fastcgi_busy_buffers_size\" must be less than "
|
|
2172 "the size of all \"fastcgi_buffers\" minus one buffer");
|
|
2173
|
|
2174 return NGX_CONF_ERROR;
|
|
2175 }
|
|
2176
|
|
2177
|
78
|
2178 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,
|
|
2179 prev->upstream.temp_file_write_size_conf,
|
50
|
2180 NGX_CONF_UNSET_SIZE);
|
|
2181
|
78
|
2182 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
2183 conf->upstream.temp_file_write_size = 2 * size;
|
78
|
2184 } else {
|
|
2185 conf->upstream.temp_file_write_size =
|
|
2186 conf->upstream.temp_file_write_size_conf;
|
|
2187 }
|
50
|
2188
|
78
|
2189 if (conf->upstream.temp_file_write_size < size) {
|
50
|
2190 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2191 "\"fastcgi_temp_file_write_size\" must be equal or bigger than "
|
288
|
2192 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
2193 "one of the \"fastcgi_buffers\"");
|
|
2194
|
|
2195 return NGX_CONF_ERROR;
|
|
2196 }
|
|
2197
|
|
2198
|
78
|
2199 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,
|
|
2200 prev->upstream.max_temp_file_size_conf,
|
50
|
2201 NGX_CONF_UNSET_SIZE);
|
|
2202
|
78
|
2203 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {
|
50
|
2204 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;
|
78
|
2205 } else {
|
|
2206 conf->upstream.max_temp_file_size =
|
|
2207 conf->upstream.max_temp_file_size_conf;
|
|
2208 }
|
50
|
2209
|
78
|
2210 if (conf->upstream.max_temp_file_size != 0
|
|
2211 && conf->upstream.max_temp_file_size < size)
|
50
|
2212 {
|
|
2213 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2214 "\"fastcgi_max_temp_file_size\" must be equal to zero to disable "
|
|
2215 "the temporary files usage or must be equal or bigger than "
|
288
|
2216 "maximum of the value of \"fastcgi_buffer_size\" and "
|
50
|
2217 "one of the \"fastcgi_buffers\"");
|
|
2218
|
|
2219 return NGX_CONF_ERROR;
|
|
2220 }
|
|
2221
|
|
2222
|
484
|
2223 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,
|
|
2224 prev->upstream.ignore_headers,
|
|
2225 NGX_CONF_BITMASK_SET);
|
|
2226
|
|
2227
|
50
|
2228 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
|
|
2229 prev->upstream.next_upstream,
|
|
2230 (NGX_CONF_BITMASK_SET
|
|
2231 |NGX_HTTP_UPSTREAM_FT_ERROR
|
|
2232 |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
|
|
2233
|
214
|
2234 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
2235 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
|
|
2236 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
2237 }
|
|
2238
|
464
|
2239 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,
|
50
|
2240 prev->upstream.temp_path,
|
464
|
2241 &ngx_http_fastcgi_temp_path)
|
|
2242 != NGX_OK)
|
|
2243 {
|
|
2244 return NGX_CONF_ERROR;
|
|
2245 }
|
50
|
2246
|
466
|
2247 #if (NGX_HTTP_CACHE)
|
|
2248
|
|
2249 ngx_conf_merge_ptr_value(conf->upstream.cache,
|
|
2250 prev->upstream.cache, NULL);
|
|
2251
|
|
2252 if (conf->upstream.cache && conf->upstream.cache->data == NULL) {
|
|
2253 ngx_shm_zone_t *shm_zone;
|
|
2254
|
|
2255 shm_zone = conf->upstream.cache;
|
|
2256
|
|
2257 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2258 "\"fastcgi_cache\" zone \"%V\" is unknown",
|
480
|
2259 &shm_zone->shm.name);
|
466
|
2260
|
|
2261 return NGX_CONF_ERROR;
|
|
2262 }
|
|
2263
|
|
2264 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
|
|
2265 prev->upstream.cache_min_uses, 1);
|
|
2266
|
|
2267 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,
|
|
2268 prev->upstream.cache_use_stale,
|
|
2269 (NGX_CONF_BITMASK_SET
|
|
2270 |NGX_HTTP_UPSTREAM_FT_OFF));
|
|
2271
|
|
2272 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {
|
|
2273 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
|
|
2274 |NGX_HTTP_UPSTREAM_FT_OFF;
|
|
2275 }
|
|
2276
|
494
|
2277 if (conf->upstream.cache_methods == 0) {
|
|
2278 conf->upstream.cache_methods = prev->upstream.cache_methods;
|
|
2279 }
|
|
2280
|
|
2281 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;
|
|
2282
|
588
|
2283 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass,
|
|
2284 prev->upstream.cache_bypass, NULL);
|
|
2285
|
572
|
2286 ngx_conf_merge_ptr_value(conf->upstream.no_cache,
|
|
2287 prev->upstream.no_cache, NULL);
|
|
2288
|
588
|
2289 if (conf->upstream.no_cache && conf->upstream.cache_bypass == NULL) {
|
|
2290 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
|
|
2291 "\"fastcgi_no_cache\" functionality has been changed in 0.8.46, "
|
|
2292 "now it should be used together with \"fastcgi_cache_bypass\"");
|
|
2293 }
|
|
2294
|
466
|
2295 ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
|
|
2296 prev->upstream.cache_valid, NULL);
|
|
2297
|
472
|
2298 if (conf->cache_key.value.data == NULL) {
|
|
2299 conf->cache_key = prev->cache_key;
|
|
2300 }
|
|
2301
|
466
|
2302 #endif
|
|
2303
|
58
|
2304 ngx_conf_merge_value(conf->upstream.pass_request_headers,
|
|
2305 prev->upstream.pass_request_headers, 1);
|
|
2306 ngx_conf_merge_value(conf->upstream.pass_request_body,
|
|
2307 prev->upstream.pass_request_body, 1);
|
|
2308
|
206
|
2309 ngx_conf_merge_value(conf->upstream.intercept_errors,
|
|
2310 prev->upstream.intercept_errors, 0);
|
58
|
2311
|
306
|
2312 ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL);
|
|
2313
|
640
|
2314 ngx_conf_merge_value(conf->keep_conn, prev->keep_conn, 0);
|
|
2315
|
56
|
2316
|
50
|
2317 ngx_conf_merge_str_value(conf->index, prev->index, "");
|
|
2318
|
356
|
2319 hash.max_size = 512;
|
|
2320 hash.bucket_size = ngx_align(64, ngx_cacheline_size);
|
|
2321 hash.name = "fastcgi_hide_headers_hash";
|
|
2322
|
|
2323 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,
|
584
|
2324 &prev->upstream, ngx_http_fastcgi_hide_headers, &hash)
|
198
|
2325 != NGX_OK)
|
|
2326 {
|
|
2327 return NGX_CONF_ERROR;
|
|
2328 }
|
|
2329
|
260
|
2330 if (conf->upstream.upstream == NULL) {
|
|
2331 conf->upstream.upstream = prev->upstream.upstream;
|
430
|
2332 }
|
|
2333
|
|
2334 if (conf->fastcgi_lengths == NULL) {
|
|
2335 conf->fastcgi_lengths = prev->fastcgi_lengths;
|
|
2336 conf->fastcgi_values = prev->fastcgi_values;
|
56
|
2337 }
|
|
2338
|
592
|
2339 if (conf->upstream.upstream || conf->fastcgi_lengths) {
|
|
2340 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
|
2341 if (clcf->handler == NULL && clcf->lmt_excpt) {
|
|
2342 clcf->handler = ngx_http_fastcgi_handler;
|
|
2343 }
|
|
2344 }
|
|
2345
|
438
|
2346 #if (NGX_PCRE)
|
|
2347 if (conf->split_regex == NULL) {
|
|
2348 conf->split_regex = prev->split_regex;
|
|
2349 conf->split_name = prev->split_name;
|
|
2350 }
|
|
2351 #endif
|
|
2352
|
648
|
2353 if (ngx_http_fastcgi_merge_params(cf, conf, prev) != NGX_OK) {
|
|
2354 return NGX_CONF_ERROR;
|
|
2355 }
|
|
2356
|
|
2357 return NGX_CONF_OK;
|
|
2358 }
|
|
2359
|
|
2360
|
|
2361 static ngx_int_t
|
|
2362 ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
|
|
2363 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev)
|
|
2364 {
|
|
2365 u_char *p;
|
|
2366 size_t size;
|
|
2367 uintptr_t *code;
|
|
2368 ngx_uint_t i, nsrc;
|
|
2369 ngx_array_t headers_names;
|
576
|
2370 #if (NGX_HTTP_CACHE)
|
648
|
2371 ngx_array_t params_merged;
|
|
2372 #endif
|
|
2373 ngx_keyval_t *src;
|
|
2374 ngx_hash_key_t *hk;
|
|
2375 ngx_hash_init_t hash;
|
|
2376 ngx_http_script_compile_t sc;
|
|
2377 ngx_http_script_copy_code_t *copy;
|
|
2378
|
|
2379 if (conf->params_source == NULL) {
|
|
2380 conf->params_source = prev->params_source;
|
|
2381
|
|
2382 if (prev->headers_hash.buckets
|
|
2383 #if (NGX_HTTP_CACHE)
|
|
2384 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
|
|
2385 #endif
|
|
2386 )
|
|
2387 {
|
|
2388 conf->flushes = prev->flushes;
|
|
2389 conf->params_len = prev->params_len;
|
|
2390 conf->params = prev->params;
|
|
2391 conf->headers_hash = prev->headers_hash;
|
|
2392 conf->header_params = prev->header_params;
|
|
2393
|
|
2394 return NGX_OK;
|
576
|
2395 }
|
648
|
2396 }
|
|
2397
|
|
2398 if (conf->params_source == NULL
|
|
2399 #if (NGX_HTTP_CACHE)
|
|
2400 && (conf->upstream.cache == NULL)
|
576
|
2401 #endif
|
648
|
2402 )
|
|
2403 {
|
|
2404 conf->headers_hash.buckets = (void *) 1;
|
|
2405 return NGX_OK;
|
58
|
2406 }
|
|
2407
|
|
2408 conf->params_len = ngx_array_create(cf->pool, 64, 1);
|
|
2409 if (conf->params_len == NULL) {
|
648
|
2410 return NGX_ERROR;
|
58
|
2411 }
|
122
|
2412
|
58
|
2413 conf->params = ngx_array_create(cf->pool, 512, 1);
|
|
2414 if (conf->params == NULL) {
|
648
|
2415 return NGX_ERROR;
|
58
|
2416 }
|
|
2417
|
576
|
2418 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
|
|
2419 != NGX_OK)
|
|
2420 {
|
648
|
2421 return NGX_ERROR;
|
576
|
2422 }
|
|
2423
|
648
|
2424 if (conf->params_source) {
|
|
2425 src = conf->params_source->elts;
|
|
2426 nsrc = conf->params_source->nelts;
|
|
2427
|
|
2428 } else {
|
|
2429 src = NULL;
|
|
2430 nsrc = 0;
|
|
2431 }
|
576
|
2432
|
|
2433 #if (NGX_HTTP_CACHE)
|
|
2434
|
|
2435 if (conf->upstream.cache) {
|
|
2436 ngx_keyval_t *h, *s;
|
|
2437
|
648
|
2438 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
|
|
2439 != NGX_OK)
|
|
2440 {
|
|
2441 return NGX_ERROR;
|
|
2442 }
|
|
2443
|
|
2444 for (i = 0; i < nsrc; i++) {
|
|
2445
|
|
2446 s = ngx_array_push(¶ms_merged);
|
|
2447 if (s == NULL) {
|
|
2448 return NGX_ERROR;
|
|
2449 }
|
|
2450
|
|
2451 *s = src[i];
|
|
2452 }
|
|
2453
|
|
2454 h = ngx_http_fastcgi_cache_headers;
|
|
2455
|
|
2456 while (h->key.len) {
|
|
2457
|
|
2458 src = params_merged.elts;
|
|
2459 nsrc = params_merged.nelts;
|
|
2460
|
|
2461 for (i = 0; i < nsrc; i++) {
|
576
|
2462 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
|
|
2463 goto next;
|
|
2464 }
|
|
2465 }
|
|
2466
|
648
|
2467 s = ngx_array_push(¶ms_merged);
|
576
|
2468 if (s == NULL) {
|
648
|
2469 return NGX_ERROR;
|
58
|
2470 }
|
|
2471
|
576
|
2472 *s = *h;
|
|
2473
|
|
2474 next:
|
|
2475
|
|
2476 h++;
|
|
2477 }
|
648
|
2478
|
|
2479 src = params_merged.elts;
|
|
2480 nsrc = params_merged.nelts;
|
576
|
2481 }
|
|
2482
|
|
2483 #endif
|
|
2484
|
648
|
2485 for (i = 0; i < nsrc; i++) {
|
576
|
2486
|
|
2487 if (src[i].key.len > sizeof("HTTP_") - 1
|
|
2488 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
|
|
2489 {
|
|
2490 hk = ngx_array_push(&headers_names);
|
|
2491 if (hk == NULL) {
|
648
|
2492 return NGX_ERROR;
|
58
|
2493 }
|
126
|
2494
|
576
|
2495 hk->key.len = src[i].key.len - 5;
|
|
2496 hk->key.data = src[i].key.data + 5;
|
|
2497 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len);
|
|
2498 hk->value = (void *) 1;
|
|
2499
|
|
2500 if (src[i].value.len == 0) {
|
|
2501 continue;
|
58
|
2502 }
|
576
|
2503 }
|
|
2504
|
|
2505 copy = ngx_array_push_n(conf->params_len,
|
|
2506 sizeof(ngx_http_script_copy_code_t));
|
|
2507 if (copy == NULL) {
|
648
|
2508 return NGX_ERROR;
|
576
|
2509 }
|
|
2510
|
|
2511 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
|
|
2512 copy->len = src[i].key.len;
|
|
2513
|
|
2514
|
|
2515 size = (sizeof(ngx_http_script_copy_code_t)
|
|
2516 + src[i].key.len + sizeof(uintptr_t) - 1)
|
648
|
2517 & ~(sizeof(uintptr_t) - 1);
|
576
|
2518
|
|
2519 copy = ngx_array_push_n(conf->params, size);
|
|
2520 if (copy == NULL) {
|
648
|
2521 return NGX_ERROR;
|
576
|
2522 }
|
|
2523
|
|
2524 copy->code = ngx_http_script_copy_code;
|
|
2525 copy->len = src[i].key.len;
|
|
2526
|
|
2527 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);
|
|
2528 ngx_memcpy(p, src[i].key.data, src[i].key.len);
|
|
2529
|
|
2530
|
|
2531 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2532
|
|
2533 sc.cf = cf;
|
|
2534 sc.source = &src[i].value;
|
|
2535 sc.flushes = &conf->flushes;
|
|
2536 sc.lengths = &conf->params_len;
|
|
2537 sc.values = &conf->params;
|
|
2538
|
|
2539 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
648
|
2540 return NGX_ERROR;
|
58
|
2541 }
|
|
2542
|
|
2543 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
2544 if (code == NULL) {
|
648
|
2545 return NGX_ERROR;
|
58
|
2546 }
|
|
2547
|
|
2548 *code = (uintptr_t) NULL;
|
|
2549
|
|
2550
|
|
2551 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
|
|
2552 if (code == NULL) {
|
648
|
2553 return NGX_ERROR;
|
58
|
2554 }
|
|
2555
|
|
2556 *code = (uintptr_t) NULL;
|
|
2557 }
|
|
2558
|
|
2559 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
|
|
2560 if (code == NULL) {
|
648
|
2561 return NGX_ERROR;
|
58
|
2562 }
|
|
2563
|
|
2564 *code = (uintptr_t) NULL;
|
|
2565
|
576
|
2566 conf->header_params = headers_names.nelts;
|
|
2567
|
|
2568 hash.hash = &conf->headers_hash;
|
|
2569 hash.key = ngx_hash_key_lc;
|
|
2570 hash.max_size = 512;
|
|
2571 hash.bucket_size = 64;
|
|
2572 hash.name = "fastcgi_params_hash";
|
|
2573 hash.pool = cf->pool;
|
|
2574 hash.temp_pool = NULL;
|
|
2575
|
648
|
2576 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
|
50
|
2577 }
|
58
|
2578
|
|
2579
|
122
|
2580 static ngx_int_t
|
|
2581 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
|
|
2582 ngx_http_variable_value_t *v, uintptr_t data)
|
58
|
2583 {
|
|
2584 u_char *p;
|
438
|
2585 ngx_http_fastcgi_ctx_t *f;
|
58
|
2586 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
2587
|
438
|
2588 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
2589
|
440
|
2590 f = ngx_http_fastcgi_split(r, flcf);
|
|
2591
|
|
2592 if (f == NULL) {
|
438
|
2593 return NGX_ERROR;
|
|
2594 }
|
|
2595
|
|
2596 if (f->script_name.len == 0
|
|
2597 || f->script_name.data[f->script_name.len - 1] != '/')
|
|
2598 {
|
|
2599 v->len = f->script_name.len;
|
284
|
2600 v->valid = 1;
|
340
|
2601 v->no_cacheable = 0;
|
284
|
2602 v->not_found = 0;
|
438
|
2603 v->data = f->script_name.data;
|
284
|
2604
|
122
|
2605 return NGX_OK;
|
58
|
2606 }
|
|
2607
|
438
|
2608 v->len = f->script_name.len + flcf->index.len;
|
|
2609
|
|
2610 v->data = ngx_pnalloc(r->pool, v->len);
|
|
2611 if (v->data == NULL) {
|
|
2612 return NGX_ERROR;
|
|
2613 }
|
|
2614
|
|
2615 p = ngx_copy(v->data, f->script_name.data, f->script_name.len);
|
|
2616 ngx_memcpy(p, flcf->index.data, flcf->index.len);
|
|
2617
|
122
|
2618 return NGX_OK;
|
58
|
2619 }
|
|
2620
|
|
2621
|
438
|
2622 static ngx_int_t
|
|
2623 ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
|
|
2624 ngx_http_variable_value_t *v, uintptr_t data)
|
|
2625 {
|
|
2626 ngx_http_fastcgi_ctx_t *f;
|
|
2627 ngx_http_fastcgi_loc_conf_t *flcf;
|
|
2628
|
|
2629 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
|
|
2630
|
440
|
2631 f = ngx_http_fastcgi_split(r, flcf);
|
|
2632
|
|
2633 if (f == NULL) {
|
438
|
2634 return NGX_ERROR;
|
|
2635 }
|
|
2636
|
|
2637 v->len = f->path_info.len;
|
|
2638 v->valid = 1;
|
|
2639 v->no_cacheable = 0;
|
|
2640 v->not_found = 0;
|
|
2641 v->data = f->path_info.data;
|
|
2642
|
|
2643 return NGX_OK;
|
|
2644 }
|
|
2645
|
|
2646
|
440
|
2647 static ngx_http_fastcgi_ctx_t *
|
|
2648 ngx_http_fastcgi_split(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
|
438
|
2649 {
|
440
|
2650 ngx_http_fastcgi_ctx_t *f;
|
438
|
2651 #if (NGX_PCRE)
|
440
|
2652 ngx_int_t n;
|
|
2653 int captures[(1 + 2) * 3];
|
|
2654
|
|
2655 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
2656
|
|
2657 if (f == NULL) {
|
|
2658 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
|
2659 if (f == NULL) {
|
|
2660 return NULL;
|
|
2661 }
|
|
2662
|
|
2663 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
|
2664 }
|
438
|
2665
|
|
2666 if (f->script_name.len) {
|
440
|
2667 return f;
|
438
|
2668 }
|
|
2669
|
|
2670 if (flcf->split_regex == NULL) {
|
|
2671 f->script_name = r->uri;
|
440
|
2672 return f;
|
438
|
2673 }
|
|
2674
|
|
2675 n = ngx_regex_exec(flcf->split_regex, &r->uri, captures, (1 + 2) * 3);
|
|
2676
|
546
|
2677 if (n >= 0) { /* match */
|
|
2678 f->script_name.len = captures[3] - captures[2];
|
592
|
2679 f->script_name.data = r->uri.data + captures[2];
|
546
|
2680
|
|
2681 f->path_info.len = captures[5] - captures[4];
|
592
|
2682 f->path_info.data = r->uri.data + captures[4];
|
546
|
2683
|
|
2684 return f;
|
|
2685 }
|
|
2686
|
438
|
2687 if (n == NGX_REGEX_NO_MATCHED) {
|
|
2688 f->script_name = r->uri;
|
440
|
2689 return f;
|
438
|
2690 }
|
|
2691
|
546
|
2692 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
2693 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"",
|
|
2694 n, &r->uri, &flcf->split_name);
|
|
2695 return NULL;
|
438
|
2696
|
|
2697 #else
|
|
2698
|
440
|
2699 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
|
|
2700
|
|
2701 if (f == NULL) {
|
|
2702 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
|
|
2703 if (f == NULL) {
|
|
2704 return NULL;
|
|
2705 }
|
|
2706
|
|
2707 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module);
|
|
2708 }
|
|
2709
|
438
|
2710 f->script_name = r->uri;
|
|
2711
|
440
|
2712 return f;
|
438
|
2713
|
|
2714 #endif
|
|
2715 }
|
|
2716
|
|
2717
|
58
|
2718 static char *
|
|
2719 ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2720 {
|
430
|
2721 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2722
|
|
2723 ngx_url_t u;
|
|
2724 ngx_str_t *value, *url;
|
|
2725 ngx_uint_t n;
|
|
2726 ngx_http_core_loc_conf_t *clcf;
|
|
2727 ngx_http_script_compile_t sc;
|
|
2728
|
|
2729 if (flcf->upstream.upstream || flcf->fastcgi_lengths) {
|
104
|
2730 return "is duplicate";
|
|
2731 }
|
|
2732
|
430
|
2733 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
510
|
2734
|
430
|
2735 clcf->handler = ngx_http_fastcgi_handler;
|
|
2736
|
510
|
2737 if (clcf->name.data[clcf->name.len - 1] == '/') {
|
|
2738 clcf->auto_redirect = 1;
|
|
2739 }
|
|
2740
|
58
|
2741 value = cf->args->elts;
|
|
2742
|
430
|
2743 url = &value[1];
|
|
2744
|
|
2745 n = ngx_http_script_variables_count(url);
|
|
2746
|
|
2747 if (n) {
|
|
2748
|
|
2749 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2750
|
|
2751 sc.cf = cf;
|
|
2752 sc.source = url;
|
|
2753 sc.lengths = &flcf->fastcgi_lengths;
|
|
2754 sc.values = &flcf->fastcgi_values;
|
|
2755 sc.variables = n;
|
|
2756 sc.complete_lengths = 1;
|
|
2757 sc.complete_values = 1;
|
|
2758
|
|
2759 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2760 return NGX_CONF_ERROR;
|
|
2761 }
|
|
2762
|
|
2763 return NGX_CONF_OK;
|
|
2764 }
|
|
2765
|
200
|
2766 ngx_memzero(&u, sizeof(ngx_url_t));
|
|
2767
|
|
2768 u.url = value[1];
|
260
|
2769 u.no_resolve = 1;
|
|
2770
|
430
|
2771 flcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
|
|
2772 if (flcf->upstream.upstream == NULL) {
|
58
|
2773 return NGX_CONF_ERROR;
|
|
2774 }
|
|
2775
|
|
2776 return NGX_CONF_OK;
|
|
2777 }
|
|
2778
|
|
2779
|
|
2780 static char *
|
438
|
2781 ngx_http_fastcgi_split_path_info(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2782 {
|
|
2783 #if (NGX_PCRE)
|
|
2784 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2785
|
546
|
2786 ngx_str_t *value;
|
|
2787 ngx_regex_compile_t rc;
|
|
2788 u_char errstr[NGX_MAX_CONF_ERRSTR];
|
438
|
2789
|
|
2790 value = cf->args->elts;
|
|
2791
|
|
2792 flcf->split_name = value[1];
|
|
2793
|
546
|
2794 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
|
|
2795
|
|
2796 rc.pattern = value[1];
|
|
2797 rc.pool = cf->pool;
|
|
2798 rc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
2799 rc.err.data = errstr;
|
|
2800
|
|
2801 if (ngx_regex_compile(&rc) != NGX_OK) {
|
|
2802 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
438
|
2803 return NGX_CONF_ERROR;
|
|
2804 }
|
|
2805
|
546
|
2806 if (rc.captures != 2) {
|
438
|
2807 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2808 "pattern \"%V\" must have 2 captures", &value[1]);
|
|
2809 return NGX_CONF_ERROR;
|
|
2810 }
|
|
2811
|
546
|
2812 flcf->split_regex = rc.regex;
|
|
2813
|
438
|
2814 return NGX_CONF_OK;
|
|
2815
|
|
2816 #else
|
|
2817
|
|
2818 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2819 "\"%V\" requires PCRE library", &cmd->name);
|
|
2820 return NGX_CONF_ERROR;
|
|
2821
|
|
2822 #endif
|
|
2823 }
|
|
2824
|
|
2825
|
|
2826 static char *
|
320
|
2827 ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2828 {
|
|
2829 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2830
|
|
2831 ngx_str_t *value;
|
|
2832 ngx_http_script_compile_t sc;
|
|
2833
|
496
|
2834 if (flcf->upstream.store != NGX_CONF_UNSET
|
|
2835 || flcf->upstream.store_lengths)
|
320
|
2836 {
|
|
2837 return "is duplicate";
|
|
2838 }
|
|
2839
|
|
2840 value = cf->args->elts;
|
|
2841
|
496
|
2842 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
2843 flcf->upstream.store = 0;
|
320
|
2844 return NGX_CONF_OK;
|
|
2845 }
|
|
2846
|
496
|
2847 #if (NGX_HTTP_CACHE)
|
|
2848
|
|
2849 if (flcf->upstream.cache != NGX_CONF_UNSET_PTR
|
|
2850 && flcf->upstream.cache != NULL)
|
|
2851 {
|
|
2852 return "is incompatible with \"fastcgi_cache\"";
|
|
2853 }
|
|
2854
|
|
2855 #endif
|
|
2856
|
|
2857 if (ngx_strcmp(value[1].data, "on") == 0) {
|
|
2858 flcf->upstream.store = 1;
|
320
|
2859 return NGX_CONF_OK;
|
|
2860 }
|
|
2861
|
|
2862 /* include the terminating '\0' into script */
|
|
2863 value[1].len++;
|
|
2864
|
|
2865 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
|
2866
|
|
2867 sc.cf = cf;
|
|
2868 sc.source = &value[1];
|
|
2869 sc.lengths = &flcf->upstream.store_lengths;
|
|
2870 sc.values = &flcf->upstream.store_values;
|
340
|
2871 sc.variables = ngx_http_script_variables_count(&value[1]);
|
320
|
2872 sc.complete_lengths = 1;
|
|
2873 sc.complete_values = 1;
|
|
2874
|
|
2875 if (ngx_http_script_compile(&sc) != NGX_OK) {
|
|
2876 return NGX_CONF_ERROR;
|
|
2877 }
|
|
2878
|
|
2879 return NGX_CONF_OK;
|
|
2880 }
|
|
2881
|
|
2882
|
466
|
2883 #if (NGX_HTTP_CACHE)
|
|
2884
|
|
2885 static char *
|
|
2886 ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2887 {
|
|
2888 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2889
|
|
2890 ngx_str_t *value;
|
|
2891
|
|
2892 value = cf->args->elts;
|
|
2893
|
|
2894 if (flcf->upstream.cache != NGX_CONF_UNSET_PTR) {
|
|
2895 return "is duplicate";
|
|
2896 }
|
|
2897
|
|
2898 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
2899 flcf->upstream.cache = NULL;
|
|
2900 return NGX_CONF_OK;
|
|
2901 }
|
|
2902
|
496
|
2903 if (flcf->upstream.store > 0 || flcf->upstream.store_lengths) {
|
|
2904 return "is incompatible with \"fastcgi_store\"";
|
|
2905 }
|
|
2906
|
466
|
2907 flcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
|
|
2908 &ngx_http_fastcgi_module);
|
|
2909 if (flcf->upstream.cache == NULL) {
|
|
2910 return NGX_CONF_ERROR;
|
|
2911 }
|
|
2912
|
|
2913 return NGX_CONF_OK;
|
|
2914 }
|
|
2915
|
|
2916
|
|
2917 static char *
|
|
2918 ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
2919 {
|
|
2920 ngx_http_fastcgi_loc_conf_t *flcf = conf;
|
|
2921
|
|
2922 ngx_str_t *value;
|
|
2923 ngx_http_compile_complex_value_t ccv;
|
|
2924
|
|
2925 value = cf->args->elts;
|
|
2926
|
|
2927 if (flcf->cache_key.value.len) {
|
|
2928 return "is duplicate";
|
|
2929 }
|
|
2930
|
|
2931 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
|
|
2932
|
|
2933 ccv.cf = cf;
|
|
2934 ccv.value = &value[1];
|
|
2935 ccv.complex_value = &flcf->cache_key;
|
|
2936
|
|
2937 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
|
|
2938 return NGX_CONF_ERROR;
|
|
2939 }
|
|
2940
|
|
2941 return NGX_CONF_OK;
|
|
2942 }
|
|
2943
|
|
2944 #endif
|
|
2945
|
|
2946
|
320
|
2947 static char *
|
58
|
2948 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
|
|
2949 {
|
|
2950 #if (NGX_FREEBSD)
|
|
2951 ssize_t *np = data;
|
|
2952
|
222
|
2953 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {
|
58
|
2954 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2955 "\"fastcgi_send_lowat\" must be less than %d "
|
|
2956 "(sysctl net.inet.tcp.sendspace)",
|
|
2957 ngx_freebsd_net_inet_tcp_sendspace);
|
|
2958
|
|
2959 return NGX_CONF_ERROR;
|
|
2960 }
|
|
2961
|
|
2962 #elif !(NGX_HAVE_SO_SNDLOWAT)
|
|
2963 ssize_t *np = data;
|
|
2964
|
|
2965 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
2966 "\"fastcgi_send_lowat\" is not supported, ignored");
|
|
2967
|
|
2968 *np = 0;
|
|
2969
|
|
2970 #endif
|
|
2971
|
|
2972 return NGX_CONF_OK;
|
|
2973 }
|