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