Mercurial > hg > nginx
comparison src/http/modules/ngx_http_fastcgi_module.c @ 509:9b8c906f6e63 release-0.1.29
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 12 May 2005 14:58:06 +0000 |
parents | cd3117ad9aab |
children | 417a087c9c4d |
comparison
equal
deleted
inserted
replaced
508:ca1020ce99ba | 509:9b8c906f6e63 |
---|---|
13 typedef struct { | 13 typedef struct { |
14 ngx_http_upstream_conf_t upstream; | 14 ngx_http_upstream_conf_t upstream; |
15 | 15 |
16 ngx_peers_t *peers; | 16 ngx_peers_t *peers; |
17 | 17 |
18 ngx_uint_t params; | |
19 | |
20 ngx_str_t root; | |
21 ngx_str_t index; | 18 ngx_str_t index; |
22 | 19 |
23 ngx_array_t *vars; | 20 ngx_array_t *params_len; |
24 | 21 ngx_array_t *params; |
25 ngx_str_t *location; | 22 ngx_array_t *params_source; |
26 } ngx_http_fastcgi_loc_conf_t; | 23 } ngx_http_fastcgi_loc_conf_t; |
27 | |
28 | |
29 typedef struct { | |
30 ngx_list_t headers; | |
31 | |
32 ngx_table_elt_t *status; | |
33 | |
34 ngx_table_elt_t *content_type; | |
35 ngx_table_elt_t *content_length; | |
36 ngx_table_elt_t *x_powered_by; | |
37 | |
38 #if (NGX_HTTP_GZIP) | |
39 ngx_table_elt_t *content_encoding; | |
40 #endif | |
41 } ngx_http_fastcgi_headers_in_t; | |
42 | |
43 | |
44 typedef struct { | |
45 ngx_http_fastcgi_headers_in_t headers_in; | |
46 } ngx_http_fastcgi_upstream_t; | |
47 | 24 |
48 | 25 |
49 typedef enum { | 26 typedef enum { |
50 ngx_http_fastcgi_st_version = 0, | 27 ngx_http_fastcgi_st_version = 0, |
51 ngx_http_fastcgi_st_type, | 28 ngx_http_fastcgi_st_type, |
67 ngx_uint_t type; | 44 ngx_uint_t type; |
68 size_t length; | 45 size_t length; |
69 size_t padding; | 46 size_t padding; |
70 | 47 |
71 ngx_uint_t header; | 48 ngx_uint_t header; |
72 | |
73 ngx_http_fastcgi_upstream_t *upstream; | |
74 } ngx_http_fastcgi_ctx_t; | 49 } ngx_http_fastcgi_ctx_t; |
75 | |
76 | |
77 #define NGX_HTTP_FASTCGI_REMOTE_ADDR 0x00000002 | |
78 #define NGX_HTTP_FASTCGI_REMOTE_USER 0x00000004 | |
79 #define NGX_HTTP_FASTCGI_SERVER_NAME 0x00000008 | |
80 #define NGX_HTTP_FASTCGI_SERVER_ADDR 0x00000010 | |
81 #define NGX_HTTP_FASTCGI_SERVER_PORT 0x00000020 | |
82 #define NGX_HTTP_FASTCGI_SCRIPT_NAME 0x00000040 | |
83 #define NGX_HTTP_FASTCGI_AUTH_TYPE 0x00000080 | |
84 #define NGX_HTTP_FASTCGI_SERVER_PROTOCOL 0x00000100 | |
85 #define NGX_HTTP_FASTCGI_SERVER_SOFTWARE 0x00000200 | |
86 #define NGX_HTTP_FASTCGI_GATEWAY_INTERFACE 0x00000400 | |
87 #define NGX_HTTP_FASTCGI_REQUEST_URI 0x00000800 | |
88 #define NGX_HTTP_FASTCGI_REDIRECT_STATUS 0x00001000 | |
89 #define NGX_HTTP_FASTCGI_DOCUMENT_ROOT 0x00002000 | |
90 #define NGX_HTTP_FASTCGI_SCRIPT_FILENAME 0x00004000 | |
91 #define NGX_HTTP_FASTCGI_REMOTE_PORT 0x00008000 | |
92 | 50 |
93 | 51 |
94 #define NGX_HTTP_FASTCGI_RESPONDER 1 | 52 #define NGX_HTTP_FASTCGI_RESPONDER 1 |
95 | 53 |
96 #define NGX_HTTP_FASTCGI_BEGIN_REQUEST 1 | 54 #define NGX_HTTP_FASTCGI_BEGIN_REQUEST 1 |
121 u_char flags; | 79 u_char flags; |
122 u_char reserved[5]; | 80 u_char reserved[5]; |
123 } ngx_http_fastcgi_begin_request_t; | 81 } ngx_http_fastcgi_begin_request_t; |
124 | 82 |
125 | 83 |
84 typedef struct { | |
85 u_char version; | |
86 u_char type; | |
87 u_char request_id_hi; | |
88 u_char request_id_lo; | |
89 } ngx_http_fastcgi_header_small_t; | |
90 | |
91 | |
92 typedef struct { | |
93 ngx_http_fastcgi_header_t h0; | |
94 ngx_http_fastcgi_begin_request_t br; | |
95 ngx_http_fastcgi_header_small_t h1; | |
96 } ngx_http_fastcgi_request_start_t; | |
97 | |
98 | |
126 static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r); | 99 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); | 100 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); | 101 static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r); |
129 static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r); | |
130 static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, | 102 static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, |
131 ngx_buf_t *buf); | 103 ngx_buf_t *buf); |
132 static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r, | 104 static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r, |
133 ngx_http_fastcgi_ctx_t *f); | 105 ngx_http_fastcgi_ctx_t *f); |
134 static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r); | 106 static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r); |
135 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, | 107 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, |
136 ngx_int_t rc); | 108 ngx_int_t rc); |
137 | 109 |
110 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); | |
111 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | |
112 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | |
113 void *parent, void *child); | |
114 static ngx_http_variable_value_t * | |
115 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, | |
116 uintptr_t data); | |
117 | |
138 static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 118 static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
139 void *conf); | |
140 static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, | |
141 void *conf); | 119 void *conf); |
142 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, | 120 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, |
143 void *data); | 121 void *data); |
144 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | 122 |
145 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | 123 |
146 void *parent, void *child); | 124 static ngx_http_fastcgi_request_start_t ngx_http_fastcgi_request_start = { |
147 | 125 { 1, /* version */ |
148 | 126 NGX_HTTP_FASTCGI_BEGIN_REQUEST, /* type */ |
127 0, /* request_id_hi */ | |
128 1, /* request_id_lo */ | |
129 0, /* content_length_hi */ | |
130 sizeof(ngx_http_fastcgi_begin_request_t), /* content_length_lo */ | |
131 0, /* padding_length */ | |
132 0 }, /* reserved */ | |
133 | |
134 { 0, /* role_hi */ | |
135 NGX_HTTP_FASTCGI_RESPONDER, /* role_lo */ | |
136 0, /* NGX_HTTP_FASTCGI_KEEP_CONN */ /* flags */ | |
137 { 0, 0, 0, 0, 0 } }, /* reserved[5] */ | |
138 | |
139 { 1, /* version */ | |
140 NGX_HTTP_FASTCGI_PARAMS, /* type */ | |
141 0, /* request_id_hi */ | |
142 1 }, /* request_id_lo */ | |
143 | |
144 }; | |
145 | |
146 | |
147 #if 0 | |
149 static ngx_str_t ngx_http_fastcgi_methods[] = { | 148 static ngx_str_t ngx_http_fastcgi_methods[] = { |
150 ngx_string("GET"), | 149 ngx_string("GET"), |
151 ngx_string("HEAD"), | 150 ngx_string("HEAD"), |
152 ngx_string("POST") | 151 ngx_string("POST") |
153 }; | 152 }; |
153 #endif | |
154 | |
155 | |
156 static ngx_str_t ngx_http_fastcgi_script_name = | |
157 ngx_string("fastcgi_script_name"); | |
154 | 158 |
155 | 159 |
156 #if (NGX_PCRE) | 160 #if (NGX_PCRE) |
157 static ngx_str_t ngx_http_fastcgi_uri = ngx_string("/"); | 161 static ngx_str_t ngx_http_fastcgi_uri = ngx_string("/"); |
158 #endif | 162 #endif |
159 | 163 |
160 | 164 |
161 static ngx_http_header_t ngx_http_fastcgi_headers_in[] = { | 165 static ngx_conf_post_t ngx_http_fastcgi_lowat_post = |
162 { ngx_string("Status"), offsetof(ngx_http_fastcgi_headers_in_t, status) }, | 166 { ngx_http_fastcgi_lowat_check }; |
163 | 167 |
164 { ngx_string("Content-Type"), | 168 static ngx_conf_enum_t ngx_http_fastcgi_set_methods[] = { |
165 offsetof(ngx_http_fastcgi_headers_in_t, content_type) }, | 169 { ngx_string("get"), NGX_HTTP_GET }, |
166 | |
167 { ngx_string("Content-Length"), | |
168 offsetof(ngx_http_fastcgi_headers_in_t, content_length) }, | |
169 | |
170 { ngx_string("X-Powered-By"), | |
171 offsetof(ngx_http_fastcgi_headers_in_t, x_powered_by) }, | |
172 | |
173 #if (NGX_HTTP_GZIP) | |
174 { ngx_string("Content-Encoding"), | |
175 offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) }, | |
176 #endif | |
177 | |
178 { ngx_null_string, 0 } | 170 { ngx_null_string, 0 } |
179 }; | 171 }; |
180 | |
181 | |
182 static ngx_conf_post_t ngx_http_fastcgi_lowat_post = | |
183 { ngx_http_fastcgi_lowat_check }; | |
184 | 172 |
185 static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = { | 173 static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = { |
186 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, | 174 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, |
187 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, | 175 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, |
188 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, | 176 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, |
190 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, | 178 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
191 { ngx_null_string, 0 } | 179 { ngx_null_string, 0 } |
192 }; | 180 }; |
193 | 181 |
194 | 182 |
195 static ngx_conf_bitmask_t ngx_http_fastcgi_params_masks[] = { | |
196 { ngx_string("remote_addr"), NGX_HTTP_FASTCGI_REMOTE_ADDR }, | |
197 { ngx_string("server_port"), NGX_HTTP_FASTCGI_SERVER_PORT }, | |
198 { ngx_string("server_addr"), NGX_HTTP_FASTCGI_SERVER_ADDR }, | |
199 { ngx_string("server_name"), NGX_HTTP_FASTCGI_SERVER_NAME }, | |
200 { ngx_string("script_name"), NGX_HTTP_FASTCGI_SCRIPT_NAME }, | |
201 | |
202 { ngx_string("server_protocol"), NGX_HTTP_FASTCGI_SERVER_PROTOCOL }, | |
203 { ngx_string("server_software"), NGX_HTTP_FASTCGI_SERVER_SOFTWARE }, | |
204 { ngx_string("gateway_interface"), NGX_HTTP_FASTCGI_GATEWAY_INTERFACE }, | |
205 | |
206 { ngx_string("redirect_status"), NGX_HTTP_FASTCGI_REDIRECT_STATUS }, | |
207 { ngx_string("request_uri"), NGX_HTTP_FASTCGI_REQUEST_URI }, | |
208 | |
209 { ngx_string("document_root"), NGX_HTTP_FASTCGI_DOCUMENT_ROOT }, | |
210 { ngx_string("script_filename"), NGX_HTTP_FASTCGI_SCRIPT_FILENAME }, | |
211 { ngx_string("remote_port"), NGX_HTTP_FASTCGI_REMOTE_PORT }, | |
212 | |
213 { ngx_null_string, 0 } | |
214 }; | |
215 | |
216 | |
217 static ngx_command_t ngx_http_fastcgi_commands[] = { | 183 static ngx_command_t ngx_http_fastcgi_commands[] = { |
218 | 184 |
219 { ngx_string("fastcgi_pass"), | 185 { ngx_string("fastcgi_pass"), |
220 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 186 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
221 ngx_http_fastcgi_pass, | 187 ngx_http_fastcgi_pass, |
222 NGX_HTTP_LOC_CONF_OFFSET, | 188 NGX_HTTP_LOC_CONF_OFFSET, |
223 0, | 189 0, |
224 NULL }, | 190 NULL }, |
225 | 191 |
226 { ngx_string("fastcgi_root"), | |
227 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
228 ngx_conf_set_str_slot, | |
229 NGX_HTTP_LOC_CONF_OFFSET, | |
230 offsetof(ngx_http_fastcgi_loc_conf_t, root), | |
231 NULL }, | |
232 | |
233 { ngx_string("fastcgi_index"), | 192 { ngx_string("fastcgi_index"), |
234 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 193 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
235 ngx_conf_set_str_slot, | 194 ngx_conf_set_str_slot, |
236 NGX_HTTP_LOC_CONF_OFFSET, | 195 NGX_HTTP_LOC_CONF_OFFSET, |
237 offsetof(ngx_http_fastcgi_loc_conf_t, index), | 196 offsetof(ngx_http_fastcgi_loc_conf_t, index), |
263 ngx_conf_set_size_slot, | 222 ngx_conf_set_size_slot, |
264 NGX_HTTP_LOC_CONF_OFFSET, | 223 NGX_HTTP_LOC_CONF_OFFSET, |
265 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.header_buffer_size), | 224 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.header_buffer_size), |
266 NULL }, | 225 NULL }, |
267 | 226 |
227 { ngx_string("fastcgi_method"), | |
228 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
229 ngx_conf_set_enum_slot, | |
230 NGX_HTTP_LOC_CONF_OFFSET, | |
231 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.method), | |
232 ngx_http_fastcgi_set_methods }, | |
233 | |
234 { ngx_string("fastcgi_pass_request_headers"), | |
235 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
236 ngx_conf_set_flag_slot, | |
237 NGX_HTTP_LOC_CONF_OFFSET, | |
238 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_headers), | |
239 NULL }, | |
240 | |
241 { ngx_string("fastcgi_pass_request_body"), | |
242 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
243 ngx_conf_set_flag_slot, | |
244 NGX_HTTP_LOC_CONF_OFFSET, | |
245 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_request_body), | |
246 NULL }, | |
247 | |
268 { ngx_string("fastcgi_redirect_errors"), | 248 { ngx_string("fastcgi_redirect_errors"), |
269 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 249 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
270 ngx_conf_set_flag_slot, | 250 ngx_conf_set_flag_slot, |
271 NGX_HTTP_LOC_CONF_OFFSET, | 251 NGX_HTTP_LOC_CONF_OFFSET, |
272 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.redirect_errors), | 252 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.redirect_errors), |
274 | 254 |
275 { ngx_string("fastcgi_x_powered_by"), | 255 { ngx_string("fastcgi_x_powered_by"), |
276 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 256 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
277 ngx_conf_set_flag_slot, | 257 ngx_conf_set_flag_slot, |
278 NGX_HTTP_LOC_CONF_OFFSET, | 258 NGX_HTTP_LOC_CONF_OFFSET, |
279 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.x_powered_by), | 259 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.pass_x_powered_by), |
280 NULL }, | 260 NULL }, |
281 | 261 |
282 { ngx_string("fastcgi_read_timeout"), | 262 { ngx_string("fastcgi_read_timeout"), |
283 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 263 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
284 ngx_conf_set_msec_slot, | 264 ngx_conf_set_msec_slot, |
326 ngx_conf_set_bitmask_slot, | 306 ngx_conf_set_bitmask_slot, |
327 NGX_HTTP_LOC_CONF_OFFSET, | 307 NGX_HTTP_LOC_CONF_OFFSET, |
328 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream), | 308 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.next_upstream), |
329 &ngx_http_fastcgi_next_upstream_masks }, | 309 &ngx_http_fastcgi_next_upstream_masks }, |
330 | 310 |
331 { ngx_string("fastcgi_set_var"), | 311 { ngx_string("fastcgi_param"), |
332 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 312 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, |
333 ngx_http_fastcgi_set_var, | 313 ngx_conf_set_table_elt_slot, |
334 NGX_HTTP_LOC_CONF_OFFSET, | 314 NGX_HTTP_LOC_CONF_OFFSET, |
335 0, | 315 offsetof(ngx_http_fastcgi_loc_conf_t, params_source), |
336 NULL }, | 316 NULL }, |
337 | |
338 { ngx_string("fastcgi_params"), | |
339 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_ANY, | |
340 ngx_conf_set_bitmask_slot, | |
341 NGX_HTTP_LOC_CONF_OFFSET, | |
342 offsetof(ngx_http_fastcgi_loc_conf_t, params), | |
343 &ngx_http_fastcgi_params_masks }, | |
344 | 317 |
345 ngx_null_command | 318 ngx_null_command |
346 }; | 319 }; |
347 | 320 |
348 | 321 |
349 ngx_http_module_t ngx_http_fastcgi_module_ctx = { | 322 ngx_http_module_t ngx_http_fastcgi_module_ctx = { |
350 NULL, /* pre conf */ | 323 ngx_http_fastcgi_add_variables, /* preconfiguration */ |
324 NULL, /* postconfiguration */ | |
351 | 325 |
352 NULL, /* create main configuration */ | 326 NULL, /* create main configuration */ |
353 NULL, /* init main configuration */ | 327 NULL, /* init main configuration */ |
354 | 328 |
355 NULL, /* create server configuration */ | 329 NULL, /* create server configuration */ |
359 ngx_http_fastcgi_merge_loc_conf /* merge location configuration */ | 333 ngx_http_fastcgi_merge_loc_conf /* merge location configuration */ |
360 }; | 334 }; |
361 | 335 |
362 | 336 |
363 ngx_module_t ngx_http_fastcgi_module = { | 337 ngx_module_t ngx_http_fastcgi_module = { |
364 NGX_MODULE, | 338 NGX_MODULE_V1, |
365 &ngx_http_fastcgi_module_ctx, /* module context */ | 339 &ngx_http_fastcgi_module_ctx, /* module context */ |
366 ngx_http_fastcgi_commands, /* module directives */ | 340 ngx_http_fastcgi_commands, /* module directives */ |
367 NGX_HTTP_MODULE, /* module type */ | 341 NGX_HTTP_MODULE, /* module type */ |
368 NULL, /* init module */ | 342 NULL, /* init module */ |
369 NULL /* init process */ | 343 NULL /* init process */ |
394 | 368 |
395 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module; | 369 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module; |
396 | 370 |
397 u->conf = &flcf->upstream; | 371 u->conf = &flcf->upstream; |
398 | 372 |
399 u->location0 = flcf->location; | |
400 | |
401 u->create_request = ngx_http_fastcgi_create_request; | 373 u->create_request = ngx_http_fastcgi_create_request; |
402 u->reinit_request = ngx_http_fastcgi_reinit_request; | 374 u->reinit_request = ngx_http_fastcgi_reinit_request; |
403 u->process_header = ngx_http_fastcgi_process_header; | 375 u->process_header = ngx_http_fastcgi_process_header; |
404 u->send_header = ngx_http_fastcgi_send_header; | |
405 u->abort_request = ngx_http_fastcgi_abort_request; | 376 u->abort_request = ngx_http_fastcgi_abort_request; |
406 u->finalize_request = ngx_http_fastcgi_finalize_request; | 377 u->finalize_request = ngx_http_fastcgi_finalize_request; |
407 | 378 |
408 u->pipe.input_filter = ngx_http_fastcgi_input_filter; | 379 u->pipe.input_filter = ngx_http_fastcgi_input_filter; |
409 u->pipe.input_ctx = r; | 380 u->pipe.input_ctx = r; |
410 | |
411 u->log_ctx = r->connection->log->data; | |
412 u->log_handler = ngx_http_upstream_log_error; | |
413 | |
414 u->schema0.len = sizeof("fastcgi://") - 1; | |
415 u->schema0.data = (u_char *) "fastcgi://"; | |
416 u->uri0.len = sizeof("/") - 1; | |
417 u->uri0.data = (u_char *) "/"; | |
418 | 381 |
419 r->upstream = u; | 382 r->upstream = u; |
420 | 383 |
421 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); | 384 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); |
422 | 385 |
429 | 392 |
430 | 393 |
431 static ngx_int_t | 394 static ngx_int_t |
432 ngx_http_fastcgi_create_request(ngx_http_request_t *r) | 395 ngx_http_fastcgi_create_request(ngx_http_request_t *r) |
433 { | 396 { |
434 u_char ch, *pos, addr_text[INET_ADDRSTRLEN], | 397 off_t file_pos; |
435 port_text[sizeof("65535") - 1]; | 398 u_char ch, *pos; |
436 size_t size, len, index, padding, | 399 size_t size, len, key_len, val_len, padding; |
437 addr_len, port_len; | 400 ngx_uint_t i, n, next; |
438 off_t file_pos; | 401 ngx_buf_t *b; |
439 ngx_buf_t *b; | 402 ngx_chain_t *cl, *body; |
440 socklen_t slen; | 403 ngx_list_part_t *part; |
441 ngx_chain_t *cl, *body; | 404 ngx_table_elt_t *header; |
442 ngx_uint_t i, n, next, *vindex, port; | 405 ngx_http_script_code_pt code; |
443 ngx_list_part_t *part; | 406 ngx_http_script_engine_t e, le; |
444 ngx_table_elt_t *header; | 407 ngx_http_fastcgi_header_t *h; |
445 struct sockaddr_in sin, *sinp; | 408 ngx_http_fastcgi_loc_conf_t *flcf; |
446 ngx_http_variable_t *var; | 409 ngx_http_script_len_code_pt lcode; |
447 ngx_http_variable_value_t *value; | 410 |
448 ngx_http_core_loc_conf_t *clcf; | 411 len = 0; |
449 ngx_http_core_main_conf_t *cmcf; | |
450 ngx_http_fastcgi_header_t *h; | |
451 ngx_http_fastcgi_loc_conf_t *flcf; | |
452 ngx_http_fastcgi_begin_request_t *br; | |
453 | |
454 | 412 |
455 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); | 413 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
456 | 414 |
457 if ((flcf->params & NGX_HTTP_FASTCGI_SERVER_ADDR) && r->in_addr == 0) { | 415 if (flcf->params_len) { |
458 | 416 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); |
459 slen = sizeof(struct sockaddr_in); | 417 |
460 if (getsockname(r->connection->fd, | 418 le.ip = flcf->params_len->elts; |
461 (struct sockaddr *) &sin, &slen) == -1) | 419 le.request = r; |
462 { | 420 |
463 ngx_log_error(NGX_LOG_CRIT, r->connection->log, | 421 while (*(uintptr_t *) le.ip) { |
464 ngx_socket_errno, "getsockname() failed"); | 422 |
465 return NGX_ERROR; | 423 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
466 } | 424 key_len = lcode(&le); |
467 | 425 |
468 r->in_addr = sin.sin_addr.s_addr; | 426 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { |
469 } | 427 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
470 | 428 } |
471 addr_len = ngx_inet_ntop(r->connection->listening->family, &r->in_addr, | 429 le.ip += sizeof(uintptr_t); |
472 addr_text, INET_ADDRSTRLEN); | 430 |
473 if (addr_len == 0) { | 431 if (val_len) { |
474 return NGX_ERROR; | 432 len += 1 + key_len + ((val_len > 127) ? 4 : 1) + val_len; |
475 } | 433 } |
476 | 434 } |
477 #if (NGX_SUPPRESS_WARN) | 435 } |
478 clcf = NULL; | 436 |
479 var = NULL; | 437 if (flcf->upstream.pass_request_headers) { |
480 vindex = NULL; | 438 |
481 #endif | 439 part = &r->headers_in.headers.part; |
482 | 440 header = part->elts; |
483 | 441 |
484 if (r->upstream->method) { | 442 for (i = 0; /* void */; i++) { |
485 len = 1 + 1 + sizeof("REQUEST_METHOD") - 1 | 443 |
486 + ngx_http_fastcgi_methods[r->upstream->method - 1].len; | 444 if (i >= part->nelts) { |
487 | 445 if (part->next == NULL) { |
488 } else { | 446 break; |
489 len = 1 + ((r->method_name.len - 1 > 127) ? 4 : 1) | 447 } |
490 + sizeof("REQUEST_METHOD") - 1 | 448 |
491 + r->method_name.len - 1; | 449 part = part->next; |
492 } | 450 header = part->elts; |
493 | 451 i = 0; |
494 | 452 } |
495 index = (r->uri.data[r->uri.len - 1] == '/') ? flcf->index.len : 0; | 453 |
496 | 454 len += ((sizeof("HTTP_") - 1 + header[i].key.len > 127) ? 4 : 1) |
497 len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1) | 455 + ((header[i].value.len > 127) ? 4 : 1) |
498 + sizeof("PATH_TRANSLATED") - 1 + flcf->root.len + r->uri.len + index; | 456 + sizeof("HTTP_") - 1 + header[i].key.len + header[i].value.len; |
499 | 457 } |
500 if (r->args.len) { | |
501 len += 1 + ((r->args.len > 127) ? 4 : 1) + sizeof("QUERY_STRING") - 1 | |
502 + r->args.len; | |
503 } | |
504 | |
505 if (r->headers_in.content_length_n > 0) { | |
506 len += 1 + ((r->headers_in.content_length->value.len > 127) ? 4 : 1) | |
507 + sizeof("CONTENT_LENGTH") - 1 | |
508 + r->headers_in.content_length->value.len; | |
509 } | |
510 | |
511 | |
512 if (r->headers_in.content_type) { | |
513 len += 1 + ((r->headers_in.content_type->value.len > 127) ? 4 : 1) | |
514 + sizeof("CONTENT_TYPE") - 1 | |
515 + r->headers_in.content_type->value.len; | |
516 } | |
517 | |
518 | |
519 if (flcf->params & NGX_HTTP_FASTCGI_REDIRECT_STATUS) { | |
520 len += 1 + 1 + sizeof("REDIRECT_STATUS200") - 1; | |
521 } | |
522 | |
523 if (flcf->params & NGX_HTTP_FASTCGI_REQUEST_URI) { | |
524 len += 1 + ((r->unparsed_uri.len > 127) ? 4 : 1) | |
525 + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len; | |
526 } | |
527 | |
528 if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) { | |
529 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
530 len += 1 + ((clcf->root.len > 127) ? 4 : 1) | |
531 + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len; | |
532 } | |
533 | |
534 if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_FILENAME) { | |
535 len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1) | |
536 + sizeof("SCRIPT_FILENAME") - 1 | |
537 + flcf->root.len + r->uri.len + index; | |
538 } | |
539 | |
540 if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) { | |
541 len += 1 + ((r->uri.len + index > 127) ? 4 : 1) | |
542 + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ; | |
543 } | |
544 | |
545 if (flcf->params & NGX_HTTP_FASTCGI_REMOTE_ADDR) { | |
546 len += 1 + 1 + sizeof("REMOTE_ADDR") - 1 + r->connection->addr_text.len; | |
547 } | |
548 | |
549 port_len = 0; | |
550 | |
551 if (flcf->params & NGX_HTTP_FASTCGI_REMOTE_PORT) { | |
552 | |
553 /* AF_INET only */ | |
554 | |
555 if (r->connection->sockaddr->sa_family == AF_INET) { | |
556 sinp = (struct sockaddr_in *) r->connection->sockaddr; | |
557 | |
558 port = ntohs(sinp->sin_port); | |
559 | |
560 if (port > 0 && port < 65536) { | |
561 port_len = ngx_sprintf(port_text, "%ui", port) - port_text; | |
562 } | |
563 | |
564 len += 1 + 1 + sizeof("REMOTE_PORT") - 1 + port_len; | |
565 } | |
566 } | |
567 | |
568 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_NAME) { | |
569 len += 1 + 1 + sizeof("SERVER_NAME") - 1 + r->server_name.len; | |
570 } | |
571 | |
572 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_PORT) { | |
573 len += 1 + 1 + sizeof("SERVER_PORT") - 1 + r->port_text->len - 1; | |
574 } | |
575 | |
576 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_ADDR) { | |
577 len += 1 + 1 + sizeof("SERVER_ADDR") - 1 + addr_len; | |
578 } | |
579 | |
580 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_PROTOCOL | |
581 && r->http_protocol.len) | |
582 { | |
583 len += 1 + ((r->http_protocol.len > 127) ? 4 : 1) | |
584 + sizeof("SERVER_PROTOCOL") - 1 + r->http_protocol.len; | |
585 } | |
586 | |
587 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_SOFTWARE) { | |
588 len += 1 + 1 + sizeof("SERVER_SOFTWARE") - 1 + sizeof(NGINX_VER) - 1; | |
589 } | |
590 | |
591 if (flcf->params & NGX_HTTP_FASTCGI_GATEWAY_INTERFACE) { | |
592 len += 1 + 1 + sizeof("GATEWAY_INTERFACE") - 1 + sizeof("CGI/1.1") - 1; | |
593 } | |
594 | |
595 | |
596 if (flcf->vars) { | |
597 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
598 | |
599 var = cmcf->variables.elts; | |
600 vindex = flcf->vars->elts; | |
601 | |
602 for (i = 0; i < flcf->vars->nelts; i++) { | |
603 | |
604 value = ngx_http_get_indexed_variable(r, vindex[i]); | |
605 if (value == NULL) { | |
606 continue; | |
607 } | |
608 | |
609 if (value->text.len) { | |
610 len += 1 + 1 + var[vindex[i]].name.len + value->text.len; | |
611 } | |
612 } | |
613 } | |
614 | |
615 | |
616 part = &r->headers_in.headers.part; | |
617 header = part->elts; | |
618 | |
619 for (i = 0; /* void */; i++) { | |
620 | |
621 if (i >= part->nelts) { | |
622 if (part->next == NULL) { | |
623 break; | |
624 } | |
625 | |
626 part = part->next; | |
627 header = part->elts; | |
628 i = 0; | |
629 } | |
630 | |
631 len += ((header[i].key.len > 127) ? 4 : 1) | |
632 + ((header[i].value.len > 127) ? 4 : 1) | |
633 + 5 + header[i].key.len + header[i].value.len; | |
634 } | 458 } |
635 | 459 |
636 | 460 |
637 if (len > 65535) { | 461 if (len > 65535) { |
638 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 462 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
665 return NGX_ERROR; | 489 return NGX_ERROR; |
666 } | 490 } |
667 | 491 |
668 cl->buf = b; | 492 cl->buf = b; |
669 | 493 |
670 h = (ngx_http_fastcgi_header_t *) b->pos; | 494 ngx_memcpy(b->pos, &ngx_http_fastcgi_request_start, |
671 | 495 sizeof(ngx_http_fastcgi_request_start_t)); |
672 h->version = 1; | |
673 h->type = NGX_HTTP_FASTCGI_BEGIN_REQUEST; | |
674 h->request_id_hi = 0; | |
675 h->request_id_lo = 1; | |
676 h->content_length_hi = 0; | |
677 h->content_length_lo = sizeof(ngx_http_fastcgi_begin_request_t); | |
678 h->padding_length = 0; | |
679 h->reserved = 0; | |
680 | |
681 br = (ngx_http_fastcgi_begin_request_t *) | |
682 (b->pos + sizeof(ngx_http_fastcgi_header_t)); | |
683 br->role_hi = 0; | |
684 br->role_lo = NGX_HTTP_FASTCGI_RESPONDER; | |
685 br->flags = 0; /* NGX_HTTP_FASTCGI_KEEP_CONN */ | |
686 br->reserved[0] = 0; | |
687 br->reserved[1] = 0; | |
688 br->reserved[2] = 0; | |
689 br->reserved[3] = 0; | |
690 br->reserved[4] = 0; | |
691 | 496 |
692 h = (ngx_http_fastcgi_header_t *) | 497 h = (ngx_http_fastcgi_header_t *) |
693 (b->pos + sizeof(ngx_http_fastcgi_header_t) | 498 (b->pos + sizeof(ngx_http_fastcgi_header_t) |
694 + sizeof(ngx_http_fastcgi_begin_request_t)); | 499 + sizeof(ngx_http_fastcgi_begin_request_t)); |
695 | 500 |
696 h->version = 1; | |
697 h->type = NGX_HTTP_FASTCGI_PARAMS; | |
698 h->request_id_hi = 0; | |
699 h->request_id_lo = 1; | |
700 h->content_length_hi = (u_char) ((len >> 8) & 0xff); | 501 h->content_length_hi = (u_char) ((len >> 8) & 0xff); |
701 h->content_length_lo = (u_char) (len & 0xff); | 502 h->content_length_lo = (u_char) (len & 0xff); |
702 h->padding_length = (u_char) padding; | 503 h->padding_length = (u_char) padding; |
703 h->reserved = 0; | 504 h->reserved = 0; |
704 | 505 |
705 b->last = b->pos + sizeof(ngx_http_fastcgi_header_t) | 506 b->last = b->pos + sizeof(ngx_http_fastcgi_header_t) |
706 + sizeof(ngx_http_fastcgi_begin_request_t) | 507 + sizeof(ngx_http_fastcgi_begin_request_t) |
707 + sizeof(ngx_http_fastcgi_header_t); | 508 + sizeof(ngx_http_fastcgi_header_t); |
708 | 509 |
709 | 510 |
710 *b->last++ = sizeof("PATH_TRANSLATED") - 1; | 511 if (flcf->params_len) { |
711 | 512 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
712 len = flcf->root.len + r->uri.len + index; | 513 |
713 if (len > 127) { | 514 e.ip = flcf->params->elts; |
714 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | 515 e.pos = b->last; |
715 *b->last++ = (u_char) ((len >> 16) & 0xff); | 516 e.request = r; |
716 *b->last++ = (u_char) ((len >> 8) & 0xff); | 517 |
717 *b->last++ = (u_char) (len & 0xff); | 518 le.ip = flcf->params_len->elts; |
718 | 519 |
719 } else { | 520 while (*(uintptr_t *) le.ip) { |
720 *b->last++ = (u_char) len; | 521 |
721 } | 522 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
722 | 523 key_len = (u_char) lcode(&le); |
723 b->last = ngx_cpymem(b->last, "PATH_TRANSLATED", | 524 |
724 sizeof("PATH_TRANSLATED") - 1); | 525 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { |
725 b->last = ngx_cpymem(b->last, flcf->root.data, flcf->root.len); | 526 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
726 b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len); | 527 } |
727 | 528 le.ip += sizeof(uintptr_t); |
728 if (index) { | 529 |
729 b->last = ngx_cpymem(b->last, flcf->index.data, index); | 530 if (val_len) { |
730 } | 531 *e.pos++ = (u_char) key_len; |
731 | 532 |
732 | 533 if (val_len > 127) { |
733 *b->last++ = sizeof("REQUEST_METHOD") - 1; | 534 *e.pos++ = (u_char) (((val_len >> 24) & 0x7f) | 0x80); |
734 | 535 *e.pos++ = (u_char) ((val_len >> 16) & 0xff); |
735 if (r->upstream->method) { | 536 *e.pos++ = (u_char) ((val_len >> 8) & 0xff); |
736 *b->last++ = (u_char) | 537 *e.pos++ = (u_char) (val_len & 0xff); |
737 ngx_http_fastcgi_methods[r->upstream->method - 1].len; | 538 |
738 | 539 } else { |
739 b->last = ngx_cpymem(b->last, "REQUEST_METHOD", | 540 *e.pos++ = (u_char) val_len; |
740 sizeof("REQUEST_METHOD") - 1); | 541 } |
741 | 542 } |
742 b->last = ngx_cpymem(b->last, | 543 |
743 ngx_http_fastcgi_methods[r->upstream->method - 1].data, | 544 e.skip = val_len ? 0 : 1; |
744 ngx_http_fastcgi_methods[r->upstream->method - 1].len); | 545 |
745 | 546 while (*(uintptr_t *) e.ip) { |
746 } else { | 547 code = *(ngx_http_script_code_pt *) e.ip; |
747 len = r->method_name.len - 1; | 548 code((ngx_http_script_engine_t *) &e); |
748 if (len > 127) { | 549 } |
749 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | 550 e.ip += sizeof(uintptr_t); |
750 *b->last++ = (u_char) ((len >> 16) & 0xff); | 551 } |
751 *b->last++ = (u_char) ((len >> 8) & 0xff); | 552 |
752 *b->last++ = (u_char) (len & 0xff); | 553 b->last = e.pos; |
753 | 554 } |
754 } else { | 555 |
755 *b->last++ = (u_char) len; | 556 |
756 } | 557 if (flcf->upstream.pass_request_headers) { |
757 | 558 |
758 b->last = ngx_cpymem(b->last, "REQUEST_METHOD", | 559 part = &r->headers_in.headers.part; |
759 sizeof("REQUEST_METHOD") - 1); | 560 header = part->elts; |
760 b->last = ngx_cpymem(b->last, r->method_name.data, len); | 561 |
761 } | 562 for (i = 0; /* void */; i++) { |
762 | 563 |
763 | 564 if (i >= part->nelts) { |
764 if (r->args.len) { | 565 if (part->next == NULL) { |
765 *b->last++ = sizeof("QUERY_STRING") - 1; | 566 break; |
766 | 567 } |
767 len = r->args.len; | 568 |
768 if (len > 127) { | 569 part = part->next; |
769 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | 570 header = part->elts; |
770 *b->last++ = (u_char) ((len >> 16) & 0xff); | 571 i = 0; |
771 *b->last++ = (u_char) ((len >> 8) & 0xff); | 572 } |
772 *b->last++ = (u_char) (len & 0xff); | 573 |
773 | 574 len = sizeof("HTTP_") - 1 + header[i].key.len; |
774 } else { | 575 if (len > 127) { |
775 *b->last++ = (u_char) len; | 576 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); |
776 } | 577 *b->last++ = (u_char) ((len >> 16) & 0xff); |
777 | 578 *b->last++ = (u_char) ((len >> 8) & 0xff); |
778 b->last = ngx_cpymem(b->last, "QUERY_STRING", | 579 *b->last++ = (u_char) (len & 0xff); |
779 sizeof("QUERY_STRING") - 1); | 580 |
780 b->last = ngx_cpymem(b->last, r->args.data, len); | 581 } else { |
781 } | 582 *b->last++ = (u_char) len; |
782 | 583 } |
783 | 584 |
784 if (r->headers_in.content_length_n > 0) { | 585 len = header[i].value.len; |
785 *b->last++ = sizeof("CONTENT_LENGTH") - 1; | 586 if (len > 127) { |
786 | 587 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); |
787 len = r->headers_in.content_length->value.len; | 588 *b->last++ = (u_char) ((len >> 16) & 0xff); |
788 if (len > 127) { | 589 *b->last++ = (u_char) ((len >> 8) & 0xff); |
789 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | 590 *b->last++ = (u_char) (len & 0xff); |
790 *b->last++ = (u_char) ((len >> 16) & 0xff); | 591 |
791 *b->last++ = (u_char) ((len >> 8) & 0xff); | 592 } else { |
792 *b->last++ = (u_char) (len & 0xff); | 593 *b->last++ = (u_char) len; |
793 | 594 } |
794 } else { | 595 |
795 *b->last++ = (u_char) len; | 596 b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1); |
796 } | 597 |
797 | 598 for (n = 0; n < header[i].key.len; n++) { |
798 b->last = ngx_cpymem(b->last, "CONTENT_LENGTH", | 599 ch = header[i].key.data[n]; |
799 sizeof("CONTENT_LENGTH") - 1); | 600 |
800 b->last = ngx_cpymem(b->last, r->headers_in.content_length->value.data, | 601 if (ch >= 'a' && ch <= 'z') { |
801 len); | 602 ch &= ~0x20; |
802 } | 603 |
803 | 604 } else if (ch == '-') { |
804 | 605 ch = '_'; |
805 if (r->headers_in.content_type) { | 606 } |
806 *b->last++ = sizeof("CONTENT_TYPE") - 1; | 607 |
807 | 608 *b->last++ = ch; |
808 len = r->headers_in.content_type->value.len; | 609 } |
809 if (len > 127) { | 610 |
810 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | 611 b->last = ngx_cpymem(b->last, header[i].value.data, |
811 *b->last++ = (u_char) ((len >> 16) & 0xff); | 612 header[i].value.len); |
812 *b->last++ = (u_char) ((len >> 8) & 0xff); | 613 } |
813 *b->last++ = (u_char) (len & 0xff); | |
814 | |
815 } else { | |
816 *b->last++ = (u_char) len; | |
817 } | |
818 | |
819 b->last = ngx_cpymem(b->last, "CONTENT_TYPE", | |
820 sizeof("CONTENT_TYPE") - 1); | |
821 b->last = ngx_cpymem(b->last, r->headers_in.content_type->value.data, | |
822 len); | |
823 } | |
824 | |
825 | |
826 if (flcf->params & NGX_HTTP_FASTCGI_REDIRECT_STATUS) { | |
827 *b->last++ = sizeof("REDIRECT_STATUS") - 1; | |
828 *b->last++ = sizeof("200") - 1; | |
829 b->last = ngx_cpymem(b->last, "REDIRECT_STATUS200", | |
830 sizeof("REDIRECT_STATUS200") - 1); | |
831 } | |
832 | |
833 | |
834 if (flcf->params & NGX_HTTP_FASTCGI_REQUEST_URI) { | |
835 *b->last++ = sizeof("REQUEST_URI") - 1; | |
836 | |
837 len = r->unparsed_uri.len; | |
838 if (len > 127) { | |
839 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
840 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
841 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
842 *b->last++ = (u_char) (len & 0xff); | |
843 | |
844 } else { | |
845 *b->last++ = (u_char) len; | |
846 } | |
847 | |
848 b->last = ngx_cpymem(b->last, "REQUEST_URI", sizeof("REQUEST_URI") - 1); | |
849 b->last = ngx_cpymem(b->last, r->unparsed_uri.data, len); | |
850 } | |
851 | |
852 | |
853 if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) { | |
854 *b->last++ = sizeof("DOCUMENT_ROOT") - 1; | |
855 | |
856 len = clcf->root.len; | |
857 if (len > 127) { | |
858 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
859 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
860 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
861 *b->last++ = (u_char) (len & 0xff); | |
862 | |
863 } else { | |
864 *b->last++ = (u_char) len; | |
865 } | |
866 | |
867 b->last = ngx_cpymem(b->last, "DOCUMENT_ROOT", | |
868 sizeof("DOCUMENT_ROOT") - 1); | |
869 b->last = ngx_cpymem(b->last, clcf->root.data, len); | |
870 } | |
871 | |
872 | |
873 if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_FILENAME) { | |
874 *b->last++ = sizeof("SCRIPT_FILENAME") - 1; | |
875 | |
876 len = flcf->root.len + r->uri.len + index; | |
877 if (len > 127) { | |
878 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
879 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
880 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
881 *b->last++ = (u_char) (len & 0xff); | |
882 | |
883 } else { | |
884 *b->last++ = (u_char) len; | |
885 } | |
886 | |
887 b->last = ngx_cpymem(b->last, "SCRIPT_FILENAME", | |
888 sizeof("SCRIPT_FILENAME") - 1); | |
889 b->last = ngx_cpymem(b->last, flcf->root.data, flcf->root.len); | |
890 b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len); | |
891 | |
892 if (index) { | |
893 b->last = ngx_cpymem(b->last, flcf->index.data, index); | |
894 } | |
895 } | |
896 | |
897 | |
898 if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) { | |
899 *b->last++ = sizeof("SCRIPT_NAME") - 1; | |
900 | |
901 len = r->uri.len + index; | |
902 if (len > 127) { | |
903 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
904 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
905 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
906 *b->last++ = (u_char) (len & 0xff); | |
907 | |
908 } else { | |
909 *b->last++ = (u_char) len; | |
910 } | |
911 | |
912 b->last = ngx_cpymem(b->last, "SCRIPT_NAME", sizeof("SCRIPT_NAME") - 1); | |
913 b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len); | |
914 | |
915 if (index) { | |
916 b->last = ngx_cpymem(b->last, flcf->index.data, index); | |
917 } | |
918 } | |
919 | |
920 | |
921 if (flcf->params & NGX_HTTP_FASTCGI_REMOTE_ADDR) { | |
922 *b->last++ = sizeof("REMOTE_ADDR") - 1; | |
923 *b->last++ = (u_char) (r->connection->addr_text.len); | |
924 b->last = ngx_cpymem(b->last, "REMOTE_ADDR", sizeof("REMOTE_ADDR") - 1); | |
925 b->last = ngx_cpymem(b->last, r->connection->addr_text.data, | |
926 r->connection->addr_text.len); | |
927 } | |
928 | |
929 | |
930 if (port_len) { | |
931 *b->last++ = sizeof("REMOTE_PORT") - 1; | |
932 *b->last++ = (u_char) port_len; | |
933 b->last = ngx_cpymem(b->last, "REMOTE_PORT", sizeof("REMOTE_PORT") - 1); | |
934 b->last = ngx_cpymem(b->last, port_text, port_len); | |
935 } | |
936 | |
937 | |
938 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_NAME) { | |
939 *b->last++ = sizeof("SERVER_NAME") - 1; | |
940 *b->last++ = (u_char) r->server_name.len; | |
941 b->last = ngx_cpymem(b->last, "SERVER_NAME", sizeof("SERVER_NAME") - 1); | |
942 b->last = ngx_cpymem(b->last, r->server_name.data, r->server_name.len); | |
943 } | |
944 | |
945 | |
946 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_PORT) { | |
947 *b->last++ = sizeof("SERVER_PORT") - 1; | |
948 *b->last++ = (u_char) (r->port_text->len - 1); | |
949 b->last = ngx_cpymem(b->last, "SERVER_PORT", sizeof("SERVER_PORT") - 1); | |
950 b->last = ngx_cpymem(b->last, r->port_text->data + 1, | |
951 r->port_text->len - 1); | |
952 } | |
953 | |
954 | |
955 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_ADDR) { | |
956 *b->last++ = sizeof("SERVER_ADDR") - 1; | |
957 *b->last++ = (u_char) addr_len; | |
958 b->last = ngx_cpymem(b->last, "SERVER_ADDR", sizeof("SERVER_ADDR") - 1); | |
959 b->last = ngx_cpymem(b->last, addr_text, addr_len); | |
960 } | |
961 | |
962 | |
963 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_PROTOCOL | |
964 && r->http_protocol.len) | |
965 { | |
966 *b->last++ = sizeof("SERVER_PROTOCOL") - 1; | |
967 | |
968 len = r->http_protocol.len; | |
969 if (len > 127) { | |
970 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
971 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
972 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
973 *b->last++ = (u_char) (len & 0xff); | |
974 | |
975 } else { | |
976 *b->last++ = (u_char) len; | |
977 } | |
978 | |
979 b->last = ngx_cpymem(b->last, "SERVER_PROTOCOL", | |
980 sizeof("SERVER_PROTOCOL") - 1); | |
981 b->last = ngx_cpymem(b->last, r->http_protocol.data, len); | |
982 } | |
983 | |
984 | |
985 if (flcf->params & NGX_HTTP_FASTCGI_SERVER_SOFTWARE) { | |
986 *b->last++ = sizeof("SERVER_SOFTWARE") - 1; | |
987 *b->last++ = (u_char) (sizeof(NGINX_VER) - 1); | |
988 b->last = ngx_cpymem(b->last, "SERVER_SOFTWARE", | |
989 sizeof("SERVER_SOFTWARE") - 1); | |
990 b->last = ngx_cpymem(b->last, NGINX_VER, sizeof(NGINX_VER) - 1); | |
991 } | |
992 | |
993 | |
994 if (flcf->params & NGX_HTTP_FASTCGI_GATEWAY_INTERFACE) { | |
995 *b->last++ = sizeof("GATEWAY_INTERFACE") - 1; | |
996 *b->last++ = (u_char) (sizeof("CGI/1.1") - 1); | |
997 b->last = ngx_cpymem(b->last, "GATEWAY_INTERFACE", | |
998 sizeof("GATEWAY_INTERFACE") - 1); | |
999 b->last = ngx_cpymem(b->last, "CGI/1.1", sizeof("CGI/1.1") - 1); | |
1000 } | |
1001 | |
1002 | |
1003 if (flcf->vars) { | |
1004 for (i = 0; i < flcf->vars->nelts; i++) { | |
1005 | |
1006 value = ngx_http_get_indexed_variable(r, vindex[i]); | |
1007 if (value == NULL) { | |
1008 continue; | |
1009 } | |
1010 | |
1011 if (value->text.len == 0) { | |
1012 continue; | |
1013 } | |
1014 | |
1015 *b->last++ = (u_char) var[vindex[i]].name.len; | |
1016 *b->last++ = (u_char) value->text.len; | |
1017 | |
1018 b->last = ngx_cpymem(b->last, var[vindex[i]].name.data, | |
1019 var[vindex[i]].name.len); | |
1020 | |
1021 b->last = ngx_cpymem(b->last, value->text.data, value->text.len); | |
1022 } | |
1023 } | |
1024 | |
1025 | |
1026 part = &r->headers_in.headers.part; | |
1027 header = part->elts; | |
1028 | |
1029 for (i = 0; /* void */; i++) { | |
1030 | |
1031 if (i >= part->nelts) { | |
1032 if (part->next == NULL) { | |
1033 break; | |
1034 } | |
1035 | |
1036 part = part->next; | |
1037 header = part->elts; | |
1038 i = 0; | |
1039 } | |
1040 | |
1041 len = 5 + header[i].key.len; | |
1042 if (len > 127) { | |
1043 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
1044 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
1045 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
1046 *b->last++ = (u_char) (len & 0xff); | |
1047 | |
1048 } else { | |
1049 *b->last++ = (u_char) len; | |
1050 } | |
1051 | |
1052 len = header[i].value.len; | |
1053 if (len > 127) { | |
1054 *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80); | |
1055 *b->last++ = (u_char) ((len >> 16) & 0xff); | |
1056 *b->last++ = (u_char) ((len >> 8) & 0xff); | |
1057 *b->last++ = (u_char) (len & 0xff); | |
1058 | |
1059 } else { | |
1060 *b->last++ = (u_char) len; | |
1061 } | |
1062 | |
1063 b->last = ngx_cpymem(b->last, "HTTP_", sizeof("HTTP_") - 1); | |
1064 | |
1065 for (n = 0; n < header[i].key.len; n++) { | |
1066 ch = header[i].key.data[n]; | |
1067 | |
1068 if (ch >= 'a' && ch <= 'z') { | |
1069 ch &= ~0x20; | |
1070 | |
1071 } else if (ch == '-') { | |
1072 ch = '_'; | |
1073 } | |
1074 | |
1075 *b->last++ = ch; | |
1076 } | |
1077 | |
1078 b->last = ngx_cpymem(b->last, header[i].value.data, | |
1079 header[i].value.len); | |
1080 } | 614 } |
1081 | 615 |
1082 | 616 |
1083 if (padding) { | 617 if (padding) { |
1084 ngx_memzero(b->last, padding); | 618 ngx_memzero(b->last, padding); |
1099 h->reserved = 0; | 633 h->reserved = 0; |
1100 | 634 |
1101 h = (ngx_http_fastcgi_header_t *) b->last; | 635 h = (ngx_http_fastcgi_header_t *) b->last; |
1102 b->last += sizeof(ngx_http_fastcgi_header_t); | 636 b->last += sizeof(ngx_http_fastcgi_header_t); |
1103 | 637 |
1104 body = r->request_body->bufs; | 638 if (flcf->upstream.pass_request_body) { |
1105 r->request_body->bufs = cl; | 639 body = r->upstream->request_bufs; |
640 r->upstream->request_bufs = cl; | |
1106 | 641 |
1107 #if (NGX_SUPPRESS_WARN) | 642 #if (NGX_SUPPRESS_WARN) |
1108 file_pos = 0; | 643 file_pos = 0; |
1109 pos = NULL; | 644 pos = NULL; |
1110 #endif | 645 #endif |
1111 | 646 |
1112 while (body) { | 647 while (body) { |
1113 | |
1114 if (body->buf->in_file) { | |
1115 file_pos = body->buf->file_pos; | |
1116 | |
1117 } else { | |
1118 pos = body->buf->pos; | |
1119 } | |
1120 | |
1121 next = 0; | |
1122 | |
1123 do { | |
1124 b = ngx_alloc_buf(r->pool); | |
1125 if (b == NULL) { | |
1126 return NGX_ERROR; | |
1127 } | |
1128 | |
1129 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); | |
1130 | 648 |
1131 if (body->buf->in_file) { | 649 if (body->buf->in_file) { |
1132 b->file_pos = file_pos; | 650 file_pos = body->buf->file_pos; |
1133 file_pos += 32 * 1024; | |
1134 | |
1135 if (file_pos > body->buf->file_last) { | |
1136 file_pos = body->buf->file_last; | |
1137 next = 1; | |
1138 } | |
1139 | |
1140 b->file_last = file_pos; | |
1141 len = (ngx_uint_t) (file_pos - b->file_pos); | |
1142 | 651 |
1143 } else { | 652 } else { |
1144 b->pos = pos; | 653 pos = body->buf->pos; |
1145 pos += 32 * 1024; | 654 } |
1146 | 655 |
1147 if (pos > body->buf->last) { | 656 next = 0; |
1148 pos = body->buf->last; | 657 |
1149 next = 1; | 658 do { |
1150 } | 659 b = ngx_alloc_buf(r->pool); |
1151 | 660 if (b == NULL) { |
1152 b->last = pos; | 661 return NGX_ERROR; |
1153 len = (ngx_uint_t) (pos - b->pos); | 662 } |
1154 } | 663 |
1155 | 664 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); |
1156 padding = 8 - len % 8; | 665 |
1157 padding = (padding == 8) ? 0 : padding; | 666 if (body->buf->in_file) { |
1158 | 667 b->file_pos = file_pos; |
1159 h->version = 1; | 668 file_pos += 32 * 1024; |
1160 h->type = NGX_HTTP_FASTCGI_STDIN; | 669 |
1161 h->request_id_hi = 0; | 670 if (file_pos > body->buf->file_last) { |
1162 h->request_id_lo = 1; | 671 file_pos = body->buf->file_last; |
1163 h->content_length_hi = (u_char) ((len >> 8) & 0xff); | 672 next = 1; |
1164 h->content_length_lo = (u_char) (len & 0xff); | 673 } |
1165 h->padding_length = (u_char) padding; | 674 |
1166 h->reserved = 0; | 675 b->file_last = file_pos; |
1167 | 676 len = (ngx_uint_t) (file_pos - b->file_pos); |
1168 cl->next = ngx_alloc_chain_link(r->pool); | 677 |
1169 if (cl->next == NULL) { | 678 } else { |
1170 return NGX_ERROR; | 679 b->pos = pos; |
1171 } | 680 pos += 32 * 1024; |
1172 | 681 |
1173 cl = cl->next; | 682 if (pos > body->buf->last) { |
1174 cl->buf = b; | 683 pos = body->buf->last; |
1175 | 684 next = 1; |
1176 b = ngx_create_temp_buf(r->pool, sizeof(ngx_http_fastcgi_header_t) | 685 } |
1177 + padding); | 686 |
1178 if (b == NULL) { | 687 b->last = pos; |
1179 return NGX_ERROR; | 688 len = (ngx_uint_t) (pos - b->pos); |
1180 } | 689 } |
1181 | 690 |
1182 if (padding) { | 691 padding = 8 - len % 8; |
1183 ngx_memzero(b->last, padding); | 692 padding = (padding == 8) ? 0 : padding; |
1184 b->last += padding; | 693 |
1185 } | 694 h->version = 1; |
1186 | 695 h->type = NGX_HTTP_FASTCGI_STDIN; |
1187 h = (ngx_http_fastcgi_header_t *) b->last; | 696 h->request_id_hi = 0; |
1188 b->last += sizeof(ngx_http_fastcgi_header_t); | 697 h->request_id_lo = 1; |
1189 | 698 h->content_length_hi = (u_char) ((len >> 8) & 0xff); |
1190 cl->next = ngx_alloc_chain_link(r->pool); | 699 h->content_length_lo = (u_char) (len & 0xff); |
1191 if (cl->next == NULL) { | 700 h->padding_length = (u_char) padding; |
1192 return NGX_ERROR; | 701 h->reserved = 0; |
1193 } | 702 |
1194 | 703 cl->next = ngx_alloc_chain_link(r->pool); |
1195 cl = cl->next; | 704 if (cl->next == NULL) { |
1196 cl->buf = b; | 705 return NGX_ERROR; |
1197 | 706 } |
1198 } while (!next); | 707 |
1199 | 708 cl = cl->next; |
1200 body = body->next; | 709 cl->buf = b; |
710 | |
711 b = ngx_create_temp_buf(r->pool, | |
712 sizeof(ngx_http_fastcgi_header_t) | |
713 + padding); | |
714 if (b == NULL) { | |
715 return NGX_ERROR; | |
716 } | |
717 | |
718 if (padding) { | |
719 ngx_memzero(b->last, padding); | |
720 b->last += padding; | |
721 } | |
722 | |
723 h = (ngx_http_fastcgi_header_t *) b->last; | |
724 b->last += sizeof(ngx_http_fastcgi_header_t); | |
725 | |
726 cl->next = ngx_alloc_chain_link(r->pool); | |
727 if (cl->next == NULL) { | |
728 return NGX_ERROR; | |
729 } | |
730 | |
731 cl = cl->next; | |
732 cl->buf = b; | |
733 | |
734 } while (!next); | |
735 | |
736 body = body->next; | |
737 } | |
738 | |
739 } else { | |
740 r->upstream->request_bufs = cl; | |
1201 } | 741 } |
1202 | 742 |
1203 h->version = 1; | 743 h->version = 1; |
1204 h->type = NGX_HTTP_FASTCGI_STDIN; | 744 h->type = NGX_HTTP_FASTCGI_STDIN; |
1205 h->request_id_hi = 0; | 745 h->request_id_hi = 0; |
1227 } | 767 } |
1228 | 768 |
1229 f->state = ngx_http_fastcgi_st_version; | 769 f->state = ngx_http_fastcgi_st_version; |
1230 f->header = 0; | 770 f->header = 0; |
1231 | 771 |
1232 ngx_memzero(&f->upstream->headers_in, | |
1233 sizeof(ngx_http_fastcgi_headers_in_t)); | |
1234 | |
1235 if (f->upstream->headers_in.headers.part.elts) { | |
1236 if (ngx_list_init(&f->upstream->headers_in.headers, r->pool, 8, | |
1237 sizeof(ngx_table_elt_t)) == NGX_ERROR) | |
1238 { | |
1239 return NGX_ERROR; | |
1240 } | |
1241 } | |
1242 | |
1243 return NGX_OK; | 772 return NGX_OK; |
1244 } | 773 } |
1245 | 774 |
1246 | 775 |
1247 static ngx_int_t | 776 static ngx_int_t |
1248 ngx_http_fastcgi_process_header(ngx_http_request_t *r) | 777 ngx_http_fastcgi_process_header(ngx_http_request_t *r) |
1249 { | 778 { |
1250 u_char *start, *last; | 779 u_char *start, *last; |
1251 ngx_str_t *status_line, line; | 780 ngx_str_t *status_line, line; |
1252 ngx_int_t rc, status; | 781 ngx_int_t rc, status; |
1253 ngx_uint_t i; | 782 ngx_uint_t key; |
1254 ngx_table_elt_t *h; | 783 ngx_table_elt_t *h; |
1255 ngx_http_upstream_t *u; | 784 ngx_http_upstream_t *u; |
1256 ngx_http_fastcgi_ctx_t *f; | 785 ngx_http_fastcgi_ctx_t *f; |
786 ngx_http_upstream_header_t *hh; | |
787 ngx_http_upstream_main_conf_t *umcf; | |
1257 | 788 |
1258 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); | 789 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); |
790 | |
791 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
792 hh = (ngx_http_upstream_header_t *) umcf->headers_in_hash.buckets; | |
1259 | 793 |
1260 if (f == NULL) { | 794 if (f == NULL) { |
1261 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t)); | 795 f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t)); |
1262 if (f == NULL) { | 796 if (f == NULL) { |
1263 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 797 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1264 } | 798 } |
1265 | 799 |
1266 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module); | 800 ngx_http_set_ctx(r, f, ngx_http_fastcgi_module); |
1267 | |
1268 f->upstream = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_upstream_t)); | |
1269 if (f->upstream == NULL) { | |
1270 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1271 } | |
1272 | |
1273 if (ngx_list_init(&f->upstream->headers_in.headers, r->pool, 8, | |
1274 sizeof(ngx_table_elt_t)) == NGX_ERROR) | |
1275 { | |
1276 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1277 } | |
1278 } | 801 } |
1279 | 802 |
1280 u = r->upstream; | 803 u = r->upstream; |
1281 | 804 |
1282 for ( ;; ) { | 805 for ( ;; ) { |
1422 | 945 |
1423 if (rc == NGX_OK) { | 946 if (rc == NGX_OK) { |
1424 | 947 |
1425 /* a header line has been parsed successfully */ | 948 /* a header line has been parsed successfully */ |
1426 | 949 |
1427 h = ngx_list_push(&f->upstream->headers_in.headers); | 950 h = ngx_list_push(&u->headers_in.headers); |
1428 if (h == NULL) { | 951 if (h == NULL) { |
1429 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 952 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1430 } | 953 } |
954 | |
955 h->hash = r->header_hash; | |
1431 | 956 |
1432 h->key.len = r->header_name_end - r->header_name_start; | 957 h->key.len = r->header_name_end - r->header_name_start; |
1433 h->value.len = r->header_end - r->header_start; | 958 h->value.len = r->header_end - r->header_start; |
1434 | 959 |
1435 h->key.data = ngx_palloc(r->pool, | 960 h->key.data = ngx_palloc(r->pool, |
1441 h->value.data = h->key.data + h->key.len + 1; | 966 h->value.data = h->key.data + h->key.len + 1; |
1442 | 967 |
1443 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1); | 968 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1); |
1444 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1); | 969 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1); |
1445 | 970 |
1446 for (i = 0; ngx_http_fastcgi_headers_in[i].name.len != 0; i++) { | 971 key = h->hash % umcf->headers_in_hash.hash_size; |
1447 if (ngx_http_fastcgi_headers_in[i].name.len != h->key.len) { | 972 |
1448 continue; | 973 if (hh[key].name.len == h->key.len |
1449 } | 974 && ngx_strcasecmp(hh[key].name.data, h->key.data) == 0) |
1450 | 975 { |
1451 if (ngx_strcasecmp(ngx_http_fastcgi_headers_in[i].name.data, | 976 if (hh[key].handler(r, h, hh[key].offset) != NGX_OK) { |
1452 h->key.data) == 0) | 977 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1453 { | |
1454 *((ngx_table_elt_t **) | |
1455 ((char *) &f->upstream->headers_in | |
1456 + ngx_http_fastcgi_headers_in[i].offset)) = h; | |
1457 break; | |
1458 } | 978 } |
1459 } | 979 } |
1460 | 980 |
1461 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 981 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1462 "http fastcgi header: \"%V: %V\"", | 982 "http fastcgi header: \"%V: %V\"", |
1470 /* a whole header has been parsed successfully */ | 990 /* a whole header has been parsed successfully */ |
1471 | 991 |
1472 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 992 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1473 "http fastcgi header done"); | 993 "http fastcgi header done"); |
1474 | 994 |
1475 if (f->upstream->headers_in.status) { | 995 if (u->headers_in.status) { |
1476 status_line = &f->upstream->headers_in.status->value; | 996 status_line = &u->headers_in.status->value; |
1477 | 997 |
1478 status = ngx_atoi(status_line->data, 3); | 998 status = ngx_atoi(status_line->data, 3); |
1479 | 999 |
1480 if (status == NGX_ERROR) { | 1000 if (status == NGX_ERROR) { |
1481 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 1001 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1535 } | 1055 } |
1536 } | 1056 } |
1537 | 1057 |
1538 return NGX_OK; | 1058 return NGX_OK; |
1539 } | 1059 } |
1540 } | |
1541 | |
1542 | |
1543 static ngx_int_t | |
1544 ngx_http_fastcgi_send_header(ngx_http_request_t *r) | |
1545 { | |
1546 ngx_uint_t i; | |
1547 ngx_list_part_t *part; | |
1548 ngx_table_elt_t *ho, *h; | |
1549 ngx_http_fastcgi_ctx_t *f; | |
1550 ngx_http_fastcgi_headers_in_t *headers_in; | |
1551 | |
1552 f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module); | |
1553 | |
1554 headers_in = &f->upstream->headers_in; | |
1555 part = &headers_in->headers.part; | |
1556 h = part->elts; | |
1557 | |
1558 for (i = 0; /* void */; i++) { | |
1559 | |
1560 if (i >= part->nelts) { | |
1561 if (part->next == NULL) { | |
1562 break; | |
1563 } | |
1564 | |
1565 part = part->next; | |
1566 h = part->elts; | |
1567 i = 0; | |
1568 } | |
1569 | |
1570 /* ignore some headers */ | |
1571 | |
1572 if (&h[i] == headers_in->status) { | |
1573 continue; | |
1574 } | |
1575 | |
1576 | |
1577 if (&h[i] == headers_in->x_powered_by | |
1578 && !r->upstream->conf->x_powered_by) | |
1579 { | |
1580 continue; | |
1581 } | |
1582 | |
1583 | |
1584 /* "Content-Type" is handled specially */ | |
1585 | |
1586 if (&h[i] == headers_in->content_type) { | |
1587 r->headers_out.content_type = &h[i]; | |
1588 r->headers_out.content_type->key.len = 0; | |
1589 continue; | |
1590 } | |
1591 | |
1592 | |
1593 /* copy some header pointers and set up r->headers_out */ | |
1594 | |
1595 ho = ngx_list_push(&r->headers_out.headers); | |
1596 if (ho == NULL) { | |
1597 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1598 } | |
1599 | |
1600 *ho = h[i]; | |
1601 | |
1602 #if (NGX_HTTP_GZIP) | |
1603 if (&h[i] == headers_in->content_encoding) { | |
1604 r->headers_out.content_encoding = ho; | |
1605 continue; | |
1606 } | |
1607 #endif | |
1608 | |
1609 if (&h[i] == headers_in->content_length) { | |
1610 r->headers_out.content_length = ho; | |
1611 r->headers_out.content_length_n = ngx_atoi(ho->value.data, | |
1612 ho->value.len); | |
1613 continue; | |
1614 } | |
1615 } | |
1616 | |
1617 return ngx_http_send_header(r); | |
1618 } | 1060 } |
1619 | 1061 |
1620 | 1062 |
1621 static ngx_int_t | 1063 static ngx_int_t |
1622 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) | 1064 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) |
1935 case ngx_http_fastcgi_st_padding: | 1377 case ngx_http_fastcgi_st_padding: |
1936 break; | 1378 break; |
1937 } | 1379 } |
1938 } | 1380 } |
1939 | 1381 |
1940 f->pos = p + 1; | |
1941 f->state = state; | 1382 f->state = state; |
1942 | 1383 |
1943 return NGX_AGAIN; | 1384 return NGX_AGAIN; |
1944 } | 1385 } |
1945 | 1386 |
1962 | 1403 |
1963 return; | 1404 return; |
1964 } | 1405 } |
1965 | 1406 |
1966 | 1407 |
1967 static char * | 1408 static ngx_int_t |
1968 ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1409 ngx_http_fastcgi_add_variables(ngx_conf_t *cf) |
1969 { | 1410 { |
1970 ngx_http_fastcgi_loc_conf_t *lcf = conf; | 1411 ngx_http_variable_t *var; |
1971 | 1412 |
1972 ngx_str_t *value; | 1413 var = ngx_http_add_variable(cf, &ngx_http_fastcgi_script_name, 0); |
1973 ngx_inet_upstream_t inet_upstream; | 1414 if (var == NULL) { |
1974 ngx_http_core_loc_conf_t *clcf; | 1415 return NGX_ERROR; |
1975 #if (NGX_HAVE_UNIX_DOMAIN) | 1416 } |
1976 ngx_unix_domain_upstream_t unix_upstream; | 1417 |
1977 #endif | 1418 var->handler = ngx_http_fastcgi_script_name_variable; |
1978 | 1419 |
1979 value = cf->args->elts; | 1420 return NGX_OK; |
1980 | |
1981 if (ngx_strncasecmp(value[1].data, "unix:", 5) == 0) { | |
1982 | |
1983 #if (NGX_HAVE_UNIX_DOMAIN) | |
1984 | |
1985 ngx_memzero(&unix_upstream, sizeof(ngx_unix_domain_upstream_t)); | |
1986 | |
1987 unix_upstream.name = value[1]; | |
1988 unix_upstream.url = value[1]; | |
1989 | |
1990 lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream); | |
1991 if (lcf->peers == NULL) { | |
1992 return NGX_CONF_ERROR; | |
1993 } | |
1994 | |
1995 #else | |
1996 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1997 "the unix domain sockets are not supported " | |
1998 "on this platform"); | |
1999 return NGX_CONF_ERROR; | |
2000 | |
2001 #endif | |
2002 | |
2003 } else { | |
2004 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t)); | |
2005 | |
2006 inet_upstream.name = value[1]; | |
2007 inet_upstream.url = value[1]; | |
2008 | |
2009 lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream); | |
2010 if (lcf->peers == NULL) { | |
2011 return NGX_CONF_ERROR; | |
2012 } | |
2013 } | |
2014 | |
2015 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
2016 | |
2017 clcf->handler = ngx_http_fastcgi_handler; | |
2018 | |
2019 #if (NGX_PCRE) | |
2020 lcf->location = clcf->regex ? &ngx_http_fastcgi_uri : &clcf->name; | |
2021 #else | |
2022 lcf->location = &clcf->name; | |
2023 #endif | |
2024 | |
2025 if (clcf->name.data[clcf->name.len - 1] == '/') { | |
2026 clcf->auto_redirect = 1; | |
2027 } | |
2028 | |
2029 return NGX_CONF_OK; | |
2030 } | |
2031 | |
2032 | |
2033 static char * | |
2034 ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2035 { | |
2036 ngx_http_fastcgi_loc_conf_t *lcf = conf; | |
2037 | |
2038 ngx_uint_t i, *index; | |
2039 ngx_str_t *value; | |
2040 ngx_http_variable_t *var; | |
2041 ngx_http_core_main_conf_t *cmcf; | |
2042 | |
2043 if (lcf->vars == NULL) { | |
2044 lcf->vars = ngx_array_create(cf->pool, 4, | |
2045 sizeof(ngx_http_variable_t *)); | |
2046 if (lcf->vars == NULL) { | |
2047 return NGX_CONF_ERROR; | |
2048 } | |
2049 } | |
2050 | |
2051 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2052 | |
2053 value = cf->args->elts; | |
2054 | |
2055 var = cmcf->variables.elts; | |
2056 for (i = 0; i < cmcf->variables.nelts; i++) { | |
2057 if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) { | |
2058 | |
2059 index = ngx_array_push(lcf->vars); | |
2060 if (index == NULL) { | |
2061 return NGX_CONF_ERROR; | |
2062 } | |
2063 | |
2064 *index = var[i].index; | |
2065 return NGX_CONF_OK; | |
2066 } | |
2067 } | |
2068 | |
2069 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2070 "unknown variable name \"%V\"", &value[1]); | |
2071 return NGX_CONF_ERROR; | |
2072 } | |
2073 | |
2074 | |
2075 static char * | |
2076 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data) | |
2077 { | |
2078 #if (NGX_FREEBSD) | |
2079 ssize_t *np = data; | |
2080 | |
2081 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { | |
2082 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2083 "\"fastcgi_send_lowat\" must be less than %d " | |
2084 "(sysctl net.inet.tcp.sendspace)", | |
2085 ngx_freebsd_net_inet_tcp_sendspace); | |
2086 | |
2087 return NGX_CONF_ERROR; | |
2088 } | |
2089 | |
2090 #elif !(NGX_HAVE_SO_SNDLOWAT) | |
2091 ssize_t *np = data; | |
2092 | |
2093 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2094 "\"fastcgi_send_lowat\" is not supported, ignored"); | |
2095 | |
2096 *np = 0; | |
2097 | |
2098 #endif | |
2099 | |
2100 return NGX_CONF_OK; | |
2101 } | 1421 } |
2102 | 1422 |
2103 | 1423 |
2104 static void * | 1424 static void * |
2105 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) | 1425 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) |
2116 * | 1436 * |
2117 * conf->upstream.bufs.num = 0; | 1437 * conf->upstream.bufs.num = 0; |
2118 * conf->upstream.path = NULL; | 1438 * conf->upstream.path = NULL; |
2119 * conf->upstream.next_upstream = 0; | 1439 * conf->upstream.next_upstream = 0; |
2120 * conf->upstream.temp_path = NULL; | 1440 * conf->upstream.temp_path = NULL; |
2121 * conf->params = 0; | 1441 * conf->upstream.schema = { 0, NULL }; |
2122 * conf->root.len = 0; | 1442 * conf->upstream.uri = { 0, NULL }; |
2123 * conf->root.data = NULL; | 1443 * conf->upstream.location = NULL; |
1444 * | |
2124 * conf->index.len = 0; | 1445 * conf->index.len = 0; |
2125 * conf->index.data = NULL; | 1446 * conf->index.data = NULL; |
2126 * conf->location = NULL; | |
2127 */ | 1447 */ |
2128 | 1448 |
2129 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; | 1449 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
2130 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | 1450 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; |
2131 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | 1451 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; |
2133 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | 1453 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; |
2134 conf->upstream.header_buffer_size = NGX_CONF_UNSET_SIZE; | 1454 conf->upstream.header_buffer_size = NGX_CONF_UNSET_SIZE; |
2135 conf->upstream.busy_buffers_size = NGX_CONF_UNSET_SIZE; | 1455 conf->upstream.busy_buffers_size = NGX_CONF_UNSET_SIZE; |
2136 conf->upstream.max_temp_file_size = NGX_CONF_UNSET_SIZE; | 1456 conf->upstream.max_temp_file_size = NGX_CONF_UNSET_SIZE; |
2137 conf->upstream.temp_file_write_size = NGX_CONF_UNSET_SIZE; | 1457 conf->upstream.temp_file_write_size = NGX_CONF_UNSET_SIZE; |
2138 | 1458 |
1459 conf->upstream.pass_unparsed_uri = NGX_CONF_UNSET; | |
1460 conf->upstream.method = NGX_CONF_UNSET_UINT; | |
1461 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1462 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
1463 | |
2139 conf->upstream.redirect_errors = NGX_CONF_UNSET; | 1464 conf->upstream.redirect_errors = NGX_CONF_UNSET; |
2140 conf->upstream.pass_unparsed_uri = NGX_CONF_UNSET; | |
2141 conf->upstream.x_powered_by = NGX_CONF_UNSET; | |
2142 | 1465 |
2143 /* "fastcgi_cyclic_temp_file" is disabled */ | 1466 /* "fastcgi_cyclic_temp_file" is disabled */ |
2144 conf->upstream.cyclic_temp_file = 0; | 1467 conf->upstream.cyclic_temp_file = 0; |
1468 | |
1469 conf->upstream.pass_x_powered_by = NGX_CONF_UNSET; | |
1470 | |
1471 /* the hardcoded values */ | |
1472 conf->upstream.pass_server = 1; | |
1473 conf->upstream.pass_date = 1; | |
2145 | 1474 |
2146 return conf; | 1475 return conf; |
2147 } | 1476 } |
2148 | 1477 |
2149 | 1478 |
2151 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | 1480 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
2152 { | 1481 { |
2153 ngx_http_fastcgi_loc_conf_t *prev = parent; | 1482 ngx_http_fastcgi_loc_conf_t *prev = parent; |
2154 ngx_http_fastcgi_loc_conf_t *conf = child; | 1483 ngx_http_fastcgi_loc_conf_t *conf = child; |
2155 | 1484 |
2156 size_t size; | 1485 u_char *p; |
1486 size_t size; | |
1487 uintptr_t *code; | |
1488 ngx_uint_t i; | |
1489 ngx_table_elt_t *src; | |
1490 ngx_http_script_compile_t sc; | |
1491 ngx_http_script_copy_code_t *copy; | |
2157 | 1492 |
2158 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | 1493 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
2159 prev->upstream.connect_timeout, 60000); | 1494 prev->upstream.connect_timeout, 60000); |
2160 | 1495 |
2161 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | 1496 ngx_conf_merge_msec_value(conf->upstream.send_timeout, |
2261 ngx_conf_merge_path_value(conf->upstream.temp_path, | 1596 ngx_conf_merge_path_value(conf->upstream.temp_path, |
2262 prev->upstream.temp_path, | 1597 prev->upstream.temp_path, |
2263 NGX_HTTP_FASTCGI_TEMP_PATH, 1, 2, 0, | 1598 NGX_HTTP_FASTCGI_TEMP_PATH, 1, 2, 0, |
2264 ngx_garbage_collector_temp_handler, cf); | 1599 ngx_garbage_collector_temp_handler, cf); |
2265 | 1600 |
2266 | |
2267 ngx_conf_merge_msec_value(conf->upstream.redirect_errors, | |
2268 prev->upstream.redirect_errors, 0); | |
2269 | |
2270 ngx_conf_merge_msec_value(conf->upstream.pass_unparsed_uri, | 1601 ngx_conf_merge_msec_value(conf->upstream.pass_unparsed_uri, |
2271 prev->upstream.pass_unparsed_uri, 0); | 1602 prev->upstream.pass_unparsed_uri, 0); |
2272 | 1603 |
2273 if (conf->upstream.pass_unparsed_uri && conf->location->len > 1) { | 1604 if (conf->upstream.pass_unparsed_uri && conf->upstream.location->len > 1) { |
2274 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 1605 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
2275 "\"fastcgi_pass_unparsed_uri\" can be set for " | 1606 "\"fastcgi_pass_unparsed_uri\" can be set for " |
2276 "location \"/\" or given by regular expression."); | 1607 "location \"/\" or given by regular expression."); |
2277 return NGX_CONF_ERROR; | 1608 return NGX_CONF_ERROR; |
2278 } | 1609 } |
2279 | 1610 |
2280 ngx_conf_merge_msec_value(conf->upstream.x_powered_by, | 1611 if (conf->upstream.method == NGX_CONF_UNSET_UINT) { |
2281 prev->upstream.x_powered_by, 1); | 1612 conf->upstream.method = prev->upstream.method; |
2282 | 1613 } |
2283 | 1614 |
2284 ngx_conf_merge_bitmask_value(conf->params, prev->params, | 1615 ngx_conf_merge_value(conf->upstream.pass_request_headers, |
2285 (NGX_CONF_BITMASK_SET | 1616 prev->upstream.pass_request_headers, 1); |
2286 |NGX_HTTP_FASTCGI_REMOTE_ADDR | 1617 ngx_conf_merge_value(conf->upstream.pass_request_body, |
2287 |NGX_HTTP_FASTCGI_REMOTE_USER | 1618 prev->upstream.pass_request_body, 1); |
2288 |NGX_HTTP_FASTCGI_SERVER_NAME | 1619 |
2289 |NGX_HTTP_FASTCGI_SERVER_PORT | 1620 ngx_conf_merge_msec_value(conf->upstream.redirect_errors, |
2290 |NGX_HTTP_FASTCGI_SCRIPT_NAME | 1621 prev->upstream.redirect_errors, 0); |
2291 |NGX_HTTP_FASTCGI_AUTH_TYPE | 1622 |
2292 |NGX_HTTP_FASTCGI_REQUEST_URI | 1623 ngx_conf_merge_msec_value(conf->upstream.pass_x_powered_by, |
2293 |NGX_HTTP_FASTCGI_REDIRECT_STATUS)); | 1624 prev->upstream.pass_x_powered_by, 1); |
2294 | 1625 |
2295 ngx_conf_merge_str_value(conf->root, prev->root, ""); | |
2296 | |
2297 if (conf->root.len && conf->root.data[conf->root.len - 1] == '/') { | |
2298 conf->root.len--; | |
2299 } | |
2300 | 1626 |
2301 ngx_conf_merge_str_value(conf->index, prev->index, ""); | 1627 ngx_conf_merge_str_value(conf->index, prev->index, ""); |
2302 | |
2303 if (conf->vars == NULL) { | |
2304 conf->vars = prev->vars; | |
2305 } | |
2306 | 1628 |
2307 if (conf->peers == NULL) { | 1629 if (conf->peers == NULL) { |
2308 conf->peers = prev->peers; | 1630 conf->peers = prev->peers; |
2309 conf->upstream = prev->upstream; | 1631 conf->upstream = prev->upstream; |
2310 } | 1632 } |
2311 | 1633 |
1634 if (conf->params_source == NULL) { | |
1635 conf->params_source = prev->params_source; | |
1636 conf->params_len = prev->params_len; | |
1637 conf->params = prev->params; | |
1638 | |
1639 if (conf->params_source == NULL) { | |
1640 return NGX_CONF_OK; | |
1641 } | |
1642 } | |
1643 | |
1644 conf->params_len = ngx_array_create(cf->pool, 64, 1); | |
1645 if (conf->params_len == NULL) { | |
1646 return NGX_CONF_ERROR; | |
1647 } | |
1648 | |
1649 conf->params = ngx_array_create(cf->pool, 512, 1); | |
1650 if (conf->params == NULL) { | |
1651 return NGX_CONF_ERROR; | |
1652 } | |
1653 | |
1654 src = conf->params_source->elts; | |
1655 for (i = 0; i < conf->params_source->nelts; i++) { | |
1656 | |
1657 if (ngx_http_script_variables_count(&src[i].value) == 0) { | |
1658 copy = ngx_array_push_n(conf->params_len, | |
1659 sizeof(ngx_http_script_copy_code_t)); | |
1660 if (copy == NULL) { | |
1661 return NGX_CONF_ERROR; | |
1662 } | |
1663 | |
1664 copy->code = (ngx_http_script_code_pt) | |
1665 ngx_http_script_copy_len_code; | |
1666 copy->len = src[i].key.len; | |
1667 | |
1668 | |
1669 copy = ngx_array_push_n(conf->params_len, | |
1670 sizeof(ngx_http_script_copy_code_t)); | |
1671 if (copy == NULL) { | |
1672 return NGX_CONF_ERROR; | |
1673 } | |
1674 | |
1675 copy->code = (ngx_http_script_code_pt) | |
1676 ngx_http_script_copy_len_code; | |
1677 copy->len = src[i].value.len; | |
1678 | |
1679 | |
1680 size = (sizeof(ngx_http_script_copy_code_t) | |
1681 + src[i].key.len + src[i].value.len | |
1682 + sizeof(uintptr_t) - 1) | |
1683 & ~(sizeof(uintptr_t) - 1); | |
1684 | |
1685 copy = ngx_array_push_n(conf->params, size); | |
1686 if (copy == NULL) { | |
1687 return NGX_CONF_ERROR; | |
1688 } | |
1689 | |
1690 copy->code = ngx_http_script_copy_code; | |
1691 copy->len = src[i].key.len + src[i].value.len; | |
1692 | |
1693 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
1694 | |
1695 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
1696 ngx_memcpy(p, src[i].value.data, src[i].value.len); | |
1697 | |
1698 } else { | |
1699 copy = ngx_array_push_n(conf->params_len, | |
1700 sizeof(ngx_http_script_copy_code_t)); | |
1701 if (copy == NULL) { | |
1702 return NGX_CONF_ERROR; | |
1703 } | |
1704 | |
1705 copy->code = (ngx_http_script_code_pt) | |
1706 ngx_http_script_copy_len_code; | |
1707 copy->len = src[i].key.len; | |
1708 | |
1709 | |
1710 size = (sizeof(ngx_http_script_copy_code_t) | |
1711 + src[i].key.len + sizeof(uintptr_t) - 1) | |
1712 & ~(sizeof(uintptr_t) - 1); | |
1713 | |
1714 copy = ngx_array_push_n(conf->params, size); | |
1715 if (copy == NULL) { | |
1716 return NGX_CONF_ERROR; | |
1717 } | |
1718 | |
1719 copy->code = ngx_http_script_copy_code; | |
1720 copy->len = src[i].key.len; | |
1721 | |
1722 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
1723 ngx_memcpy(p, src[i].key.data, src[i].key.len); | |
1724 | |
1725 | |
1726 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1727 | |
1728 sc.cf = cf; | |
1729 sc.source = &src[i].value; | |
1730 sc.lengths = &conf->params_len; | |
1731 sc.values = &conf->params; | |
1732 | |
1733 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1734 return NGX_CONF_ERROR; | |
1735 } | |
1736 } | |
1737 | |
1738 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
1739 if (code == NULL) { | |
1740 return NGX_CONF_ERROR; | |
1741 } | |
1742 | |
1743 *code = (uintptr_t) NULL; | |
1744 | |
1745 | |
1746 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | |
1747 if (code == NULL) { | |
1748 return NGX_CONF_ERROR; | |
1749 } | |
1750 | |
1751 *code = (uintptr_t) NULL; | |
1752 } | |
1753 | |
1754 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | |
1755 if (code == NULL) { | |
1756 return NGX_CONF_ERROR; | |
1757 } | |
1758 | |
1759 *code = (uintptr_t) NULL; | |
1760 | |
2312 return NGX_CONF_OK; | 1761 return NGX_CONF_OK; |
2313 } | 1762 } |
1763 | |
1764 | |
1765 static ngx_http_variable_value_t * | |
1766 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, uintptr_t data) | |
1767 { | |
1768 u_char *p; | |
1769 ngx_http_variable_value_t *vv; | |
1770 ngx_http_fastcgi_loc_conf_t *flcf; | |
1771 | |
1772 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)); | |
1773 if (vv == NULL) { | |
1774 return NULL; | |
1775 } | |
1776 | |
1777 vv->value = 0; | |
1778 | |
1779 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); | |
1780 | |
1781 if (r->uri.data[r->uri.len - 1] != '/') { | |
1782 vv->text = r->uri; | |
1783 return vv; | |
1784 } | |
1785 | |
1786 vv->text.len = r->uri.len + flcf->index.len; | |
1787 | |
1788 vv->text.data = ngx_palloc(r->pool, vv->text.len); | |
1789 if (vv->text.data == NULL) { | |
1790 return NULL; | |
1791 } | |
1792 | |
1793 p = ngx_cpymem(vv->text.data, r->uri.data, r->uri.len); | |
1794 ngx_memcpy(p, flcf->index.data, flcf->index.len); | |
1795 | |
1796 return vv; | |
1797 } | |
1798 | |
1799 | |
1800 static char * | |
1801 ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1802 { | |
1803 ngx_http_fastcgi_loc_conf_t *lcf = conf; | |
1804 | |
1805 ngx_str_t *value; | |
1806 ngx_inet_upstream_t inet_upstream; | |
1807 ngx_http_core_loc_conf_t *clcf; | |
1808 #if (NGX_HAVE_UNIX_DOMAIN) | |
1809 ngx_unix_domain_upstream_t unix_upstream; | |
1810 #endif | |
1811 | |
1812 value = cf->args->elts; | |
1813 | |
1814 if (ngx_strncasecmp(value[1].data, "unix:", 5) == 0) { | |
1815 | |
1816 #if (NGX_HAVE_UNIX_DOMAIN) | |
1817 | |
1818 ngx_memzero(&unix_upstream, sizeof(ngx_unix_domain_upstream_t)); | |
1819 | |
1820 unix_upstream.name = value[1]; | |
1821 unix_upstream.url = value[1]; | |
1822 | |
1823 lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream); | |
1824 if (lcf->peers == NULL) { | |
1825 return NGX_CONF_ERROR; | |
1826 } | |
1827 | |
1828 #else | |
1829 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1830 "the unix domain sockets are not supported " | |
1831 "on this platform"); | |
1832 return NGX_CONF_ERROR; | |
1833 | |
1834 #endif | |
1835 | |
1836 } else { | |
1837 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t)); | |
1838 | |
1839 inet_upstream.name = value[1]; | |
1840 inet_upstream.url = value[1]; | |
1841 | |
1842 lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream); | |
1843 if (lcf->peers == NULL) { | |
1844 return NGX_CONF_ERROR; | |
1845 } | |
1846 } | |
1847 | |
1848 lcf->upstream.schema.len = sizeof("fastcgi://") - 1; | |
1849 lcf->upstream.schema.data = (u_char *) "fastcgi://"; | |
1850 lcf->upstream.uri.len = sizeof("/") - 1; | |
1851 lcf->upstream.uri.data = (u_char *) "/"; | |
1852 | |
1853 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
1854 | |
1855 clcf->handler = ngx_http_fastcgi_handler; | |
1856 | |
1857 #if (NGX_PCRE) | |
1858 lcf->upstream.location = clcf->regex ? &ngx_http_fastcgi_uri : &clcf->name; | |
1859 #else | |
1860 lcf->upstream.location = &clcf->name; | |
1861 #endif | |
1862 | |
1863 if (clcf->name.data[clcf->name.len - 1] == '/') { | |
1864 clcf->auto_redirect = 1; | |
1865 } | |
1866 | |
1867 return NGX_CONF_OK; | |
1868 } | |
1869 | |
1870 | |
1871 static char * | |
1872 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data) | |
1873 { | |
1874 #if (NGX_FREEBSD) | |
1875 ssize_t *np = data; | |
1876 | |
1877 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { | |
1878 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1879 "\"fastcgi_send_lowat\" must be less than %d " | |
1880 "(sysctl net.inet.tcp.sendspace)", | |
1881 ngx_freebsd_net_inet_tcp_sendspace); | |
1882 | |
1883 return NGX_CONF_ERROR; | |
1884 } | |
1885 | |
1886 #elif !(NGX_HAVE_SO_SNDLOWAT) | |
1887 ssize_t *np = data; | |
1888 | |
1889 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
1890 "\"fastcgi_send_lowat\" is not supported, ignored"); | |
1891 | |
1892 *np = 0; | |
1893 | |
1894 #endif | |
1895 | |
1896 return NGX_CONF_OK; | |
1897 } |