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