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