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