Mercurial > hg > nginx
annotate src/http/modules/ngx_http_proxy_module.c @ 2173:11c59ecbd04f
exit on libxslt test failure
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 13 Aug 2008 08:32:35 +0000 |
parents | 8c6521eedf84 |
children | 274c0f3ea600 |
rev | line source |
---|---|
507 | 1 |
577 | 2 /* |
507 | 3 * Copyright (C) Igor Sysoev |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_event.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
509 | 13 typedef struct ngx_http_proxy_redirect_s ngx_http_proxy_redirect_t; |
14 | |
15 typedef ngx_int_t (*ngx_http_proxy_redirect_pt)(ngx_http_request_t *r, | |
16 ngx_table_elt_t *h, size_t prefix, ngx_http_proxy_redirect_t *pr); | |
507 | 17 |
509 | 18 struct ngx_http_proxy_redirect_s { |
651 | 19 ngx_http_proxy_redirect_pt handler; |
20 ngx_str_t redirect; | |
507 | 21 |
509 | 22 union { |
651 | 23 ngx_str_t text; |
509 | 24 |
25 struct { | |
651 | 26 void *lengths; |
27 void *values; | |
509 | 28 } vars; |
507 | 29 |
651 | 30 void *regex; |
509 | 31 } replacement; |
32 }; | |
33 | |
34 | |
35 typedef struct { | |
1658 | 36 ngx_str_t host_header; |
37 ngx_str_t port; | |
38 ngx_str_t uri; | |
39 } ngx_http_proxy_vars_t; | |
40 | |
41 | |
42 typedef struct { | |
651 | 43 ngx_http_upstream_conf_t upstream; |
44 | |
45 ngx_array_t *flushes; | |
46 ngx_array_t *body_set_len; | |
47 ngx_array_t *body_set; | |
48 ngx_array_t *headers_set_len; | |
49 ngx_array_t *headers_set; | |
50 ngx_hash_t headers_set_hash; | |
51 | |
52 ngx_array_t *headers_source; | |
53 ngx_array_t *headers_names; | |
54 | |
1658 | 55 ngx_array_t *proxy_lengths; |
56 ngx_array_t *proxy_values; | |
57 | |
651 | 58 ngx_array_t *redirects; |
59 | |
60 ngx_str_t body_source; | |
61 | |
62 ngx_str_t method; | |
1658 | 63 ngx_str_t location; |
64 ngx_str_t url; | |
65 | |
66 ngx_http_proxy_vars_t vars; | |
651 | 67 |
68 ngx_flag_t redirect; | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
69 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
70 ngx_uint_t headers_hash_max_size; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
71 ngx_uint_t headers_hash_bucket_size; |
507 | 72 } ngx_http_proxy_loc_conf_t; |
73 | |
74 | |
75 typedef struct { | |
651 | 76 ngx_uint_t status; |
77 ngx_uint_t status_count; | |
78 u_char *status_start; | |
79 u_char *status_end; | |
80 | |
1658 | 81 ngx_http_proxy_vars_t vars; |
82 | |
651 | 83 size_t internal_body_length; |
509 | 84 } ngx_http_proxy_ctx_t; |
507 | 85 |
86 | |
509 | 87 #define NGX_HTTP_PROXY_PARSE_NO_HEADER 20 |
507 | 88 |
89 | |
1658 | 90 static ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r, |
91 ngx_http_proxy_ctx_t *ctx, ngx_http_proxy_loc_conf_t *plcf); | |
507 | 92 static ngx_int_t ngx_http_proxy_create_request(ngx_http_request_t *r); |
93 static ngx_int_t ngx_http_proxy_reinit_request(ngx_http_request_t *r); | |
509 | 94 static ngx_int_t ngx_http_proxy_process_status_line(ngx_http_request_t *r); |
95 static ngx_int_t ngx_http_proxy_parse_status_line(ngx_http_request_t *r, | |
1658 | 96 ngx_http_proxy_ctx_t *ctx); |
507 | 97 static ngx_int_t ngx_http_proxy_process_header(ngx_http_request_t *r); |
98 static void ngx_http_proxy_abort_request(ngx_http_request_t *r); | |
99 static void ngx_http_proxy_finalize_request(ngx_http_request_t *r, | |
100 ngx_int_t rc); | |
101 | |
573 | 102 static ngx_int_t ngx_http_proxy_host_variable(ngx_http_request_t *r, |
103 ngx_http_variable_value_t *v, uintptr_t data); | |
104 static ngx_int_t ngx_http_proxy_port_variable(ngx_http_request_t *r, | |
105 ngx_http_variable_value_t *v, uintptr_t data); | |
106 static ngx_int_t | |
509 | 107 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r, |
573 | 108 ngx_http_variable_value_t *v, uintptr_t data); |
577 | 109 static ngx_int_t |
110 ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r, | |
111 ngx_http_variable_value_t *v, uintptr_t data); | |
509 | 112 static ngx_int_t ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, |
113 ngx_table_elt_t *h, size_t prefix); | |
507 | 114 |
509 | 115 static ngx_int_t ngx_http_proxy_add_variables(ngx_conf_t *cf); |
507 | 116 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); |
117 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, | |
118 void *parent, void *child); | |
119 | |
120 static char *ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, | |
121 void *conf); | |
509 | 122 static char *ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, |
123 void *conf); | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
124 static char *ngx_http_proxy_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
|
125 void *conf); |
507 | 126 |
127 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); | |
128 | |
884 | 129 static char *ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, |
130 ngx_command_t *cmd, void *conf); | |
131 static char *ngx_http_proxy_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
132 ngx_command_t *cmd, void *conf); | |
133 | |
1658 | 134 #if (NGX_HTTP_SSL) |
135 static ngx_int_t ngx_http_proxy_set_ssl(ngx_conf_t *cf, | |
136 ngx_http_proxy_loc_conf_t *plcf); | |
137 #endif | |
138 static ngx_int_t ngx_http_proxy_set_vars(ngx_pool_t *pool, ngx_url_t *u, | |
139 ngx_http_proxy_vars_t *v); | |
140 | |
509 | 141 |
507 | 142 static ngx_conf_post_t ngx_http_proxy_lowat_post = |
509 | 143 { ngx_http_proxy_lowat_check }; |
144 | |
507 | 145 |
146 static ngx_conf_bitmask_t ngx_http_proxy_next_upstream_masks[] = { | |
147 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, | |
148 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, | |
149 { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, | |
150 { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 }, | |
623 | 151 { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 }, |
507 | 152 { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, |
665 | 153 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, |
507 | 154 { ngx_null_string, 0 } |
155 }; | |
156 | |
157 | |
158 static ngx_command_t ngx_http_proxy_commands[] = { | |
159 | |
160 { ngx_string("proxy_pass"), | |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
161 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1, |
507 | 162 ngx_http_proxy_pass, |
163 NGX_HTTP_LOC_CONF_OFFSET, | |
164 0, | |
165 NULL }, | |
166 | |
509 | 167 { ngx_string("proxy_redirect"), |
168 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, | |
169 ngx_http_proxy_redirect, | |
170 NGX_HTTP_LOC_CONF_OFFSET, | |
171 0, | |
172 NULL }, | |
173 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
174 { ngx_string("proxy_store"), |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
175 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
|
176 ngx_http_proxy_store, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
177 NGX_HTTP_LOC_CONF_OFFSET, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
178 0, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
179 NULL }, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
180 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
181 { ngx_string("proxy_store_access"), |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
182 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:
1244
diff
changeset
|
183 ngx_conf_set_access_slot, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
184 NGX_HTTP_LOC_CONF_OFFSET, |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
185 offsetof(ngx_http_proxy_loc_conf_t, upstream.store_access), |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
186 NULL }, |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
187 |
581 | 188 { ngx_string("proxy_buffering"), |
189 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
190 ngx_conf_set_flag_slot, | |
191 NGX_HTTP_LOC_CONF_OFFSET, | |
192 offsetof(ngx_http_proxy_loc_conf_t, upstream.buffering), | |
193 NULL }, | |
194 | |
629 | 195 { ngx_string("proxy_ignore_client_abort"), |
196 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
197 ngx_conf_set_flag_slot, | |
198 NGX_HTTP_LOC_CONF_OFFSET, | |
199 offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_client_abort), | |
200 NULL }, | |
201 | |
507 | 202 { ngx_string("proxy_connect_timeout"), |
203 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
204 ngx_conf_set_msec_slot, | |
205 NGX_HTTP_LOC_CONF_OFFSET, | |
206 offsetof(ngx_http_proxy_loc_conf_t, upstream.connect_timeout), | |
207 NULL }, | |
208 | |
209 { ngx_string("proxy_send_timeout"), | |
210 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
211 ngx_conf_set_msec_slot, | |
212 NGX_HTTP_LOC_CONF_OFFSET, | |
213 offsetof(ngx_http_proxy_loc_conf_t, upstream.send_timeout), | |
214 NULL }, | |
215 | |
216 { ngx_string("proxy_send_lowat"), | |
217 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
218 ngx_conf_set_size_slot, | |
219 NGX_HTTP_LOC_CONF_OFFSET, | |
220 offsetof(ngx_http_proxy_loc_conf_t, upstream.send_lowat), | |
221 &ngx_http_proxy_lowat_post }, | |
222 | |
657 | 223 { ngx_string("proxy_intercept_errors"), |
224 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
225 ngx_conf_set_flag_slot, | |
226 NGX_HTTP_LOC_CONF_OFFSET, | |
227 offsetof(ngx_http_proxy_loc_conf_t, upstream.intercept_errors), | |
228 NULL }, | |
229 | |
509 | 230 { ngx_string("proxy_set_header"), |
231 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
649 | 232 ngx_conf_set_keyval_slot, |
507 | 233 NGX_HTTP_LOC_CONF_OFFSET, |
509 | 234 offsetof(ngx_http_proxy_loc_conf_t, headers_source), |
507 | 235 NULL }, |
236 | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
237 { ngx_string("proxy_headers_hash_max_size"), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
238 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
239 ngx_conf_set_num_slot, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
240 NGX_HTTP_LOC_CONF_OFFSET, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
241 offsetof(ngx_http_proxy_loc_conf_t, headers_hash_max_size), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
242 NULL }, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
243 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
244 { ngx_string("proxy_headers_hash_bucket_size"), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
245 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
246 ngx_conf_set_num_slot, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
247 NGX_HTTP_LOC_CONF_OFFSET, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
248 offsetof(ngx_http_proxy_loc_conf_t, headers_hash_bucket_size), |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
249 NULL }, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
250 |
577 | 251 { ngx_string("proxy_set_body"), |
252 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
253 ngx_conf_set_str_slot, | |
254 NGX_HTTP_LOC_CONF_OFFSET, | |
255 offsetof(ngx_http_proxy_loc_conf_t, body_source), | |
256 NULL }, | |
257 | |
509 | 258 { ngx_string("proxy_method"), |
259 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
561 | 260 ngx_conf_set_str_slot, |
509 | 261 NGX_HTTP_LOC_CONF_OFFSET, |
561 | 262 offsetof(ngx_http_proxy_loc_conf_t, method), |
263 NULL }, | |
509 | 264 |
265 { ngx_string("proxy_pass_request_headers"), | |
507 | 266 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
267 ngx_conf_set_flag_slot, | |
268 NGX_HTTP_LOC_CONF_OFFSET, | |
509 | 269 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_request_headers), |
507 | 270 NULL }, |
271 | |
509 | 272 { ngx_string("proxy_pass_request_body"), |
507 | 273 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
274 ngx_conf_set_flag_slot, | |
275 NGX_HTTP_LOC_CONF_OFFSET, | |
509 | 276 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_request_body), |
507 | 277 NULL }, |
278 | |
581 | 279 { ngx_string("proxy_buffer_size"), |
280 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
281 ngx_conf_set_size_slot, | |
282 NGX_HTTP_LOC_CONF_OFFSET, | |
283 offsetof(ngx_http_proxy_loc_conf_t, upstream.buffer_size), | |
284 NULL }, | |
285 | |
507 | 286 { ngx_string("proxy_read_timeout"), |
287 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
288 ngx_conf_set_msec_slot, | |
289 NGX_HTTP_LOC_CONF_OFFSET, | |
290 offsetof(ngx_http_proxy_loc_conf_t, upstream.read_timeout), | |
291 NULL }, | |
292 | |
293 { ngx_string("proxy_buffers"), | |
294 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
295 ngx_conf_set_bufs_slot, | |
296 NGX_HTTP_LOC_CONF_OFFSET, | |
297 offsetof(ngx_http_proxy_loc_conf_t, upstream.bufs), | |
298 NULL }, | |
299 | |
300 { ngx_string("proxy_busy_buffers_size"), | |
301 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
302 ngx_conf_set_size_slot, | |
303 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 304 offsetof(ngx_http_proxy_loc_conf_t, upstream.busy_buffers_size_conf), |
507 | 305 NULL }, |
306 | |
307 { ngx_string("proxy_temp_path"), | |
308 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
309 ngx_conf_set_path_slot, | |
310 NGX_HTTP_LOC_CONF_OFFSET, | |
311 offsetof(ngx_http_proxy_loc_conf_t, upstream.temp_path), | |
312 (void *) ngx_garbage_collector_temp_handler }, | |
313 | |
314 { ngx_string("proxy_max_temp_file_size"), | |
315 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
316 ngx_conf_set_size_slot, | |
317 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 318 offsetof(ngx_http_proxy_loc_conf_t, upstream.max_temp_file_size_conf), |
507 | 319 NULL }, |
320 | |
321 { ngx_string("proxy_temp_file_write_size"), | |
322 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
323 ngx_conf_set_size_slot, | |
324 NGX_HTTP_LOC_CONF_OFFSET, | |
529 | 325 offsetof(ngx_http_proxy_loc_conf_t, upstream.temp_file_write_size_conf), |
507 | 326 NULL }, |
327 | |
328 { ngx_string("proxy_next_upstream"), | |
547 | 329 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
507 | 330 ngx_conf_set_bitmask_slot, |
331 NGX_HTTP_LOC_CONF_OFFSET, | |
332 offsetof(ngx_http_proxy_loc_conf_t, upstream.next_upstream), | |
333 &ngx_http_proxy_next_upstream_masks }, | |
334 | |
561 | 335 { ngx_string("proxy_upstream_max_fails"), |
336 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
884 | 337 ngx_http_proxy_upstream_max_fails_unsupported, |
338 0, | |
339 0, | |
561 | 340 NULL }, |
341 | |
342 { ngx_string("proxy_upstream_fail_timeout"), | |
343 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
884 | 344 ngx_http_proxy_upstream_fail_timeout_unsupported, |
345 0, | |
346 0, | |
561 | 347 NULL }, |
348 | |
649 | 349 { ngx_string("proxy_pass_header"), |
507 | 350 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
649 | 351 ngx_conf_set_str_array_slot, |
507 | 352 NGX_HTTP_LOC_CONF_OFFSET, |
649 | 353 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_headers), |
507 | 354 NULL }, |
355 | |
649 | 356 { ngx_string("proxy_hide_header"), |
507 | 357 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
649 | 358 ngx_conf_set_str_array_slot, |
507 | 359 NGX_HTTP_LOC_CONF_OFFSET, |
649 | 360 offsetof(ngx_http_proxy_loc_conf_t, upstream.hide_headers), |
507 | 361 NULL }, |
362 | |
363 ngx_null_command | |
364 }; | |
365 | |
366 | |
667 | 367 static ngx_http_module_t ngx_http_proxy_module_ctx = { |
509 | 368 ngx_http_proxy_add_variables, /* preconfiguration */ |
369 NULL, /* postconfiguration */ | |
507 | 370 |
371 NULL, /* create main configuration */ | |
372 NULL, /* init main configuration */ | |
373 | |
374 NULL, /* create server configuration */ | |
375 NULL, /* merge server configuration */ | |
376 | |
377 ngx_http_proxy_create_loc_conf, /* create location configration */ | |
378 ngx_http_proxy_merge_loc_conf /* merge location configration */ | |
379 }; | |
380 | |
381 | |
382 ngx_module_t ngx_http_proxy_module = { | |
509 | 383 NGX_MODULE_V1, |
507 | 384 &ngx_http_proxy_module_ctx, /* module context */ |
385 ngx_http_proxy_commands, /* module directives */ | |
386 NGX_HTTP_MODULE, /* module type */ | |
541 | 387 NULL, /* init master */ |
509 | 388 NULL, /* init module */ |
541 | 389 NULL, /* init process */ |
390 NULL, /* init thread */ | |
391 NULL, /* exit thread */ | |
392 NULL, /* exit process */ | |
393 NULL, /* exit master */ | |
394 NGX_MODULE_V1_PADDING | |
507 | 395 }; |
396 | |
397 | |
398 static char ngx_http_proxy_version[] = " HTTP/1.0" CRLF; | |
399 | |
509 | 400 |
649 | 401 static ngx_keyval_t ngx_http_proxy_headers[] = { |
402 { ngx_string("Host"), ngx_string("$proxy_host") }, | |
403 { ngx_string("Connection"), ngx_string("close") }, | |
404 { ngx_string("Keep-Alive"), ngx_string("") }, | |
2067 | 405 { ngx_string("Expect"), ngx_string("") }, |
649 | 406 { ngx_null_string, ngx_null_string } |
407 }; | |
408 | |
409 | |
410 static ngx_str_t ngx_http_proxy_hide_headers[] = { | |
411 ngx_string("Date"), | |
412 ngx_string("Server"), | |
413 ngx_string("X-Pad"), | |
414 ngx_string("X-Accel-Expires"), | |
415 ngx_string("X-Accel-Redirect"), | |
416 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:
1774
diff
changeset
|
417 ngx_string("X-Accel-Buffering"), |
2819956d1ca0
add X-Accel-Charset to ingored header, fix X-Accel-Buffering
Igor Sysoev <igor@sysoev.ru>
parents:
1774
diff
changeset
|
418 ngx_string("X-Accel-Charset"), |
649 | 419 ngx_null_string |
509 | 420 }; |
421 | |
422 | |
423 static ngx_http_variable_t ngx_http_proxy_vars[] = { | |
424 | |
637 | 425 { ngx_string("proxy_host"), NULL, ngx_http_proxy_host_variable, 0, |
1925
6fd26b0e1009
non cacheable $proxy_host and $proxy_port
Igor Sysoev <igor@sysoev.ru>
parents:
1912
diff
changeset
|
426 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 427 |
637 | 428 { ngx_string("proxy_port"), NULL, ngx_http_proxy_port_variable, 0, |
1925
6fd26b0e1009
non cacheable $proxy_host and $proxy_port
Igor Sysoev <igor@sysoev.ru>
parents:
1912
diff
changeset
|
429 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 430 |
637 | 431 { ngx_string("proxy_add_x_forwarded_for"), NULL, |
583 | 432 ngx_http_proxy_add_x_forwarded_for_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 433 |
434 #if 0 | |
637 | 435 { ngx_string("proxy_add_via"), NULL, NULL, 0, NGX_HTTP_VAR_NOHASH, 0 }, |
509 | 436 #endif |
437 | |
637 | 438 { ngx_string("proxy_internal_body_length"), NULL, |
583 | 439 ngx_http_proxy_internal_body_length_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, |
577 | 440 |
637 | 441 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
509 | 442 }; |
507 | 443 |
444 | |
445 static ngx_int_t | |
446 ngx_http_proxy_handler(ngx_http_request_t *r) | |
577 | 447 { |
507 | 448 ngx_int_t rc; |
449 ngx_http_upstream_t *u; | |
1658 | 450 ngx_http_proxy_ctx_t *ctx; |
507 | 451 ngx_http_proxy_loc_conf_t *plcf; |
577 | 452 |
507 | 453 u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t)); |
454 if (u == NULL) { | |
455 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
456 } | |
577 | 457 |
1658 | 458 r->upstream = u; |
459 | |
460 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_ctx_t)); | |
461 if (ctx == NULL) { | |
462 return NGX_ERROR; | |
463 } | |
464 | |
465 ngx_http_set_ctx(r, ctx, ngx_http_proxy_module); | |
466 | |
467 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
468 | |
469 if (plcf->proxy_lengths == 0) { | |
470 ctx->vars = plcf->vars; | |
471 u->schema = plcf->upstream.schema; | |
472 #if (NGX_HTTP_SSL) | |
473 u->ssl = (plcf->upstream.ssl != NULL); | |
474 #endif | |
475 | |
476 } else { | |
477 if (ngx_http_proxy_eval(r, ctx, plcf) != NGX_OK) { | |
478 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
479 } | |
480 } | |
481 | |
507 | 482 u->peer.log = r->connection->log; |
483 u->peer.log_error = NGX_ERROR_ERR; | |
484 #if (NGX_THREADS) | |
485 u->peer.lock = &r->connection->lock; | |
486 #endif | |
487 | |
488 u->output.tag = (ngx_buf_tag_t) &ngx_http_proxy_module; | |
489 | |
490 u->conf = &plcf->upstream; | |
491 | |
492 u->create_request = ngx_http_proxy_create_request; | |
493 u->reinit_request = ngx_http_proxy_reinit_request; | |
509 | 494 u->process_header = ngx_http_proxy_process_status_line; |
507 | 495 u->abort_request = ngx_http_proxy_abort_request; |
496 u->finalize_request = ngx_http_proxy_finalize_request; | |
497 | |
509 | 498 if (plcf->redirects) { |
499 u->rewrite_redirect = ngx_http_proxy_rewrite_redirect; | |
500 } | |
501 | |
649 | 502 u->buffering = plcf->upstream.buffering; |
503 | |
504 u->pipe = ngx_pcalloc(r->pool, sizeof(ngx_event_pipe_t)); | |
505 if (u->pipe == NULL) { | |
506 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
581 | 507 } |
507 | 508 |
649 | 509 u->pipe->input_filter = ngx_event_pipe_copy_input_filter; |
510 | |
509 | 511 u->accel = 1; |
577 | 512 |
507 | 513 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); |
514 | |
515 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
516 return rc; | |
517 } | |
518 | |
519 return NGX_DONE; | |
520 } | |
521 | |
522 | |
523 static ngx_int_t | |
1658 | 524 ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, |
525 ngx_http_proxy_loc_conf_t *plcf) | |
526 { | |
527 size_t add; | |
528 u_short port; | |
529 ngx_str_t proxy; | |
530 ngx_url_t u; | |
531 | |
532 if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0, | |
533 plcf->proxy_values->elts) | |
534 == NULL) | |
535 { | |
536 return NGX_ERROR; | |
537 } | |
538 | |
539 if (ngx_strncasecmp(proxy.data, (u_char *) "http://", 7) == 0) { | |
540 | |
541 add = 7; | |
542 port = 80; | |
543 | |
544 #if (NGX_HTTP_SSL) | |
545 | |
546 } else if (ngx_strncasecmp(proxy.data, (u_char *) "https://", 8) == 0) { | |
547 | |
548 add = 8; | |
549 port = 443; | |
550 r->upstream->ssl = 1; | |
551 | |
552 #endif | |
553 | |
554 } else { | |
555 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
556 "invalid URL prefix in \"%V\"", &proxy); | |
557 return NGX_ERROR; | |
558 } | |
559 | |
560 r->upstream->schema.len = add; | |
561 r->upstream->schema.data = proxy.data; | |
562 | |
563 ngx_memzero(&u, sizeof(ngx_url_t)); | |
564 | |
565 u.url.len = proxy.len - add; | |
566 u.url.data = proxy.data + add; | |
567 u.default_port = port; | |
568 u.uri_part = 1; | |
569 u.no_resolve = 1; | |
570 | |
571 if (ngx_parse_url(r->pool, &u) != NGX_OK) { | |
572 if (u.err) { | |
573 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
574 "%s in upstream \"%V\"", u.err, &u.url); | |
575 } | |
576 | |
577 return NGX_ERROR; | |
578 } | |
579 | |
580 if (ngx_http_proxy_set_vars(r->pool, &u, &ctx->vars) != NGX_OK) { | |
581 return NGX_ERROR; | |
582 } | |
583 | |
584 r->upstream->resolved = ngx_pcalloc(r->pool, | |
585 sizeof(ngx_http_upstream_resolved_t)); | |
586 if (r->upstream->resolved == NULL) { | |
587 return NGX_ERROR; | |
588 } | |
589 | |
590 r->upstream->resolved->host = u.host; | |
591 r->upstream->resolved->port = (in_port_t) (u.no_port ? u.default_port: | |
592 u.port); | |
1912 | 593 r->upstream->resolved->default_port = u.default_port; |
1658 | 594 |
595 return NGX_OK; | |
596 } | |
597 | |
598 | |
599 static ngx_int_t | |
507 | 600 ngx_http_proxy_create_request(ngx_http_request_t *r) |
601 { | |
577 | 602 size_t len, loc_len, body_len; |
509 | 603 uintptr_t escape; |
604 ngx_buf_t *b; | |
649 | 605 ngx_str_t method; |
606 ngx_uint_t i, unparsed_uri; | |
509 | 607 ngx_chain_t *cl, *body; |
608 ngx_list_part_t *part; | |
609 ngx_table_elt_t *header; | |
610 ngx_http_upstream_t *u; | |
1658 | 611 ngx_http_proxy_ctx_t *ctx; |
509 | 612 ngx_http_script_code_pt code; |
613 ngx_http_script_engine_t e, le; | |
614 ngx_http_proxy_loc_conf_t *plcf; | |
615 ngx_http_script_len_code_pt lcode; | |
507 | 616 |
617 u = r->upstream; | |
618 | |
619 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
620 | |
561 | 621 if (u->method.len) { |
622 /* HEAD was changed to GET to cache response */ | |
623 method = u->method; | |
624 method.len++; | |
625 | |
626 } else if (plcf->method.len) { | |
627 method = plcf->method; | |
628 | |
507 | 629 } else { |
561 | 630 method = r->method_name; |
631 method.len++; | |
507 | 632 } |
633 | |
1667 | 634 len = method.len + sizeof(ngx_http_proxy_version) - 1 + sizeof(CRLF) - 1; |
635 | |
507 | 636 escape = 0; |
1658 | 637 loc_len = 0; |
638 unparsed_uri = 0; | |
639 | |
640 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
641 | |
642 if (plcf->proxy_lengths) { | |
1667 | 643 len += ctx->vars.uri.len; |
1658 | 644 |
645 } else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main) | |
646 { | |
609 | 647 unparsed_uri = 1; |
1667 | 648 len += r->unparsed_uri.len; |
507 | 649 |
650 } else { | |
1658 | 651 loc_len = (r->valid_location && ctx->vars.uri.len) ? |
652 plcf->location.len : 0; | |
653 | |
1466
943f2ba615cd
escape internal request URI in proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
1353
diff
changeset
|
654 if (r->quoted_uri || r->internal) { |
509 | 655 escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, |
656 r->uri.len - loc_len, NGX_ESCAPE_URI); | |
507 | 657 } |
658 | |
1688 | 659 len += ctx->vars.uri.len + r->uri.len - loc_len + escape |
660 + sizeof("?") - 1 + r->args.len; | |
507 | 661 } |
662 | |
1565 | 663 ngx_http_script_flush_no_cacheable_variables(r, plcf->flushes); |
573 | 664 |
577 | 665 if (plcf->body_set_len) { |
666 le.ip = plcf->body_set_len->elts; | |
667 le.request = r; | |
668 le.flushed = 1; | |
669 body_len = 0; | |
670 | |
671 while (*(uintptr_t *) le.ip) { | |
672 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
673 body_len += lcode(&le); | |
674 } | |
675 | |
1658 | 676 ctx->internal_body_length = body_len; |
577 | 677 len += body_len; |
678 } | |
679 | |
509 | 680 le.ip = plcf->headers_set_len->elts; |
681 le.request = r; | |
573 | 682 le.flushed = 1; |
507 | 683 |
509 | 684 while (*(uintptr_t *) le.ip) { |
685 while (*(uintptr_t *) le.ip) { | |
686 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
687 len += lcode(&le); | |
688 } | |
689 le.ip += sizeof(uintptr_t); | |
507 | 690 } |
691 | |
692 | |
509 | 693 if (plcf->upstream.pass_request_headers) { |
694 part = &r->headers_in.headers.part; | |
695 header = part->elts; | |
696 | |
697 for (i = 0; /* void */; i++) { | |
507 | 698 |
509 | 699 if (i >= part->nelts) { |
700 if (part->next == NULL) { | |
701 break; | |
702 } | |
703 | |
704 part = part->next; | |
705 header = part->elts; | |
577 | 706 i = 0; |
507 | 707 } |
708 | |
649 | 709 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
710 header[i].lowcase_key, header[i].key.len)) | |
509 | 711 { |
712 continue; | |
713 } | |
714 | |
715 len += header[i].key.len + sizeof(": ") - 1 | |
716 + header[i].value.len + sizeof(CRLF) - 1; | |
507 | 717 } |
509 | 718 } |
507 | 719 |
720 | |
721 b = ngx_create_temp_buf(r->pool, len); | |
722 if (b == NULL) { | |
723 return NGX_ERROR; | |
724 } | |
725 | |
726 cl = ngx_alloc_chain_link(r->pool); | |
727 if (cl == NULL) { | |
728 return NGX_ERROR; | |
729 } | |
730 | |
731 cl->buf = b; | |
732 | |
733 | |
734 /* the request line */ | |
735 | |
573 | 736 b->last = ngx_copy(b->last, method.data, method.len); |
507 | 737 |
555 | 738 u->uri.data = b->last; |
739 | |
1658 | 740 if (plcf->proxy_lengths) { |
741 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); | |
742 | |
743 } else if (unparsed_uri) { | |
573 | 744 b->last = ngx_copy(b->last, r->unparsed_uri.data, r->unparsed_uri.len); |
745 | |
507 | 746 } else { |
555 | 747 if (r->valid_location) { |
1658 | 748 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); |
555 | 749 } |
551 | 750 |
507 | 751 if (escape) { |
509 | 752 ngx_escape_uri(b->last, r->uri.data + loc_len, |
753 r->uri.len - loc_len, NGX_ESCAPE_URI); | |
754 b->last += r->uri.len - loc_len + escape; | |
507 | 755 |
577 | 756 } else { |
573 | 757 b->last = ngx_copy(b->last, r->uri.data + loc_len, |
758 r->uri.len - loc_len); | |
507 | 759 } |
760 | |
761 if (r->args.len > 0) { | |
762 *b->last++ = '?'; | |
573 | 763 b->last = ngx_copy(b->last, r->args.data, r->args.len); |
507 | 764 } |
765 } | |
766 | |
555 | 767 u->uri.len = b->last - u->uri.data; |
768 | |
507 | 769 b->last = ngx_cpymem(b->last, ngx_http_proxy_version, |
770 sizeof(ngx_http_proxy_version) - 1); | |
771 | |
577 | 772 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
507 | 773 |
774 e.ip = plcf->headers_set->elts; | |
775 e.pos = b->last; | |
509 | 776 e.request = r; |
573 | 777 e.flushed = 1; |
507 | 778 |
509 | 779 le.ip = plcf->headers_set_len->elts; |
780 | |
781 while (*(uintptr_t *) le.ip) { | |
782 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
515 | 783 |
784 /* skip the header line name length */ | |
785 (void) lcode(&le); | |
509 | 786 |
787 if (*(ngx_http_script_len_code_pt *) le.ip) { | |
788 | |
789 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
790 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
791 } | |
792 | |
793 e.skip = (len == sizeof(CRLF) - 1) ? 1 : 0; | |
794 | |
795 } else { | |
796 e.skip = 0; | |
797 } | |
798 | |
799 le.ip += sizeof(uintptr_t); | |
800 | |
801 while (*(uintptr_t *) e.ip) { | |
802 code = *(ngx_http_script_code_pt *) e.ip; | |
803 code((ngx_http_script_engine_t *) &e); | |
577 | 804 } |
509 | 805 e.ip += sizeof(uintptr_t); |
507 | 806 } |
807 | |
808 b->last = e.pos; | |
809 | |
810 | |
509 | 811 if (plcf->upstream.pass_request_headers) { |
812 part = &r->headers_in.headers.part; | |
813 header = part->elts; | |
577 | 814 |
509 | 815 for (i = 0; /* void */; i++) { |
507 | 816 |
509 | 817 if (i >= part->nelts) { |
818 if (part->next == NULL) { | |
819 break; | |
820 } | |
821 | |
822 part = part->next; | |
823 header = part->elts; | |
577 | 824 i = 0; |
507 | 825 } |
826 | |
649 | 827 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
828 header[i].lowcase_key, header[i].key.len)) | |
509 | 829 { |
830 continue; | |
831 } | |
507 | 832 |
573 | 833 b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len); |
507 | 834 |
509 | 835 *b->last++ = ':'; *b->last++ = ' '; |
507 | 836 |
573 | 837 b->last = ngx_copy(b->last, header[i].value.data, |
838 header[i].value.len); | |
507 | 839 |
509 | 840 *b->last++ = CR; *b->last++ = LF; |
507 | 841 |
509 | 842 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
843 "http proxy header: \"%V: %V\"", | |
844 &header[i].key, &header[i].value); | |
845 } | |
507 | 846 } |
847 | |
577 | 848 |
507 | 849 /* add "\r\n" at the header end */ |
850 *b->last++ = CR; *b->last++ = LF; | |
851 | |
577 | 852 if (plcf->body_set) { |
853 e.ip = plcf->body_set->elts; | |
854 e.pos = b->last; | |
855 | |
856 while (*(uintptr_t *) e.ip) { | |
857 code = *(ngx_http_script_code_pt *) e.ip; | |
858 code((ngx_http_script_engine_t *) &e); | |
859 } | |
579 | 860 |
861 b->last = e.pos; | |
577 | 862 } |
863 | |
1774 | 864 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
865 "http proxy header:\n\"%*s\"", | |
866 (size_t) (b->last - b->pos), b->pos); | |
507 | 867 |
577 | 868 if (plcf->body_set == NULL && plcf->upstream.pass_request_body) { |
509 | 869 |
870 body = u->request_bufs; | |
871 u->request_bufs = cl; | |
872 | |
873 while (body) { | |
874 b = ngx_alloc_buf(r->pool); | |
875 if (b == NULL) { | |
876 return NGX_ERROR; | |
877 } | |
878 | |
879 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); | |
880 | |
881 cl->next = ngx_alloc_chain_link(r->pool); | |
882 if (cl->next == NULL) { | |
883 return NGX_ERROR; | |
884 } | |
885 | |
886 cl = cl->next; | |
887 cl->buf = b; | |
888 | |
889 body = body->next; | |
890 } | |
891 | |
611 | 892 b->flush = 1; |
893 | |
509 | 894 } else { |
895 u->request_bufs = cl; | |
896 } | |
897 | |
898 cl->next = NULL; | |
899 | |
507 | 900 return NGX_OK; |
901 } | |
902 | |
903 | |
904 static ngx_int_t | |
905 ngx_http_proxy_reinit_request(ngx_http_request_t *r) | |
906 { | |
1658 | 907 ngx_http_proxy_ctx_t *ctx; |
908 | |
909 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
910 | |
911 if (ctx == NULL) { | |
509 | 912 return NGX_OK; |
913 } | |
914 | |
1658 | 915 ctx->status = 0; |
916 ctx->status_count = 0; | |
917 ctx->status_start = NULL; | |
918 ctx->status_end = NULL; | |
509 | 919 |
920 r->upstream->process_header = ngx_http_proxy_process_status_line; | |
921 | |
922 return NGX_OK; | |
923 } | |
924 | |
925 | |
926 static ngx_int_t | |
927 ngx_http_proxy_process_status_line(ngx_http_request_t *r) | |
928 { | |
929 ngx_int_t rc; | |
930 ngx_http_upstream_t *u; | |
1658 | 931 ngx_http_proxy_ctx_t *ctx; |
932 | |
933 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
934 | |
935 if (ctx == NULL) { | |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
936 return NGX_ERROR; |
509 | 937 } |
938 | |
1658 | 939 rc = ngx_http_proxy_parse_status_line(r, ctx); |
509 | 940 |
941 if (rc == NGX_AGAIN) { | |
942 return rc; | |
943 } | |
944 | |
945 u = r->upstream; | |
946 | |
947 if (rc == NGX_HTTP_PROXY_PARSE_NO_HEADER) { | |
948 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
577 | 949 "upstream sent no valid HTTP/1.0 header"); |
509 | 950 |
619 | 951 #if 0 |
509 | 952 if (u->accel) { |
953 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
954 } | |
619 | 955 #endif |
509 | 956 |
957 r->http_version = NGX_HTTP_VERSION_9; | |
1616 | 958 u->headers_in.status_n = NGX_HTTP_OK; |
959 u->state->status = NGX_HTTP_OK; | |
577 | 960 |
509 | 961 return NGX_OK; |
962 } | |
963 | |
1658 | 964 u->headers_in.status_n = ctx->status; |
965 u->state->status = ctx->status; | |
966 | |
967 u->headers_in.status_line.len = ctx->status_end - ctx->status_start; | |
2049 | 968 u->headers_in.status_line.data = ngx_pnalloc(r->pool, |
969 u->headers_in.status_line.len); | |
529 | 970 if (u->headers_in.status_line.data == NULL) { |
1699
976db8c6fb64
return NGX_ERROR instead of NGX_HTTP_INTERNAL_SERVER_ERROR in u->parse_header()
Igor Sysoev <igor@sysoev.ru>
parents:
1688
diff
changeset
|
971 return NGX_ERROR; |
509 | 972 } |
573 | 973 |
1658 | 974 ngx_memcpy(u->headers_in.status_line.data, ctx->status_start, |
529 | 975 u->headers_in.status_line.len); |
509 | 976 |
977 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
978 "http proxy status %ui \"%V\"", | |
936 | 979 u->headers_in.status_n, &u->headers_in.status_line); |
509 | 980 |
981 u->process_header = ngx_http_proxy_process_header; | |
982 | |
983 return ngx_http_proxy_process_header(r); | |
984 } | |
985 | |
986 | |
987 static ngx_int_t | |
1658 | 988 ngx_http_proxy_parse_status_line(ngx_http_request_t *r, |
989 ngx_http_proxy_ctx_t *ctx) | |
509 | 990 { |
991 u_char ch; | |
1658 | 992 u_char *p; |
509 | 993 ngx_http_upstream_t *u; |
994 enum { | |
995 sw_start = 0, | |
996 sw_H, | |
997 sw_HT, | |
998 sw_HTT, | |
999 sw_HTTP, | |
1000 sw_first_major_digit, | |
1001 sw_major_digit, | |
1002 sw_first_minor_digit, | |
1003 sw_minor_digit, | |
1004 sw_status, | |
1005 sw_space_after_status, | |
1006 sw_status_text, | |
1007 sw_almost_done | |
577 | 1008 } state; |
509 | 1009 |
1010 u = r->upstream; | |
1011 | |
1012 state = r->state; | |
1013 | |
1658 | 1014 for (p = u->buffer.pos; p < u->buffer.last; p++) { |
1015 ch = *p; | |
509 | 1016 |
1017 switch (state) { | |
1018 | |
1019 /* "HTTP/" */ | |
1020 case sw_start: | |
1021 switch (ch) { | |
577 | 1022 case 'H': |
509 | 1023 state = sw_H; |
1024 break; | |
1025 default: | |
1026 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1027 } | |
1028 break; | |
1029 | |
577 | 1030 case sw_H: |
509 | 1031 switch (ch) { |
577 | 1032 case 'T': |
509 | 1033 state = sw_HT; |
1034 break; | |
1035 default: | |
1036 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1037 } | |
1038 break; | |
1039 | |
1040 case sw_HT: | |
1041 switch (ch) { | |
577 | 1042 case 'T': |
509 | 1043 state = sw_HTT; |
1044 break; | |
1045 default: | |
1046 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1047 } | |
1048 break; | |
1049 | |
1050 case sw_HTT: | |
1051 switch (ch) { | |
577 | 1052 case 'P': |
509 | 1053 state = sw_HTTP; |
1054 break; | |
1055 default: | |
1056 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1057 } | |
1058 break; | |
1059 | |
1060 case sw_HTTP: | |
1061 switch (ch) { | |
577 | 1062 case '/': |
509 | 1063 state = sw_first_major_digit; |
1064 break; | |
1065 default: | |
1066 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1067 } | |
1068 break; | |
1069 | |
1070 /* the first digit of major HTTP version */ | |
1071 case sw_first_major_digit: | |
1072 if (ch < '1' || ch > '9') { | |
1073 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1074 } | |
1075 | |
1076 state = sw_major_digit; | |
1077 break; | |
1078 | |
1079 /* the major HTTP version or dot */ | |
1080 case sw_major_digit: | |
1081 if (ch == '.') { | |
1082 state = sw_first_minor_digit; | |
1083 break; | |
1084 } | |
1085 | |
1086 if (ch < '0' || ch > '9') { | |
1087 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1088 } | |
1089 | |
1090 break; | |
1091 | |
1092 /* the first digit of minor HTTP version */ | |
1093 case sw_first_minor_digit: | |
1094 if (ch < '0' || ch > '9') { | |
1095 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1096 } | |
1097 | |
1098 state = sw_minor_digit; | |
1099 break; | |
1100 | |
1101 /* the minor HTTP version or the end of the request line */ | |
1102 case sw_minor_digit: | |
1103 if (ch == ' ') { | |
1104 state = sw_status; | |
1105 break; | |
1106 } | |
1107 | |
1108 if (ch < '0' || ch > '9') { | |
1109 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1110 } | |
1111 | |
1112 break; | |
1113 | |
1114 /* HTTP status code */ | |
1115 case sw_status: | |
619 | 1116 if (ch == ' ') { |
1117 break; | |
1118 } | |
1119 | |
509 | 1120 if (ch < '0' || ch > '9') { |
1121 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1122 } | |
1123 | |
1658 | 1124 ctx->status = ctx->status * 10 + ch - '0'; |
1125 | |
1126 if (++ctx->status_count == 3) { | |
509 | 1127 state = sw_space_after_status; |
1658 | 1128 ctx->status_start = p - 2; |
509 | 1129 } |
1130 | |
1131 break; | |
1132 | |
1133 /* space or end of line */ | |
1134 case sw_space_after_status: | |
1135 switch (ch) { | |
577 | 1136 case ' ': |
509 | 1137 state = sw_status_text; |
1138 break; | |
1139 case '.': /* IIS may send 403.1, 403.2, etc */ | |
1140 state = sw_status_text; | |
1141 break; | |
1142 case CR: | |
1143 state = sw_almost_done; | |
1144 break; | |
1145 case LF: | |
1146 goto done; | |
1147 default: | |
1148 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1149 } | |
1150 break; | |
1151 | |
1152 /* any text until end of line */ | |
1153 case sw_status_text: | |
1154 switch (ch) { | |
1155 case CR: | |
1156 state = sw_almost_done; | |
1157 | |
1158 break; | |
1159 case LF: | |
1160 goto done; | |
1161 } | |
1162 break; | |
1163 | |
527 | 1164 /* end of status line */ |
509 | 1165 case sw_almost_done: |
1658 | 1166 ctx->status_end = p - 1; |
509 | 1167 switch (ch) { |
1168 case LF: | |
1169 goto done; | |
1170 default: | |
1171 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1172 } | |
1173 } | |
1174 } | |
1175 | |
1658 | 1176 u->buffer.pos = p; |
509 | 1177 r->state = state; |
1178 | |
1179 return NGX_AGAIN; | |
1180 | |
1181 done: | |
1182 | |
1658 | 1183 u->buffer.pos = p + 1; |
1184 | |
1185 if (ctx->status_end == NULL) { | |
1186 ctx->status_end = p; | |
509 | 1187 } |
1188 | |
1189 r->state = sw_start; | |
1190 | |
507 | 1191 return NGX_OK; |
1192 } | |
1193 | |
1194 | |
1195 static ngx_int_t | |
1196 ngx_http_proxy_process_header(ngx_http_request_t *r) | |
1197 { | |
509 | 1198 ngx_int_t rc; |
1199 ngx_table_elt_t *h; | |
1200 ngx_http_upstream_header_t *hh; | |
1201 ngx_http_upstream_main_conf_t *umcf; | |
1202 | |
1203 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
1204 | |
2024 | 1205 for ( ;; ) { |
509 | 1206 |
581 | 1207 rc = ngx_http_parse_header_line(r, &r->upstream->buffer); |
509 | 1208 |
1209 if (rc == NGX_OK) { | |
1210 | |
1211 /* a header line has been parsed successfully */ | |
507 | 1212 |
509 | 1213 h = ngx_list_push(&r->upstream->headers_in.headers); |
1214 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:
1688
diff
changeset
|
1215 return NGX_ERROR; |
509 | 1216 } |
1217 | |
1218 h->hash = r->header_hash; | |
1219 | |
1220 h->key.len = r->header_name_end - r->header_name_start; | |
1221 h->value.len = r->header_end - r->header_start; | |
1222 | |
2049 | 1223 h->key.data = ngx_pnalloc(r->pool, |
649 | 1224 h->key.len + 1 + h->value.len + 1 + h->key.len); |
509 | 1225 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:
1688
diff
changeset
|
1226 return NGX_ERROR; |
509 | 1227 } |
1228 | |
1229 h->value.data = h->key.data + h->key.len + 1; | |
649 | 1230 h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1; |
507 | 1231 |
509 | 1232 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1); |
1233 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1); | |
1234 | |
649 | 1235 if (h->key.len == r->lowcase_index) { |
1236 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); | |
1237 | |
1238 } else { | |
2135 | 1239 ngx_strlow(h->lowcase_key, h->key.data, h->key.len); |
509 | 1240 } |
1241 | |
649 | 1242 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, |
1243 h->lowcase_key, h->key.len); | |
1244 | |
1245 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:
1688
diff
changeset
|
1246 return NGX_ERROR; |
649 | 1247 } |
1248 | |
509 | 1249 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1250 "http proxy header: \"%V: %V\"", | |
1251 &h->key, &h->value); | |
1252 | |
1253 continue; | |
1254 } | |
1255 | |
1256 if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | |
1257 | |
1258 /* a whole header has been parsed successfully */ | |
1259 | |
1260 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1261 "http proxy header done"); | |
1262 | |
649 | 1263 /* |
1264 * if no "Server" and "Date" in header line, | |
1265 * then add the special empty headers | |
1266 */ | |
1267 | |
1268 if (r->upstream->headers_in.server == NULL) { | |
1269 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1270 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:
1688
diff
changeset
|
1271 return NGX_ERROR; |
649 | 1272 } |
1273 | |
1274 h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash( | |
1275 ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r'); | |
1276 | |
1277 h->key.len = sizeof("Server") - 1; | |
1278 h->key.data = (u_char *) "Server"; | |
1279 h->value.len = 0; | |
1280 h->value.data = NULL; | |
1281 h->lowcase_key = (u_char *) "server"; | |
1282 } | |
1283 | |
1284 if (r->upstream->headers_in.date == NULL) { | |
1285 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1286 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:
1688
diff
changeset
|
1287 return NGX_ERROR; |
649 | 1288 } |
1289 | |
1290 h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e'); | |
1291 | |
1292 h->key.len = sizeof("Date") - 1; | |
1293 h->key.data = (u_char *) "Date"; | |
1294 h->value.len = 0; | |
1295 h->value.data = NULL; | |
1296 h->lowcase_key = (u_char *) "date"; | |
1297 } | |
1298 | |
509 | 1299 return NGX_OK; |
1300 } | |
1301 | |
521 | 1302 if (rc == NGX_AGAIN) { |
1303 return NGX_AGAIN; | |
1304 } | |
1305 | |
509 | 1306 /* there was error while a header line parsing */ |
1307 | |
1308 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
619 | 1309 "upstream sent invalid header"); |
509 | 1310 |
1311 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1312 } | |
507 | 1313 } |
1314 | |
1315 | |
1316 static void | |
1317 ngx_http_proxy_abort_request(ngx_http_request_t *r) | |
1318 { | |
1319 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1320 "abort http proxy request"); | |
577 | 1321 |
507 | 1322 return; |
1323 } | |
1324 | |
1325 | |
1326 static void | |
1327 ngx_http_proxy_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
577 | 1328 { |
507 | 1329 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1330 "finalize http proxy request"); | |
1331 | |
1332 return; | |
1333 } | |
1334 | |
1335 | |
573 | 1336 static ngx_int_t |
1337 ngx_http_proxy_host_variable(ngx_http_request_t *r, | |
1338 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1339 { |
1658 | 1340 ngx_http_proxy_ctx_t *ctx; |
1341 | |
1342 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1343 | |
1344 if (ctx == NULL) { | |
1345 v->not_found = 1; | |
1346 return NGX_OK; | |
1347 } | |
1348 | |
1349 v->len = ctx->vars.host_header.len; | |
577 | 1350 v->valid = 1; |
1565 | 1351 v->no_cacheable = 0; |
573 | 1352 v->not_found = 0; |
1658 | 1353 v->data = ctx->vars.host_header.data; |
507 | 1354 |
573 | 1355 return NGX_OK; |
507 | 1356 } |
1357 | |
1358 | |
573 | 1359 static ngx_int_t |
1360 ngx_http_proxy_port_variable(ngx_http_request_t *r, | |
1361 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1362 { |
1658 | 1363 ngx_http_proxy_ctx_t *ctx; |
1364 | |
1365 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1366 | |
1367 if (ctx == NULL) { | |
1368 v->not_found = 1; | |
1369 return NGX_OK; | |
1370 } | |
1371 | |
1372 v->len = ctx->vars.port.len; | |
577 | 1373 v->valid = 1; |
1565 | 1374 v->no_cacheable = 0; |
573 | 1375 v->not_found = 0; |
1658 | 1376 v->data = ctx->vars.port.data; |
509 | 1377 |
573 | 1378 return NGX_OK; |
509 | 1379 } |
1380 | |
1381 | |
573 | 1382 static ngx_int_t |
509 | 1383 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r, |
573 | 1384 ngx_http_variable_value_t *v, uintptr_t data) |
509 | 1385 { |
573 | 1386 u_char *p; |
509 | 1387 |
577 | 1388 v->valid = 1; |
1565 | 1389 v->no_cacheable = 0; |
573 | 1390 v->not_found = 0; |
509 | 1391 |
1392 if (r->headers_in.x_forwarded_for == NULL) { | |
573 | 1393 v->len = r->connection->addr_text.len; |
1394 v->data = r->connection->addr_text.data; | |
1395 return NGX_OK; | |
509 | 1396 } |
1397 | |
573 | 1398 v->len = r->headers_in.x_forwarded_for->value.len |
1399 + sizeof(", ") - 1 + r->connection->addr_text.len; | |
509 | 1400 |
2049 | 1401 p = ngx_pnalloc(r->pool, v->len); |
509 | 1402 if (p == NULL) { |
573 | 1403 return NGX_ERROR; |
509 | 1404 } |
1405 | |
573 | 1406 v->data = p; |
509 | 1407 |
573 | 1408 p = ngx_copy(p, r->headers_in.x_forwarded_for->value.data, |
1409 r->headers_in.x_forwarded_for->value.len); | |
509 | 1410 |
1411 *p++ = ','; *p++ = ' '; | |
1412 | |
1413 ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len); | |
1414 | |
573 | 1415 return NGX_OK; |
509 | 1416 } |
1417 | |
1418 | |
1419 static ngx_int_t | |
577 | 1420 ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r, |
1421 ngx_http_variable_value_t *v, uintptr_t data) | |
1422 { | |
1658 | 1423 ngx_http_proxy_ctx_t *ctx; |
1424 | |
1425 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1426 | |
1427 if (ctx == NULL) { | |
577 | 1428 v->not_found = 1; |
1429 return NGX_OK; | |
1430 } | |
1431 | |
1432 v->valid = 1; | |
1565 | 1433 v->no_cacheable = 0; |
577 | 1434 v->not_found = 0; |
1435 | |
2049 | 1436 v->data = ngx_pnalloc(r->connection->pool, NGX_SIZE_T_LEN); |
577 | 1437 |
1438 if (v->data == NULL) { | |
1439 return NGX_ERROR; | |
1440 } | |
1441 | |
1658 | 1442 v->len = ngx_sprintf(v->data, "%uz", ctx->internal_body_length) - v->data; |
577 | 1443 |
1444 return NGX_OK; | |
1445 } | |
1446 | |
1447 | |
1448 static ngx_int_t | |
509 | 1449 ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, ngx_table_elt_t *h, |
1450 size_t prefix) | |
1451 { | |
1452 ngx_int_t rc; | |
1453 ngx_uint_t i; | |
1454 ngx_http_proxy_loc_conf_t *plcf; | |
1455 ngx_http_proxy_redirect_t *pr; | |
1456 | |
1457 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
1458 | |
1459 pr = plcf->redirects->elts; | |
1460 | |
1461 if (pr == NULL) { | |
1462 return NGX_DECLINED; | |
1463 } | |
1464 | |
1465 for (i = 0; i < plcf->redirects->nelts; i++) { | |
605 | 1466 rc = pr[i].handler(r, h, prefix, &pr[i]); |
509 | 1467 |
1468 if (rc != NGX_DECLINED) { | |
1469 return rc; | |
1470 } | |
1471 } | |
1472 | |
1473 return NGX_DECLINED; | |
1474 } | |
1475 | |
1476 | |
1477 static ngx_int_t | |
1478 ngx_http_proxy_rewrite_redirect_text(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1479 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1480 { | |
1481 size_t len; | |
1482 u_char *data, *p; | |
1483 | |
1484 if (pr->redirect.len > h->value.len - prefix | |
1485 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1486 pr->redirect.len) != 0) | |
1487 { | |
1488 return NGX_DECLINED; | |
1489 } | |
1490 | |
1491 len = prefix + pr->replacement.text.len + h->value.len - pr->redirect.len; | |
507 | 1492 |
2049 | 1493 data = ngx_pnalloc(r->pool, len); |
509 | 1494 if (data == NULL) { |
1495 return NGX_ERROR; | |
1496 } | |
1497 | |
1498 p = data; | |
1499 | |
573 | 1500 p = ngx_copy(p, h->value.data, prefix); |
509 | 1501 |
653 | 1502 if (pr->replacement.text.len) { |
1503 p = ngx_copy(p, pr->replacement.text.data, pr->replacement.text.len); | |
1504 } | |
509 | 1505 |
1506 ngx_memcpy(p, h->value.data + prefix + pr->redirect.len, | |
1507 h->value.len - pr->redirect.len - prefix); | |
1508 | |
1509 h->value.len = len; | |
1510 h->value.data = data; | |
1511 | |
1512 return NGX_OK; | |
1513 } | |
1514 | |
1515 | |
1516 static ngx_int_t | |
1517 ngx_http_proxy_rewrite_redirect_vars(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1518 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1519 { | |
1520 size_t len; | |
1521 u_char *data, *p; | |
1522 ngx_http_script_code_pt code; | |
1523 ngx_http_script_engine_t e; | |
1524 ngx_http_script_len_code_pt lcode; | |
1525 | |
1526 if (pr->redirect.len > h->value.len - prefix | |
1527 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1528 pr->redirect.len) != 0) | |
1529 { | |
1530 return NGX_DECLINED; | |
1531 } | |
1532 | |
1533 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
1534 | |
1535 e.ip = pr->replacement.vars.lengths; | |
1536 e.request = r; | |
1537 | |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1538 len = prefix + h->value.len - pr->redirect.len; |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1539 |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1540 while (*(uintptr_t *) e.ip) { |
509 | 1541 lcode = *(ngx_http_script_len_code_pt *) e.ip; |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1542 len += lcode(&e); |
509 | 1543 } |
1544 | |
2049 | 1545 data = ngx_pnalloc(r->pool, len); |
509 | 1546 if (data == NULL) { |
1547 return NGX_ERROR; | |
1548 } | |
1549 | |
1550 p = data; | |
1551 | |
573 | 1552 p = ngx_copy(p, h->value.data, prefix); |
509 | 1553 |
1554 e.ip = pr->replacement.vars.values; | |
1555 e.pos = p; | |
1556 | |
1557 while (*(uintptr_t *) e.ip) { | |
1558 code = *(ngx_http_script_code_pt *) e.ip; | |
1559 code(&e); | |
1560 } | |
1561 | |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1562 ngx_memcpy(e.pos, h->value.data + prefix + pr->redirect.len, |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1563 h->value.len - pr->redirect.len - prefix); |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1564 |
509 | 1565 h->value.len = len; |
1566 h->value.data = data; | |
1567 | |
1568 return NGX_OK; | |
1569 } | |
1570 | |
1571 | |
1572 static ngx_int_t | |
1573 ngx_http_proxy_add_variables(ngx_conf_t *cf) | |
1574 { | |
1575 ngx_http_variable_t *var, *v; | |
1576 | |
1577 for (v = ngx_http_proxy_vars; v->name.len; v++) { | |
1578 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
1579 if (var == NULL) { | |
1580 return NGX_ERROR; | |
1581 } | |
1582 | |
637 | 1583 var->get_handler = v->get_handler; |
509 | 1584 var->data = v->data; |
1585 } | |
1586 | |
1587 return NGX_OK; | |
507 | 1588 } |
1589 | |
1590 | |
1591 static void * | |
1592 ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) | |
1593 { | |
1594 ngx_http_proxy_loc_conf_t *conf; | |
1595 | |
1596 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)); | |
1597 if (conf == NULL) { | |
1598 return NGX_CONF_ERROR; | |
1599 } | |
1600 | |
1601 /* | |
1602 * set by ngx_pcalloc(): | |
1603 * | |
1604 * conf->upstream.bufs.num = 0; | |
1605 * conf->upstream.next_upstream = 0; | |
1606 * conf->upstream.temp_path = NULL; | |
649 | 1607 * conf->upstream.hide_headers_hash = { NULL, 0 }; |
509 | 1608 * conf->upstream.schema = { 0, NULL }; |
1609 * conf->upstream.uri = { 0, NULL }; | |
1610 * conf->upstream.location = NULL; | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1611 * conf->upstream.store_lengths = NULL; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1612 * conf->upstream.store_values = NULL; |
509 | 1613 * |
561 | 1614 * conf->method = NULL; |
509 | 1615 * conf->headers_source = NULL; |
1616 * conf->headers_set_len = NULL; | |
1617 * conf->headers_set = NULL; | |
1618 * conf->headers_set_hash = NULL; | |
577 | 1619 * conf->body_set_len = NULL; |
1620 * conf->body_set = NULL; | |
1621 * conf->body_source = { 0, NULL }; | |
509 | 1622 * conf->rewrite_locations = NULL; |
507 | 1623 */ |
577 | 1624 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1625 conf->upstream.store = NGX_CONF_UNSET; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1626 conf->upstream.store_access = NGX_CONF_UNSET_UINT; |
581 | 1627 conf->upstream.buffering = NGX_CONF_UNSET; |
629 | 1628 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; |
581 | 1629 |
507 | 1630 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
1631 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
1632 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
1633 | |
1634 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | |
581 | 1635 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; |
529 | 1636 |
1637 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | |
577 | 1638 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; |
529 | 1639 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; |
509 | 1640 |
1641 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1642 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
561 | 1643 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1644 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:
1699
diff
changeset
|
1645 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:
1699
diff
changeset
|
1646 |
657 | 1647 conf->upstream.intercept_errors = NGX_CONF_UNSET; |
507 | 1648 |
1649 /* "proxy_cyclic_temp_file" is disabled */ | |
1650 conf->upstream.cyclic_temp_file = 0; | |
1651 | |
509 | 1652 conf->redirect = NGX_CONF_UNSET; |
649 | 1653 conf->upstream.change_buffering = 1; |
507 | 1654 |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1655 conf->headers_hash_max_size = NGX_CONF_UNSET_UINT; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1656 conf->headers_hash_bucket_size = NGX_CONF_UNSET_UINT; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1657 |
507 | 1658 return conf; |
1659 } | |
1660 | |
1661 | |
1662 static char * | |
1663 ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
1664 { | |
1665 ngx_http_proxy_loc_conf_t *prev = parent; | |
1666 ngx_http_proxy_loc_conf_t *conf = child; | |
1667 | |
509 | 1668 u_char *p; |
1669 size_t size; | |
1670 uintptr_t *code; | |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1671 ngx_uint_t i; |
649 | 1672 ngx_keyval_t *src, *s, *h; |
1673 ngx_hash_key_t *hk; | |
1674 ngx_hash_init_t hash; | |
509 | 1675 ngx_http_proxy_redirect_t *pr; |
1676 ngx_http_script_compile_t sc; | |
1677 ngx_http_script_copy_code_t *copy; | |
1678 | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1679 if (conf->upstream.store != 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1680 ngx_conf_merge_value(conf->upstream.store, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1681 prev->upstream.store, 0); |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1682 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1683 if (conf->upstream.store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1684 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
|
1685 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
|
1686 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1687 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1688 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1689 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
|
1690 prev->upstream.store_access, 0600); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
1691 |
581 | 1692 ngx_conf_merge_value(conf->upstream.buffering, |
1693 prev->upstream.buffering, 1); | |
1694 | |
629 | 1695 ngx_conf_merge_value(conf->upstream.ignore_client_abort, |
1696 prev->upstream.ignore_client_abort, 0); | |
1697 | |
507 | 1698 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
1699 prev->upstream.connect_timeout, 60000); | |
1700 | |
1701 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1702 prev->upstream.send_timeout, 60000); | |
1703 | |
1704 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1705 prev->upstream.read_timeout, 60000); | |
1706 | |
1707 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1708 prev->upstream.send_lowat, 0); | |
1709 | |
581 | 1710 ngx_conf_merge_size_value(conf->upstream.buffer_size, |
1711 prev->upstream.buffer_size, | |
507 | 1712 (size_t) ngx_pagesize); |
1713 | |
1714 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1715 8, ngx_pagesize); | |
1716 | |
1717 if (conf->upstream.bufs.num < 2) { | |
577 | 1718 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
507 | 1719 "there must be at least 2 \"proxy_buffers\""); |
1720 return NGX_CONF_ERROR; | |
1721 } | |
577 | 1722 |
507 | 1723 |
581 | 1724 size = conf->upstream.buffer_size; |
577 | 1725 if (size < conf->upstream.bufs.size) { |
507 | 1726 size = conf->upstream.bufs.size; |
1727 } | |
1728 | |
1729 | |
529 | 1730 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, |
1731 prev->upstream.busy_buffers_size_conf, | |
507 | 1732 NGX_CONF_UNSET_SIZE); |
1733 | |
529 | 1734 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1735 conf->upstream.busy_buffers_size = 2 * size; |
529 | 1736 } else { |
1737 conf->upstream.busy_buffers_size = | |
1738 conf->upstream.busy_buffers_size_conf; | |
1739 } | |
577 | 1740 |
529 | 1741 if (conf->upstream.busy_buffers_size < size) { |
507 | 1742 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1743 "\"proxy_busy_buffers_size\" must be equal or bigger than " | |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
1744 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1745 "one of the \"proxy_buffers\""); |
1746 | |
1747 return NGX_CONF_ERROR; | |
529 | 1748 } |
507 | 1749 |
529 | 1750 if (conf->upstream.busy_buffers_size |
1751 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
507 | 1752 { |
1753 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1754 "\"proxy_busy_buffers_size\" must be less than " | |
1755 "the size of all \"proxy_buffers\" minus one buffer"); | |
1756 | |
1757 return NGX_CONF_ERROR; | |
1758 } | |
529 | 1759 |
507 | 1760 |
529 | 1761 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, |
1762 prev->upstream.temp_file_write_size_conf, | |
507 | 1763 NGX_CONF_UNSET_SIZE); |
1764 | |
529 | 1765 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1766 conf->upstream.temp_file_write_size = 2 * size; |
529 | 1767 } else { |
1768 conf->upstream.temp_file_write_size = | |
1769 conf->upstream.temp_file_write_size_conf; | |
1770 } | |
577 | 1771 |
529 | 1772 if (conf->upstream.temp_file_write_size < size) { |
507 | 1773 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1774 "\"proxy_temp_file_write_size\" must be equal or bigger than " | |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
1775 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1776 "one of the \"proxy_buffers\""); |
1777 | |
1778 return NGX_CONF_ERROR; | |
1779 } | |
1780 | |
529 | 1781 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, |
1782 prev->upstream.max_temp_file_size_conf, | |
507 | 1783 NGX_CONF_UNSET_SIZE); |
1784 | |
529 | 1785 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1786 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; |
529 | 1787 } else { |
1788 conf->upstream.max_temp_file_size = | |
1789 conf->upstream.max_temp_file_size_conf; | |
1790 } | |
507 | 1791 |
529 | 1792 if (conf->upstream.max_temp_file_size != 0 |
1793 && conf->upstream.max_temp_file_size < size) | |
507 | 1794 { |
1795 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
561 | 1796 "\"proxy_max_temp_file_size\" must be equal to zero to disable " |
507 | 1797 "the temporary files usage or must be equal or bigger than " |
1125
2d978e1443ed
use the contemporary directives
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
1798 "maximum of the value of \"proxy_buffer_size\" and " |
561 | 1799 "one of the \"proxy_buffers\""); |
507 | 1800 |
1801 return NGX_CONF_ERROR; | |
1802 } | |
1803 | |
529 | 1804 |
507 | 1805 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, |
1806 prev->upstream.next_upstream, | |
1807 (NGX_CONF_BITMASK_SET | |
1808 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1809 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1810 | |
665 | 1811 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { |
1812 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1813 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1814 } | |
1815 | |
509 | 1816 ngx_conf_merge_path_value(conf->upstream.temp_path, |
1817 prev->upstream.temp_path, | |
1818 NGX_HTTP_PROXY_TEMP_PATH, 1, 2, 0, | |
1819 ngx_garbage_collector_temp_handler, cf); | |
507 | 1820 |
561 | 1821 if (conf->method.len == 0) { |
1822 conf->method = prev->method; | |
1823 | |
1824 } else { | |
1825 conf->method.data[conf->method.len] = ' '; | |
1826 conf->method.len++; | |
509 | 1827 } |
1828 | |
1829 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1830 prev->upstream.pass_request_headers, 1); | |
1831 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1832 prev->upstream.pass_request_body, 1); | |
1833 | |
657 | 1834 ngx_conf_merge_value(conf->upstream.intercept_errors, |
1835 prev->upstream.intercept_errors, 0); | |
509 | 1836 |
1837 ngx_conf_merge_value(conf->redirect, prev->redirect, 1); | |
1838 | |
1839 if (conf->redirect) { | |
507 | 1840 |
509 | 1841 if (conf->redirects == NULL) { |
1842 conf->redirects = prev->redirects; | |
1843 } | |
1844 | |
1658 | 1845 if (conf->redirects == NULL && conf->url.data) { |
509 | 1846 |
1847 conf->redirects = ngx_array_create(cf->pool, 1, | |
1848 sizeof(ngx_http_proxy_redirect_t)); | |
1849 if (conf->redirects == NULL) { | |
1850 return NGX_CONF_ERROR; | |
1851 } | |
1852 | |
1853 pr = ngx_array_push(conf->redirects); | |
1854 if (pr == NULL) { | |
1855 return NGX_CONF_ERROR; | |
1856 } | |
1857 | |
1858 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 1859 pr->redirect = conf->url; |
1860 | |
1861 if (conf->vars.uri.len) { | |
1862 pr->replacement.text = conf->location; | |
653 | 1863 |
1864 } else { | |
1865 pr->replacement.text.len = 0; | |
1866 pr->replacement.text.data = NULL; | |
1867 } | |
509 | 1868 } |
1869 } | |
1870 | |
1658 | 1871 /* STUB */ |
1872 if (prev->proxy_lengths) { | |
1873 conf->proxy_lengths = prev->proxy_lengths; | |
1874 conf->proxy_values = prev->proxy_values; | |
1875 } | |
1876 | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1877 ngx_conf_merge_uint_value(conf->headers_hash_max_size, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1878 prev->headers_hash_max_size, 512); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1879 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1880 ngx_conf_merge_uint_value(conf->headers_hash_bucket_size, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1881 prev->headers_hash_bucket_size, 64); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1882 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1883 conf->headers_hash_bucket_size = ngx_align(conf->headers_hash_bucket_size, |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1884 ngx_cacheline_size); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1885 |
1701
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1886 hash.max_size = conf->headers_hash_max_size; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1887 hash.bucket_size = conf->headers_hash_bucket_size; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1888 hash.name = "proxy_headers_hash"; |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1889 |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1890 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:
1699
diff
changeset
|
1891 &prev->upstream, |
40d004d95d88
*) now ngx_conf_set_str_array_slot() tests NGX_CONF_UNSET_PTR
Igor Sysoev <igor@sysoev.ru>
parents:
1699
diff
changeset
|
1892 ngx_http_proxy_hide_headers, &hash) |
649 | 1893 != NGX_OK) |
1894 { | |
1895 return NGX_CONF_ERROR; | |
1896 } | |
1897 | |
884 | 1898 if (conf->upstream.upstream == NULL) { |
1899 conf->upstream.upstream = prev->upstream.upstream; | |
629 | 1900 |
1658 | 1901 conf->vars = prev->vars; |
629 | 1902 conf->upstream.schema = prev->upstream.schema; |
507 | 1903 } |
1904 | |
577 | 1905 |
1906 if (conf->body_source.data == NULL) { | |
1907 conf->body_source = prev->body_source; | |
1908 conf->body_set_len = prev->body_set_len; | |
1909 conf->body_set = prev->body_set; | |
1910 } | |
1911 | |
579 | 1912 if (conf->body_source.data && conf->body_set_len == NULL) { |
577 | 1913 |
1914 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1915 | |
1916 sc.cf = cf; | |
1917 sc.source = &conf->body_source; | |
1918 sc.flushes = &conf->flushes; | |
1919 sc.lengths = &conf->body_set_len; | |
1920 sc.values = &conf->body_set; | |
1921 sc.complete_lengths = 1; | |
1922 sc.complete_values = 1; | |
1923 | |
1924 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1925 return NGX_CONF_ERROR; | |
1926 } | |
1927 | |
1928 if (conf->headers_source == NULL) { | |
1929 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 1930 sizeof(ngx_keyval_t)); |
577 | 1931 if (conf->headers_source == NULL) { |
1932 return NGX_CONF_ERROR; | |
1933 } | |
1934 } | |
1935 | |
1936 s = ngx_array_push(conf->headers_source); | |
1937 if (s == NULL) { | |
1938 return NGX_CONF_ERROR; | |
1939 } | |
1940 | |
1941 s->key.len = sizeof("Content-Length") - 1; | |
1942 s->key.data = (u_char *) "Content-Length"; | |
1943 s->value.len = sizeof("$proxy_internal_body_length") - 1; | |
1944 s->value.data = (u_char *) "$proxy_internal_body_length"; | |
1945 } | |
1946 | |
1947 | |
509 | 1948 if (conf->headers_source == NULL) { |
573 | 1949 conf->flushes = prev->flushes; |
507 | 1950 conf->headers_set_len = prev->headers_set_len; |
1951 conf->headers_set = prev->headers_set; | |
1952 conf->headers_set_hash = prev->headers_set_hash; | |
573 | 1953 conf->headers_source = prev->headers_source; |
507 | 1954 } |
1955 | |
649 | 1956 if (conf->headers_set_hash.buckets) { |
509 | 1957 return NGX_CONF_OK; |
1958 } | |
1959 | |
1960 | |
649 | 1961 conf->headers_names = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t)); |
509 | 1962 if (conf->headers_names == NULL) { |
1963 return NGX_CONF_ERROR; | |
1964 } | |
1965 | |
1966 if (conf->headers_source == NULL) { | |
1967 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 1968 sizeof(ngx_keyval_t)); |
509 | 1969 if (conf->headers_source == NULL) { |
1970 return NGX_CONF_ERROR; | |
1971 } | |
1972 } | |
507 | 1973 |
509 | 1974 conf->headers_set_len = ngx_array_create(cf->pool, 64, 1); |
1975 if (conf->headers_set_len == NULL) { | |
1976 return NGX_CONF_ERROR; | |
1977 } | |
1978 | |
1979 conf->headers_set = ngx_array_create(cf->pool, 512, 1); | |
1980 if (conf->headers_set == NULL) { | |
1981 return NGX_CONF_ERROR; | |
1982 } | |
1983 | |
1984 | |
1985 src = conf->headers_source->elts; | |
1986 | |
1987 for (h = ngx_http_proxy_headers; h->key.len; h++) { | |
1988 | |
1989 for (i = 0; i < conf->headers_source->nelts; i++) { | |
1990 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { | |
1991 goto next; | |
507 | 1992 } |
1993 } | |
1994 | |
509 | 1995 s = ngx_array_push(conf->headers_source); |
1996 if (s == NULL) { | |
507 | 1997 return NGX_CONF_ERROR; |
1998 } | |
1999 | |
509 | 2000 *s = *h; |
507 | 2001 |
517 | 2002 src = conf->headers_source->elts; |
2003 | |
509 | 2004 next: |
507 | 2005 |
509 | 2006 continue; |
2007 } | |
507 | 2008 |
577 | 2009 |
2010 src = conf->headers_source->elts; | |
509 | 2011 for (i = 0; i < conf->headers_source->nelts; i++) { |
507 | 2012 |
649 | 2013 hk = ngx_array_push(conf->headers_names); |
2014 if (hk == NULL) { | |
507 | 2015 return NGX_CONF_ERROR; |
2016 } | |
2017 | |
649 | 2018 hk->key = src[i].key; |
2019 hk->key_hash = ngx_hash_key_lc(src[i].key.data, src[i].key.len); | |
2020 hk->value = (void *) 1; | |
509 | 2021 |
519 | 2022 if (src[i].value.len == 0) { |
2023 continue; | |
2024 } | |
2025 | |
509 | 2026 if (ngx_http_script_variables_count(&src[i].value) == 0) { |
2027 copy = ngx_array_push_n(conf->headers_set_len, | |
2028 sizeof(ngx_http_script_copy_code_t)); | |
2029 if (copy == NULL) { | |
2030 return NGX_CONF_ERROR; | |
2031 } | |
2032 | |
2033 copy->code = (ngx_http_script_code_pt) | |
2034 ngx_http_script_copy_len_code; | |
2035 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2036 + src[i].value.len + sizeof(CRLF) - 1; | |
507 | 2037 |
2038 | |
509 | 2039 size = (sizeof(ngx_http_script_copy_code_t) |
2040 + src[i].key.len + sizeof(": ") - 1 | |
2041 + src[i].value.len + sizeof(CRLF) - 1 | |
2042 + sizeof(uintptr_t) - 1) | |
2043 & ~(sizeof(uintptr_t) - 1); | |
2044 | |
2045 copy = ngx_array_push_n(conf->headers_set, size); | |
2046 if (copy == NULL) { | |
2047 return NGX_CONF_ERROR; | |
2048 } | |
2049 | |
2050 copy->code = ngx_http_script_copy_code; | |
2051 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2052 + src[i].value.len + sizeof(CRLF) - 1; | |
2053 | |
2054 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2055 | |
2056 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2057 *p++ = ':'; *p++ = ' '; | |
2058 p = ngx_cpymem(p, src[i].value.data, src[i].value.len); | |
2059 *p++ = CR; *p = LF; | |
2060 | |
2061 } else { | |
2062 copy = ngx_array_push_n(conf->headers_set_len, | |
2063 sizeof(ngx_http_script_copy_code_t)); | |
2064 if (copy == NULL) { | |
2065 return NGX_CONF_ERROR; | |
2066 } | |
2067 | |
2068 copy->code = (ngx_http_script_code_pt) | |
2069 ngx_http_script_copy_len_code; | |
2070 copy->len = src[i].key.len + sizeof(": ") - 1; | |
507 | 2071 |
2072 | |
509 | 2073 size = (sizeof(ngx_http_script_copy_code_t) |
2074 + src[i].key.len + sizeof(": ") - 1 + sizeof(uintptr_t) - 1) | |
2075 & ~(sizeof(uintptr_t) - 1); | |
2076 | |
2077 copy = ngx_array_push_n(conf->headers_set, size); | |
2078 if (copy == NULL) { | |
2079 return NGX_CONF_ERROR; | |
2080 } | |
2081 | |
2082 copy->code = ngx_http_script_copy_code; | |
2083 copy->len = src[i].key.len + sizeof(": ") - 1; | |
2084 | |
2085 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2086 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2087 *p++ = ':'; *p = ' '; | |
2088 | |
2089 | |
2090 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2091 | |
2092 sc.cf = cf; | |
2093 sc.source = &src[i].value; | |
573 | 2094 sc.flushes = &conf->flushes; |
509 | 2095 sc.lengths = &conf->headers_set_len; |
2096 sc.values = &conf->headers_set; | |
2097 | |
2098 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2099 return NGX_CONF_ERROR; | |
2100 } | |
2101 | |
2102 | |
2103 copy = ngx_array_push_n(conf->headers_set_len, | |
2104 sizeof(ngx_http_script_copy_code_t)); | |
2105 if (copy == NULL) { | |
2106 return NGX_CONF_ERROR; | |
2107 } | |
2108 | |
2109 copy->code = (ngx_http_script_code_pt) | |
2110 ngx_http_script_copy_len_code; | |
2111 copy->len = sizeof(CRLF) - 1; | |
2112 | |
2113 | |
2114 size = (sizeof(ngx_http_script_copy_code_t) | |
2115 + sizeof(CRLF) - 1 + sizeof(uintptr_t) - 1) | |
2116 & ~(sizeof(uintptr_t) - 1); | |
2117 | |
2118 copy = ngx_array_push_n(conf->headers_set, size); | |
2119 if (copy == NULL) { | |
2120 return NGX_CONF_ERROR; | |
2121 } | |
2122 | |
2123 copy->code = ngx_http_script_copy_code; | |
2124 copy->len = sizeof(CRLF) - 1; | |
2125 | |
2126 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2127 *p++ = CR; *p = LF; | |
507 | 2128 } |
2129 | |
509 | 2130 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2131 if (code == NULL) { | |
507 | 2132 return NGX_CONF_ERROR; |
2133 } | |
2134 | |
509 | 2135 *code = (uintptr_t) NULL; |
2136 | |
2137 code = ngx_array_push_n(conf->headers_set, sizeof(uintptr_t)); | |
2138 if (code == NULL) { | |
2139 return NGX_CONF_ERROR; | |
2140 } | |
2141 | |
2142 *code = (uintptr_t) NULL; | |
507 | 2143 } |
2144 | |
509 | 2145 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2146 if (code == NULL) { | |
2147 return NGX_CONF_ERROR; | |
507 | 2148 } |
2149 | |
509 | 2150 *code = (uintptr_t) NULL; |
507 | 2151 |
2152 | |
649 | 2153 hash.hash = &conf->headers_set_hash; |
2154 hash.key = ngx_hash_key_lc; | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2155 hash.max_size = conf->headers_hash_max_size; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2156 hash.bucket_size = conf->headers_hash_bucket_size; |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
2157 hash.name = "proxy_headers_hash"; |
649 | 2158 hash.pool = cf->pool; |
2159 hash.temp_pool = NULL; | |
2160 | |
2161 if (ngx_hash_init(&hash, conf->headers_names->elts, | |
2162 conf->headers_names->nelts) | |
2163 != NGX_OK) | |
2164 { | |
2165 return NGX_CONF_ERROR; | |
2166 } | |
2167 | |
509 | 2168 return NGX_CONF_OK; |
507 | 2169 } |
2170 | |
2171 | |
2172 static char * | |
2173 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2174 { | |
509 | 2175 ngx_http_proxy_loc_conf_t *plcf = conf; |
507 | 2176 |
1658 | 2177 size_t add; |
2178 u_short port; | |
2179 ngx_str_t *value, *url; | |
2180 ngx_url_t u; | |
2181 ngx_uint_t n; | |
2182 ngx_http_core_loc_conf_t *clcf; | |
2183 ngx_http_script_compile_t sc; | |
507 | 2184 |
555 | 2185 if (plcf->upstream.schema.len) { |
2186 return "is duplicate"; | |
2187 } | |
2188 | |
1658 | 2189 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
2190 | |
507 | 2191 value = cf->args->elts; |
2192 | |
2193 url = &value[1]; | |
2194 | |
1658 | 2195 n = ngx_http_script_variables_count(url); |
2196 | |
2197 if (n) { | |
2198 | |
2199 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2200 | |
2201 sc.cf = cf; | |
2202 sc.source = url; | |
2203 sc.lengths = &plcf->proxy_lengths; | |
2204 sc.values = &plcf->proxy_values; | |
2205 sc.variables = n; | |
2206 sc.complete_lengths = 1; | |
2207 sc.complete_values = 1; | |
1679
ca317d9b5c09
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1671
diff
changeset
|
2208 |
1658 | 2209 if (ngx_http_script_compile(&sc) != NGX_OK) { |
2210 return NGX_CONF_ERROR; | |
2211 } | |
2212 | |
2213 #if (NGX_HTTP_SSL) | |
2214 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { | |
2215 return NGX_CONF_ERROR; | |
2216 } | |
2217 #endif | |
2218 | |
2219 clcf->handler = ngx_http_proxy_handler; | |
2220 | |
2221 return NGX_CONF_OK; | |
2222 } | |
2223 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2224 if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) { |
577 | 2225 add = 7; |
591 | 2226 port = 80; |
577 | 2227 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2228 } else if (ngx_strncasecmp(url->data, (u_char *) "https://", 8) == 0) { |
577 | 2229 |
2230 #if (NGX_HTTP_SSL) | |
1658 | 2231 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { |
2232 return NGX_CONF_ERROR; | |
2233 } | |
577 | 2234 |
2235 add = 8; | |
591 | 2236 port = 443; |
577 | 2237 #else |
2238 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2239 "https protocol requires SSL support"); | |
2240 return NGX_CONF_ERROR; | |
2241 #endif | |
2242 | |
2243 } else { | |
507 | 2244 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix"); |
2245 return NGX_CONF_ERROR; | |
2246 } | |
2247 | |
651 | 2248 ngx_memzero(&u, sizeof(ngx_url_t)); |
2249 | |
2250 u.url.len = url->len - add; | |
2251 u.url.data = url->data + add; | |
906 | 2252 u.default_port = port; |
2253 u.uri_part = 1; | |
884 | 2254 u.no_resolve = 1; |
2255 | |
2256 plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); | |
2257 if (plcf->upstream.upstream == NULL) { | |
507 | 2258 return NGX_CONF_ERROR; |
2259 } | |
2260 | |
1658 | 2261 if (ngx_http_proxy_set_vars(cf->pool, &u, &plcf->vars) != NGX_OK) { |
2262 return NGX_CONF_ERROR; | |
906 | 2263 } |
2264 | |
591 | 2265 plcf->upstream.schema.len = add; |
2266 plcf->upstream.schema.data = url->data; | |
1658 | 2267 plcf->location = clcf->name; |
507 | 2268 |
2269 clcf->handler = ngx_http_proxy_handler; | |
2270 | |
1353 | 2271 if (clcf->named |
507 | 2272 #if (NGX_PCRE) |
1353 | 2273 || clcf->regex |
2274 #endif | |
2275 || clcf->noname) | |
2276 { | |
1658 | 2277 if (plcf->vars.uri.len) { |
573 | 2278 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2279 "\"proxy_pass\" may not have URI part in " | |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2280 "location given by regular expression, " |
1353 | 2281 "or inside named location, " |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2282 "or inside the \"if\" statement, " |
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2283 "or inside the \"limit_except\" block"); |
573 | 2284 return NGX_CONF_ERROR; |
2285 } | |
2286 | |
1658 | 2287 plcf->location.len = 0; |
555 | 2288 } |
2289 | |
1658 | 2290 plcf->url = *url; |
509 | 2291 |
507 | 2292 if (clcf->name.data[clcf->name.len - 1] == '/') { |
2293 clcf->auto_redirect = 1; | |
2294 } | |
2295 | |
2296 return NGX_CONF_OK; | |
2297 } | |
2298 | |
2299 | |
2300 static char * | |
509 | 2301 ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
507 | 2302 { |
509 | 2303 ngx_http_proxy_loc_conf_t *plcf = conf; |
2304 | |
2305 ngx_str_t *value; | |
2306 ngx_array_t *vars_lengths, *vars_values; | |
2307 ngx_http_script_compile_t sc; | |
2308 ngx_http_proxy_redirect_t *pr; | |
2309 | |
2310 if (plcf->redirect == 0) { | |
2311 return NGX_CONF_OK; | |
2312 } | |
2313 | |
2314 value = cf->args->elts; | |
2315 | |
2316 if (ngx_strcmp(value[1].data, "off") == 0) { | |
2317 plcf->redirect = 0; | |
2318 plcf->redirects = NULL; | |
2319 return NGX_CONF_OK; | |
2320 } | |
2321 | |
2322 if (plcf->redirects == NULL) { | |
2323 plcf->redirects = ngx_array_create(cf->pool, 1, | |
2324 sizeof(ngx_http_proxy_redirect_t)); | |
2325 if (plcf->redirects == NULL) { | |
2326 return NGX_CONF_ERROR; | |
2327 } | |
2328 } | |
2329 | |
2330 pr = ngx_array_push(plcf->redirects); | |
2331 if (pr == NULL) { | |
2332 return NGX_CONF_ERROR; | |
2333 } | |
2334 | |
2335 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "default") == 0) { | |
1658 | 2336 if (plcf->url.data == NULL) { |
509 | 2337 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2338 "\"proxy_rewrite_location default\" must go " | |
2339 "after the \"proxy_pass\" directive"); | |
2340 return NGX_CONF_ERROR; | |
2341 } | |
2342 | |
2343 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 2344 pr->redirect = plcf->url; |
2345 | |
2346 if (plcf->vars.uri.len) { | |
2347 pr->replacement.text = plcf->location; | |
653 | 2348 |
2349 } else { | |
2350 pr->replacement.text.len = 0; | |
2351 pr->replacement.text.data = NULL; | |
2352 } | |
509 | 2353 |
2354 return NGX_CONF_OK; | |
2355 } | |
2356 | |
2357 if (ngx_http_script_variables_count(&value[2]) == 0) { | |
2358 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
2359 pr->redirect = value[1]; | |
2360 pr->replacement.text = value[2]; | |
2361 | |
2362 return NGX_CONF_OK; | |
2363 } | |
2364 | |
2365 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2366 | |
2367 vars_lengths = NULL; | |
2368 vars_values = NULL; | |
2369 | |
2370 sc.cf = cf; | |
2371 sc.source = &value[2]; | |
2372 sc.lengths = &vars_lengths; | |
2373 sc.values = &vars_values; | |
2374 sc.complete_lengths = 1; | |
2375 sc.complete_values = 1; | |
2376 | |
2377 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2378 return NGX_CONF_ERROR; | |
2379 } | |
2380 | |
2381 pr->handler = ngx_http_proxy_rewrite_redirect_vars; | |
2382 pr->redirect = value[1]; | |
2383 pr->replacement.vars.lengths = vars_lengths->elts; | |
2384 pr->replacement.vars.values = vars_values->elts; | |
2385 | |
507 | 2386 return NGX_CONF_OK; |
2387 } | |
2388 | |
2389 | |
2390 static char * | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2391 ngx_http_proxy_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
|
2392 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2393 ngx_http_proxy_loc_conf_t *plcf = conf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2394 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2395 ngx_str_t *value; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2396 ngx_http_script_compile_t sc; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2397 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2398 if (plcf->upstream.store != NGX_CONF_UNSET || plcf->upstream.store_lengths) |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2399 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2400 return "is duplicate"; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2401 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2402 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2403 value = cf->args->elts; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2404 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2405 if (ngx_strcmp(value[1].data, "on") == 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2406 plcf->upstream.store = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2407 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2408 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2409 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2410 if (ngx_strcmp(value[1].data, "off") == 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2411 plcf->upstream.store = 0; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2412 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2413 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2414 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2415 /* include the terminating '\0' into script */ |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2416 value[1].len++; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2417 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2418 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
|
2419 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2420 sc.cf = cf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2421 sc.source = &value[1]; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2422 sc.lengths = &plcf->upstream.store_lengths; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2423 sc.values = &plcf->upstream.store_values; |
1563
022ec9420f80
style fix: remove double semicolons
Igor Sysoev <igor@sysoev.ru>
parents:
1488
diff
changeset
|
2424 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
|
2425 sc.complete_lengths = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2426 sc.complete_values = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2427 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2428 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
|
2429 return NGX_CONF_ERROR; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2430 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2431 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2432 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2433 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2434 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2435 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2436 static char * |
507 | 2437 ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data) |
2438 { | |
2439 #if (NGX_FREEBSD) | |
2440 ssize_t *np = data; | |
2441 | |
673 | 2442 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) { |
507 | 2443 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2444 "\"proxy_send_lowat\" must be less than %d " | |
2445 "(sysctl net.inet.tcp.sendspace)", | |
2446 ngx_freebsd_net_inet_tcp_sendspace); | |
2447 | |
2448 return NGX_CONF_ERROR; | |
2449 } | |
2450 | |
2451 #elif !(NGX_HAVE_SO_SNDLOWAT) | |
2452 ssize_t *np = data; | |
2453 | |
2454 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2455 "\"proxy_send_lowat\" is not supported, ignored"); | |
2456 | |
2457 *np = 0; | |
2458 | |
2459 #endif | |
2460 | |
2461 return NGX_CONF_OK; | |
2462 } | |
884 | 2463 |
2464 | |
2465 static char * | |
2466 ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, | |
2467 ngx_command_t *cmd, void *conf) | |
2468 { | |
2469 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2470 "\"proxy_upstream_max_fails\" is not supported, " | |
2471 "use the \"max_fails\" parameter of the \"server\" directive ", | |
2472 "inside the \"upstream\" block"); | |
2473 | |
2474 return NGX_CONF_ERROR; | |
2475 } | |
2476 | |
2477 | |
2478 static char * | |
2479 ngx_http_proxy_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
2480 ngx_command_t *cmd, void *conf) | |
2481 { | |
2482 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2483 "\"proxy_upstream_fail_timeout\" is not supported, " | |
2484 "use the \"fail_timeout\" parameter of the \"server\" directive ", | |
2485 "inside the \"upstream\" block"); | |
2486 | |
2487 return NGX_CONF_ERROR; | |
2488 } | |
1658 | 2489 |
2490 | |
2491 #if (NGX_HTTP_SSL) | |
2492 | |
2493 static ngx_int_t | |
2494 ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf) | |
2495 { | |
2496 ngx_pool_cleanup_t *cln; | |
2497 | |
2498 plcf->upstream.ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); | |
2499 if (plcf->upstream.ssl == NULL) { | |
2500 return NGX_ERROR; | |
2501 } | |
2502 | |
2503 plcf->upstream.ssl->log = cf->log; | |
2504 | |
2505 if (ngx_ssl_create(plcf->upstream.ssl, | |
2506 NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1, NULL) | |
2507 != NGX_OK) | |
2508 { | |
2509 return NGX_ERROR; | |
2510 } | |
2511 | |
2512 cln = ngx_pool_cleanup_add(cf->pool, 0); | |
2513 if (cln == NULL) { | |
2514 return NGX_ERROR; | |
2515 } | |
2516 | |
2517 cln->handler = ngx_ssl_cleanup_ctx; | |
2518 cln->data = plcf->upstream.ssl; | |
2519 | |
2520 return NGX_OK; | |
2521 } | |
2522 | |
2523 #endif | |
2524 | |
2525 | |
2526 static ngx_int_t | |
2527 ngx_http_proxy_set_vars(ngx_pool_t *pool, ngx_url_t *u, | |
2528 ngx_http_proxy_vars_t *v) | |
2529 { | |
2530 if (!u->unix_socket) { | |
2531 if (u->no_port || u->port == u->default_port) { | |
2532 v->host_header = u->host; | |
2533 | |
2534 if (u->default_port == 80) { | |
2535 v->port.len = sizeof("80") - 1; | |
2536 v->port.data = (u_char *) "80"; | |
2537 | |
2538 } else { | |
2539 v->port.len = sizeof("443") - 1; | |
2540 v->port.data = (u_char *) "443"; | |
2541 } | |
2542 | |
2543 } else { | |
1671
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1667
diff
changeset
|
2544 v->host_header.len = u->host.len + 1 + u->port_text.len; |
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1667
diff
changeset
|
2545 v->host_header.data = u->host.data; |
8075179cae21
ngx_parse_url() saves port text, this allows to use it in proxy host header
Igor Sysoev <igor@sysoev.ru>
parents:
1667
diff
changeset
|
2546 v->port = u->port_text; |
1658 | 2547 } |
2548 | |
2549 } else { | |
2550 v->host_header.len = sizeof("localhost") - 1; | |
2551 v->host_header.data = (u_char *) "localhost"; | |
2552 v->port.len = 0; | |
2553 v->port.data = (u_char *) ""; | |
2554 } | |
2555 | |
2556 v->uri = u->uri; | |
2557 | |
2558 return NGX_OK; | |
2559 } |