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