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