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