Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_proxy_module.c @ 1679:ca317d9b5c09
style fix: remove trailing spaces
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 01 Dec 2007 19:57:37 +0000 |
parents | 8075179cae21 |
children | bd85a95d60c6 |
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 | |
509 | 678 len += r->uri.len - loc_len + escape + sizeof("?") - 1 + r->args.len; |
507 | 679 } |
680 | |
1565 | 681 ngx_http_script_flush_no_cacheable_variables(r, plcf->flushes); |
573 | 682 |
577 | 683 if (plcf->body_set_len) { |
684 le.ip = plcf->body_set_len->elts; | |
685 le.request = r; | |
686 le.flushed = 1; | |
687 body_len = 0; | |
688 | |
689 while (*(uintptr_t *) le.ip) { | |
690 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
691 body_len += lcode(&le); | |
692 } | |
693 | |
1658 | 694 ctx->internal_body_length = body_len; |
577 | 695 len += body_len; |
696 } | |
697 | |
509 | 698 le.ip = plcf->headers_set_len->elts; |
699 le.request = r; | |
573 | 700 le.flushed = 1; |
507 | 701 |
509 | 702 while (*(uintptr_t *) le.ip) { |
703 while (*(uintptr_t *) le.ip) { | |
704 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
705 len += lcode(&le); | |
706 } | |
707 le.ip += sizeof(uintptr_t); | |
507 | 708 } |
709 | |
710 | |
509 | 711 if (plcf->upstream.pass_request_headers) { |
712 part = &r->headers_in.headers.part; | |
713 header = part->elts; | |
714 | |
715 for (i = 0; /* void */; i++) { | |
507 | 716 |
509 | 717 if (i >= part->nelts) { |
718 if (part->next == NULL) { | |
719 break; | |
720 } | |
721 | |
722 part = part->next; | |
723 header = part->elts; | |
577 | 724 i = 0; |
507 | 725 } |
726 | |
649 | 727 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
728 header[i].lowcase_key, header[i].key.len)) | |
509 | 729 { |
730 continue; | |
731 } | |
732 | |
733 len += header[i].key.len + sizeof(": ") - 1 | |
734 + header[i].value.len + sizeof(CRLF) - 1; | |
507 | 735 } |
509 | 736 } |
507 | 737 |
738 | |
739 b = ngx_create_temp_buf(r->pool, len); | |
740 if (b == NULL) { | |
741 return NGX_ERROR; | |
742 } | |
743 | |
744 cl = ngx_alloc_chain_link(r->pool); | |
745 if (cl == NULL) { | |
746 return NGX_ERROR; | |
747 } | |
748 | |
749 cl->buf = b; | |
750 | |
751 | |
752 /* the request line */ | |
753 | |
573 | 754 b->last = ngx_copy(b->last, method.data, method.len); |
507 | 755 |
555 | 756 u->uri.data = b->last; |
757 | |
1658 | 758 if (plcf->proxy_lengths) { |
759 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); | |
760 | |
761 } else if (unparsed_uri) { | |
573 | 762 b->last = ngx_copy(b->last, r->unparsed_uri.data, r->unparsed_uri.len); |
763 | |
507 | 764 } else { |
555 | 765 if (r->valid_location) { |
1658 | 766 b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len); |
555 | 767 } |
551 | 768 |
507 | 769 if (escape) { |
509 | 770 ngx_escape_uri(b->last, r->uri.data + loc_len, |
771 r->uri.len - loc_len, NGX_ESCAPE_URI); | |
772 b->last += r->uri.len - loc_len + escape; | |
507 | 773 |
577 | 774 } else { |
573 | 775 b->last = ngx_copy(b->last, r->uri.data + loc_len, |
776 r->uri.len - loc_len); | |
507 | 777 } |
778 | |
779 if (r->args.len > 0) { | |
780 *b->last++ = '?'; | |
573 | 781 b->last = ngx_copy(b->last, r->args.data, r->args.len); |
507 | 782 } |
783 } | |
784 | |
555 | 785 u->uri.len = b->last - u->uri.data; |
786 | |
507 | 787 b->last = ngx_cpymem(b->last, ngx_http_proxy_version, |
788 sizeof(ngx_http_proxy_version) - 1); | |
789 | |
577 | 790 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
507 | 791 |
792 e.ip = plcf->headers_set->elts; | |
793 e.pos = b->last; | |
509 | 794 e.request = r; |
573 | 795 e.flushed = 1; |
507 | 796 |
509 | 797 le.ip = plcf->headers_set_len->elts; |
798 | |
799 while (*(uintptr_t *) le.ip) { | |
800 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
515 | 801 |
802 /* skip the header line name length */ | |
803 (void) lcode(&le); | |
509 | 804 |
805 if (*(ngx_http_script_len_code_pt *) le.ip) { | |
806 | |
807 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
808 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
809 } | |
810 | |
811 e.skip = (len == sizeof(CRLF) - 1) ? 1 : 0; | |
812 | |
813 } else { | |
814 e.skip = 0; | |
815 } | |
816 | |
817 le.ip += sizeof(uintptr_t); | |
818 | |
819 while (*(uintptr_t *) e.ip) { | |
820 code = *(ngx_http_script_code_pt *) e.ip; | |
821 code((ngx_http_script_engine_t *) &e); | |
577 | 822 } |
509 | 823 e.ip += sizeof(uintptr_t); |
507 | 824 } |
825 | |
826 b->last = e.pos; | |
827 | |
828 | |
509 | 829 if (plcf->upstream.pass_request_headers) { |
830 part = &r->headers_in.headers.part; | |
831 header = part->elts; | |
577 | 832 |
509 | 833 for (i = 0; /* void */; i++) { |
507 | 834 |
509 | 835 if (i >= part->nelts) { |
836 if (part->next == NULL) { | |
837 break; | |
838 } | |
839 | |
840 part = part->next; | |
841 header = part->elts; | |
577 | 842 i = 0; |
507 | 843 } |
844 | |
649 | 845 if (ngx_hash_find(&plcf->headers_set_hash, header[i].hash, |
846 header[i].lowcase_key, header[i].key.len)) | |
509 | 847 { |
848 continue; | |
849 } | |
507 | 850 |
573 | 851 b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len); |
507 | 852 |
509 | 853 *b->last++ = ':'; *b->last++ = ' '; |
507 | 854 |
573 | 855 b->last = ngx_copy(b->last, header[i].value.data, |
856 header[i].value.len); | |
507 | 857 |
509 | 858 *b->last++ = CR; *b->last++ = LF; |
507 | 859 |
509 | 860 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
861 "http proxy header: \"%V: %V\"", | |
862 &header[i].key, &header[i].value); | |
863 } | |
507 | 864 } |
865 | |
577 | 866 |
507 | 867 /* add "\r\n" at the header end */ |
868 *b->last++ = CR; *b->last++ = LF; | |
869 | |
577 | 870 if (plcf->body_set) { |
871 e.ip = plcf->body_set->elts; | |
872 e.pos = b->last; | |
873 | |
874 while (*(uintptr_t *) e.ip) { | |
875 code = *(ngx_http_script_code_pt *) e.ip; | |
876 code((ngx_http_script_engine_t *) &e); | |
877 } | |
579 | 878 |
879 b->last = e.pos; | |
577 | 880 } |
881 | |
507 | 882 #if (NGX_DEBUG) |
883 { | |
884 ngx_str_t s; | |
885 | |
886 s.len = b->last - b->pos; | |
887 s.data = b->pos; | |
888 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
889 "http proxy header:\n\"%V\"", &s); | |
890 } | |
891 #endif | |
892 | |
577 | 893 if (plcf->body_set == NULL && plcf->upstream.pass_request_body) { |
509 | 894 |
895 body = u->request_bufs; | |
896 u->request_bufs = cl; | |
897 | |
898 while (body) { | |
899 b = ngx_alloc_buf(r->pool); | |
900 if (b == NULL) { | |
901 return NGX_ERROR; | |
902 } | |
903 | |
904 ngx_memcpy(b, body->buf, sizeof(ngx_buf_t)); | |
905 | |
906 cl->next = ngx_alloc_chain_link(r->pool); | |
907 if (cl->next == NULL) { | |
908 return NGX_ERROR; | |
909 } | |
910 | |
911 cl = cl->next; | |
912 cl->buf = b; | |
913 | |
914 body = body->next; | |
915 } | |
916 | |
611 | 917 b->flush = 1; |
918 | |
509 | 919 } else { |
920 u->request_bufs = cl; | |
921 } | |
922 | |
923 cl->next = NULL; | |
924 | |
507 | 925 return NGX_OK; |
926 } | |
927 | |
928 | |
929 static ngx_int_t | |
930 ngx_http_proxy_reinit_request(ngx_http_request_t *r) | |
931 { | |
1658 | 932 ngx_http_proxy_ctx_t *ctx; |
933 | |
934 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
935 | |
936 if (ctx == NULL) { | |
509 | 937 return NGX_OK; |
938 } | |
939 | |
1658 | 940 ctx->status = 0; |
941 ctx->status_count = 0; | |
942 ctx->status_start = NULL; | |
943 ctx->status_end = NULL; | |
509 | 944 |
945 r->upstream->process_header = ngx_http_proxy_process_status_line; | |
946 | |
947 return NGX_OK; | |
948 } | |
949 | |
950 | |
951 static ngx_int_t | |
952 ngx_http_proxy_process_status_line(ngx_http_request_t *r) | |
953 { | |
954 ngx_int_t rc; | |
955 ngx_http_upstream_t *u; | |
1658 | 956 ngx_http_proxy_ctx_t *ctx; |
957 | |
958 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
959 | |
960 if (ctx == NULL) { | |
577 | 961 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
509 | 962 } |
963 | |
1658 | 964 rc = ngx_http_proxy_parse_status_line(r, ctx); |
509 | 965 |
966 if (rc == NGX_AGAIN) { | |
967 return rc; | |
968 } | |
969 | |
970 u = r->upstream; | |
971 | |
972 if (rc == NGX_HTTP_PROXY_PARSE_NO_HEADER) { | |
973 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
577 | 974 "upstream sent no valid HTTP/1.0 header"); |
509 | 975 |
619 | 976 #if 0 |
509 | 977 if (u->accel) { |
978 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
979 } | |
619 | 980 #endif |
509 | 981 |
982 r->http_version = NGX_HTTP_VERSION_9; | |
1616 | 983 u->headers_in.status_n = NGX_HTTP_OK; |
984 u->state->status = NGX_HTTP_OK; | |
577 | 985 |
509 | 986 return NGX_OK; |
987 } | |
988 | |
1658 | 989 u->headers_in.status_n = ctx->status; |
990 u->state->status = ctx->status; | |
991 | |
992 u->headers_in.status_line.len = ctx->status_end - ctx->status_start; | |
529 | 993 u->headers_in.status_line.data = ngx_palloc(r->pool, |
994 u->headers_in.status_line.len); | |
995 if (u->headers_in.status_line.data == NULL) { | |
509 | 996 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
997 } | |
573 | 998 |
1658 | 999 ngx_memcpy(u->headers_in.status_line.data, ctx->status_start, |
529 | 1000 u->headers_in.status_line.len); |
509 | 1001 |
1002 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1003 "http proxy status %ui \"%V\"", | |
936 | 1004 u->headers_in.status_n, &u->headers_in.status_line); |
509 | 1005 |
1006 u->process_header = ngx_http_proxy_process_header; | |
1007 | |
1008 return ngx_http_proxy_process_header(r); | |
1009 } | |
1010 | |
1011 | |
1012 static ngx_int_t | |
1658 | 1013 ngx_http_proxy_parse_status_line(ngx_http_request_t *r, |
1014 ngx_http_proxy_ctx_t *ctx) | |
509 | 1015 { |
1016 u_char ch; | |
1658 | 1017 u_char *p; |
509 | 1018 ngx_http_upstream_t *u; |
1019 enum { | |
1020 sw_start = 0, | |
1021 sw_H, | |
1022 sw_HT, | |
1023 sw_HTT, | |
1024 sw_HTTP, | |
1025 sw_first_major_digit, | |
1026 sw_major_digit, | |
1027 sw_first_minor_digit, | |
1028 sw_minor_digit, | |
1029 sw_status, | |
1030 sw_space_after_status, | |
1031 sw_status_text, | |
1032 sw_almost_done | |
577 | 1033 } state; |
509 | 1034 |
1035 u = r->upstream; | |
1036 | |
1037 state = r->state; | |
1038 | |
1658 | 1039 for (p = u->buffer.pos; p < u->buffer.last; p++) { |
1040 ch = *p; | |
509 | 1041 |
1042 switch (state) { | |
1043 | |
1044 /* "HTTP/" */ | |
1045 case sw_start: | |
1046 switch (ch) { | |
577 | 1047 case 'H': |
509 | 1048 state = sw_H; |
1049 break; | |
1050 default: | |
1051 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1052 } | |
1053 break; | |
1054 | |
577 | 1055 case sw_H: |
509 | 1056 switch (ch) { |
577 | 1057 case 'T': |
509 | 1058 state = sw_HT; |
1059 break; | |
1060 default: | |
1061 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1062 } | |
1063 break; | |
1064 | |
1065 case sw_HT: | |
1066 switch (ch) { | |
577 | 1067 case 'T': |
509 | 1068 state = sw_HTT; |
1069 break; | |
1070 default: | |
1071 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1072 } | |
1073 break; | |
1074 | |
1075 case sw_HTT: | |
1076 switch (ch) { | |
577 | 1077 case 'P': |
509 | 1078 state = sw_HTTP; |
1079 break; | |
1080 default: | |
1081 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1082 } | |
1083 break; | |
1084 | |
1085 case sw_HTTP: | |
1086 switch (ch) { | |
577 | 1087 case '/': |
509 | 1088 state = sw_first_major_digit; |
1089 break; | |
1090 default: | |
1091 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1092 } | |
1093 break; | |
1094 | |
1095 /* the first digit of major HTTP version */ | |
1096 case sw_first_major_digit: | |
1097 if (ch < '1' || ch > '9') { | |
1098 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1099 } | |
1100 | |
1101 state = sw_major_digit; | |
1102 break; | |
1103 | |
1104 /* the major HTTP version or dot */ | |
1105 case sw_major_digit: | |
1106 if (ch == '.') { | |
1107 state = sw_first_minor_digit; | |
1108 break; | |
1109 } | |
1110 | |
1111 if (ch < '0' || ch > '9') { | |
1112 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1113 } | |
1114 | |
1115 break; | |
1116 | |
1117 /* the first digit of minor HTTP version */ | |
1118 case sw_first_minor_digit: | |
1119 if (ch < '0' || ch > '9') { | |
1120 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1121 } | |
1122 | |
1123 state = sw_minor_digit; | |
1124 break; | |
1125 | |
1126 /* the minor HTTP version or the end of the request line */ | |
1127 case sw_minor_digit: | |
1128 if (ch == ' ') { | |
1129 state = sw_status; | |
1130 break; | |
1131 } | |
1132 | |
1133 if (ch < '0' || ch > '9') { | |
1134 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1135 } | |
1136 | |
1137 break; | |
1138 | |
1139 /* HTTP status code */ | |
1140 case sw_status: | |
619 | 1141 if (ch == ' ') { |
1142 break; | |
1143 } | |
1144 | |
509 | 1145 if (ch < '0' || ch > '9') { |
1146 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1147 } | |
1148 | |
1658 | 1149 ctx->status = ctx->status * 10 + ch - '0'; |
1150 | |
1151 if (++ctx->status_count == 3) { | |
509 | 1152 state = sw_space_after_status; |
1658 | 1153 ctx->status_start = p - 2; |
509 | 1154 } |
1155 | |
1156 break; | |
1157 | |
1158 /* space or end of line */ | |
1159 case sw_space_after_status: | |
1160 switch (ch) { | |
577 | 1161 case ' ': |
509 | 1162 state = sw_status_text; |
1163 break; | |
1164 case '.': /* IIS may send 403.1, 403.2, etc */ | |
1165 state = sw_status_text; | |
1166 break; | |
1167 case CR: | |
1168 state = sw_almost_done; | |
1169 break; | |
1170 case LF: | |
1171 goto done; | |
1172 default: | |
1173 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1174 } | |
1175 break; | |
1176 | |
1177 /* any text until end of line */ | |
1178 case sw_status_text: | |
1179 switch (ch) { | |
1180 case CR: | |
1181 state = sw_almost_done; | |
1182 | |
1183 break; | |
1184 case LF: | |
1185 goto done; | |
1186 } | |
1187 break; | |
1188 | |
527 | 1189 /* end of status line */ |
509 | 1190 case sw_almost_done: |
1658 | 1191 ctx->status_end = p - 1; |
509 | 1192 switch (ch) { |
1193 case LF: | |
1194 goto done; | |
1195 default: | |
1196 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
1197 } | |
1198 } | |
1199 } | |
1200 | |
1658 | 1201 u->buffer.pos = p; |
509 | 1202 r->state = state; |
1203 | |
1204 return NGX_AGAIN; | |
1205 | |
1206 done: | |
1207 | |
1658 | 1208 u->buffer.pos = p + 1; |
1209 | |
1210 if (ctx->status_end == NULL) { | |
1211 ctx->status_end = p; | |
509 | 1212 } |
1213 | |
1214 r->state = sw_start; | |
1215 | |
507 | 1216 return NGX_OK; |
1217 } | |
1218 | |
1219 | |
1220 static ngx_int_t | |
1221 ngx_http_proxy_process_header(ngx_http_request_t *r) | |
1222 { | |
509 | 1223 ngx_int_t rc; |
649 | 1224 ngx_uint_t i; |
509 | 1225 ngx_table_elt_t *h; |
1226 ngx_http_upstream_header_t *hh; | |
1227 ngx_http_upstream_main_conf_t *umcf; | |
1228 | |
1229 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
1230 | |
1231 for ( ;; ) { | |
1232 | |
581 | 1233 rc = ngx_http_parse_header_line(r, &r->upstream->buffer); |
509 | 1234 |
1235 if (rc == NGX_OK) { | |
1236 | |
1237 /* a header line has been parsed successfully */ | |
507 | 1238 |
509 | 1239 h = ngx_list_push(&r->upstream->headers_in.headers); |
1240 if (h == NULL) { | |
1241 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1242 } | |
1243 | |
1244 h->hash = r->header_hash; | |
1245 | |
1246 h->key.len = r->header_name_end - r->header_name_start; | |
1247 h->value.len = r->header_end - r->header_start; | |
1248 | |
1249 h->key.data = ngx_palloc(r->pool, | |
649 | 1250 h->key.len + 1 + h->value.len + 1 + h->key.len); |
509 | 1251 if (h->key.data == NULL) { |
1252 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1253 } | |
1254 | |
1255 h->value.data = h->key.data + h->key.len + 1; | |
649 | 1256 h->lowcase_key = h->key.data + h->key.len + 1 + h->value.len + 1; |
507 | 1257 |
509 | 1258 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1); |
1259 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1); | |
1260 | |
649 | 1261 if (h->key.len == r->lowcase_index) { |
1262 ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); | |
1263 | |
1264 } else { | |
1265 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
|
1266 h->lowcase_key[i] = ngx_tolower(h->key.data[i]); |
509 | 1267 } |
1268 } | |
1269 | |
649 | 1270 hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, |
1271 h->lowcase_key, h->key.len); | |
1272 | |
1273 if (hh && hh->handler(r, h, hh->offset) != NGX_OK) { | |
1274 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1275 } | |
1276 | |
509 | 1277 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1278 "http proxy header: \"%V: %V\"", | |
1279 &h->key, &h->value); | |
1280 | |
1281 continue; | |
1282 } | |
1283 | |
1284 if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | |
1285 | |
1286 /* a whole header has been parsed successfully */ | |
1287 | |
1288 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1289 "http proxy header done"); | |
1290 | |
649 | 1291 /* |
1292 * if no "Server" and "Date" in header line, | |
1293 * then add the special empty headers | |
1294 */ | |
1295 | |
1296 if (r->upstream->headers_in.server == NULL) { | |
1297 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1298 if (h == NULL) { | |
1299 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1300 } | |
1301 | |
1302 h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash( | |
1303 ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r'); | |
1304 | |
1305 h->key.len = sizeof("Server") - 1; | |
1306 h->key.data = (u_char *) "Server"; | |
1307 h->value.len = 0; | |
1308 h->value.data = NULL; | |
1309 h->lowcase_key = (u_char *) "server"; | |
1310 } | |
1311 | |
1312 if (r->upstream->headers_in.date == NULL) { | |
1313 h = ngx_list_push(&r->upstream->headers_in.headers); | |
1314 if (h == NULL) { | |
1315 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1316 } | |
1317 | |
1318 h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e'); | |
1319 | |
1320 h->key.len = sizeof("Date") - 1; | |
1321 h->key.data = (u_char *) "Date"; | |
1322 h->value.len = 0; | |
1323 h->value.data = NULL; | |
1324 h->lowcase_key = (u_char *) "date"; | |
1325 } | |
1326 | |
509 | 1327 return NGX_OK; |
1328 } | |
1329 | |
521 | 1330 if (rc == NGX_AGAIN) { |
1331 return NGX_AGAIN; | |
1332 } | |
1333 | |
509 | 1334 /* there was error while a header line parsing */ |
1335 | |
1336 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
619 | 1337 "upstream sent invalid header"); |
509 | 1338 |
1339 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1340 } | |
507 | 1341 } |
1342 | |
1343 | |
1344 static void | |
1345 ngx_http_proxy_abort_request(ngx_http_request_t *r) | |
1346 { | |
1347 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1348 "abort http proxy request"); | |
577 | 1349 |
507 | 1350 return; |
1351 } | |
1352 | |
1353 | |
1354 static void | |
1355 ngx_http_proxy_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
577 | 1356 { |
507 | 1357 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1358 "finalize http proxy request"); | |
1359 | |
1360 return; | |
1361 } | |
1362 | |
1363 | |
573 | 1364 static ngx_int_t |
1365 ngx_http_proxy_host_variable(ngx_http_request_t *r, | |
1366 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1367 { |
1658 | 1368 ngx_http_proxy_ctx_t *ctx; |
1369 | |
1370 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1371 | |
1372 if (ctx == NULL) { | |
1373 v->not_found = 1; | |
1374 return NGX_OK; | |
1375 } | |
1376 | |
1377 v->len = ctx->vars.host_header.len; | |
577 | 1378 v->valid = 1; |
1565 | 1379 v->no_cacheable = 0; |
573 | 1380 v->not_found = 0; |
1658 | 1381 v->data = ctx->vars.host_header.data; |
507 | 1382 |
573 | 1383 return NGX_OK; |
507 | 1384 } |
1385 | |
1386 | |
573 | 1387 static ngx_int_t |
1388 ngx_http_proxy_port_variable(ngx_http_request_t *r, | |
1389 ngx_http_variable_value_t *v, uintptr_t data) | |
507 | 1390 { |
1658 | 1391 ngx_http_proxy_ctx_t *ctx; |
1392 | |
1393 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1394 | |
1395 if (ctx == NULL) { | |
1396 v->not_found = 1; | |
1397 return NGX_OK; | |
1398 } | |
1399 | |
1400 v->len = ctx->vars.port.len; | |
577 | 1401 v->valid = 1; |
1565 | 1402 v->no_cacheable = 0; |
573 | 1403 v->not_found = 0; |
1658 | 1404 v->data = ctx->vars.port.data; |
509 | 1405 |
573 | 1406 return NGX_OK; |
509 | 1407 } |
1408 | |
1409 | |
573 | 1410 static ngx_int_t |
509 | 1411 ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r, |
573 | 1412 ngx_http_variable_value_t *v, uintptr_t data) |
509 | 1413 { |
573 | 1414 u_char *p; |
509 | 1415 |
577 | 1416 v->valid = 1; |
1565 | 1417 v->no_cacheable = 0; |
573 | 1418 v->not_found = 0; |
509 | 1419 |
1420 if (r->headers_in.x_forwarded_for == NULL) { | |
573 | 1421 v->len = r->connection->addr_text.len; |
1422 v->data = r->connection->addr_text.data; | |
1423 return NGX_OK; | |
509 | 1424 } |
1425 | |
573 | 1426 v->len = r->headers_in.x_forwarded_for->value.len |
1427 + sizeof(", ") - 1 + r->connection->addr_text.len; | |
509 | 1428 |
573 | 1429 p = ngx_palloc(r->pool, v->len); |
509 | 1430 if (p == NULL) { |
573 | 1431 return NGX_ERROR; |
509 | 1432 } |
1433 | |
573 | 1434 v->data = p; |
509 | 1435 |
573 | 1436 p = ngx_copy(p, r->headers_in.x_forwarded_for->value.data, |
1437 r->headers_in.x_forwarded_for->value.len); | |
509 | 1438 |
1439 *p++ = ','; *p++ = ' '; | |
1440 | |
1441 ngx_memcpy(p, r->connection->addr_text.data, r->connection->addr_text.len); | |
1442 | |
573 | 1443 return NGX_OK; |
509 | 1444 } |
1445 | |
1446 | |
1447 static ngx_int_t | |
577 | 1448 ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r, |
1449 ngx_http_variable_value_t *v, uintptr_t data) | |
1450 { | |
1658 | 1451 ngx_http_proxy_ctx_t *ctx; |
1452 | |
1453 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
1454 | |
1455 if (ctx == NULL) { | |
577 | 1456 v->not_found = 1; |
1457 return NGX_OK; | |
1458 } | |
1459 | |
1460 v->valid = 1; | |
1565 | 1461 v->no_cacheable = 0; |
577 | 1462 v->not_found = 0; |
1463 | |
1464 v->data = ngx_palloc(r->connection->pool, NGX_SIZE_T_LEN); | |
1465 | |
1466 if (v->data == NULL) { | |
1467 return NGX_ERROR; | |
1468 } | |
1469 | |
1658 | 1470 v->len = ngx_sprintf(v->data, "%uz", ctx->internal_body_length) - v->data; |
577 | 1471 |
1472 return NGX_OK; | |
1473 } | |
1474 | |
1475 | |
1476 static ngx_int_t | |
509 | 1477 ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, ngx_table_elt_t *h, |
1478 size_t prefix) | |
1479 { | |
1480 ngx_int_t rc; | |
1481 ngx_uint_t i; | |
1482 ngx_http_proxy_loc_conf_t *plcf; | |
1483 ngx_http_proxy_redirect_t *pr; | |
1484 | |
1485 plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module); | |
1486 | |
1487 pr = plcf->redirects->elts; | |
1488 | |
1489 if (pr == NULL) { | |
1490 return NGX_DECLINED; | |
1491 } | |
1492 | |
1493 for (i = 0; i < plcf->redirects->nelts; i++) { | |
605 | 1494 rc = pr[i].handler(r, h, prefix, &pr[i]); |
509 | 1495 |
1496 if (rc != NGX_DECLINED) { | |
1497 return rc; | |
1498 } | |
1499 } | |
1500 | |
1501 return NGX_DECLINED; | |
1502 } | |
1503 | |
1504 | |
1505 static ngx_int_t | |
1506 ngx_http_proxy_rewrite_redirect_text(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1507 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1508 { | |
1509 size_t len; | |
1510 u_char *data, *p; | |
1511 | |
1512 if (pr->redirect.len > h->value.len - prefix | |
1513 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1514 pr->redirect.len) != 0) | |
1515 { | |
1516 return NGX_DECLINED; | |
1517 } | |
1518 | |
1519 len = prefix + pr->replacement.text.len + h->value.len - pr->redirect.len; | |
507 | 1520 |
509 | 1521 data = ngx_palloc(r->pool, len); |
1522 if (data == NULL) { | |
1523 return NGX_ERROR; | |
1524 } | |
1525 | |
1526 p = data; | |
1527 | |
573 | 1528 p = ngx_copy(p, h->value.data, prefix); |
509 | 1529 |
653 | 1530 if (pr->replacement.text.len) { |
1531 p = ngx_copy(p, pr->replacement.text.data, pr->replacement.text.len); | |
1532 } | |
509 | 1533 |
1534 ngx_memcpy(p, h->value.data + prefix + pr->redirect.len, | |
1535 h->value.len - pr->redirect.len - prefix); | |
1536 | |
1537 h->value.len = len; | |
1538 h->value.data = data; | |
1539 | |
1540 return NGX_OK; | |
1541 } | |
1542 | |
1543 | |
1544 static ngx_int_t | |
1545 ngx_http_proxy_rewrite_redirect_vars(ngx_http_request_t *r, ngx_table_elt_t *h, | |
1546 size_t prefix, ngx_http_proxy_redirect_t *pr) | |
1547 { | |
1548 size_t len; | |
1549 u_char *data, *p; | |
1550 ngx_http_script_code_pt code; | |
1551 ngx_http_script_engine_t e; | |
1552 ngx_http_script_len_code_pt lcode; | |
1553 | |
1554 if (pr->redirect.len > h->value.len - prefix | |
1555 || ngx_rstrncmp(h->value.data + prefix, pr->redirect.data, | |
1556 pr->redirect.len) != 0) | |
1557 { | |
1558 return NGX_DECLINED; | |
1559 } | |
1560 | |
1561 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
1562 | |
1563 e.ip = pr->replacement.vars.lengths; | |
1564 e.request = r; | |
1565 | |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1566 len = prefix + h->value.len - pr->redirect.len; |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1567 |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1568 while (*(uintptr_t *) e.ip) { |
509 | 1569 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
|
1570 len += lcode(&e); |
509 | 1571 } |
1572 | |
1573 data = ngx_palloc(r->pool, len); | |
1574 if (data == NULL) { | |
1575 return NGX_ERROR; | |
1576 } | |
1577 | |
1578 p = data; | |
1579 | |
573 | 1580 p = ngx_copy(p, h->value.data, prefix); |
509 | 1581 |
1582 e.ip = pr->replacement.vars.values; | |
1583 e.pos = p; | |
1584 | |
1585 while (*(uintptr_t *) e.ip) { | |
1586 code = *(ngx_http_script_code_pt *) e.ip; | |
1587 code(&e); | |
1588 } | |
1589 | |
723
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1590 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
|
1591 h->value.len - pr->redirect.len - prefix); |
ceb5ef29b119
fix proxy_redirect with variable
Igor Sysoev <igor@sysoev.ru>
parents:
673
diff
changeset
|
1592 |
509 | 1593 h->value.len = len; |
1594 h->value.data = data; | |
1595 | |
1596 return NGX_OK; | |
1597 } | |
1598 | |
1599 | |
1600 static ngx_int_t | |
1601 ngx_http_proxy_add_variables(ngx_conf_t *cf) | |
1602 { | |
1603 ngx_http_variable_t *var, *v; | |
1604 | |
1605 for (v = ngx_http_proxy_vars; v->name.len; v++) { | |
1606 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
1607 if (var == NULL) { | |
1608 return NGX_ERROR; | |
1609 } | |
1610 | |
637 | 1611 var->get_handler = v->get_handler; |
509 | 1612 var->data = v->data; |
1613 } | |
1614 | |
1615 return NGX_OK; | |
507 | 1616 } |
1617 | |
1618 | |
1619 static void * | |
1620 ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) | |
1621 { | |
1622 ngx_http_proxy_loc_conf_t *conf; | |
1623 | |
1624 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)); | |
1625 if (conf == NULL) { | |
1626 return NGX_CONF_ERROR; | |
1627 } | |
1628 | |
1629 /* | |
1630 * set by ngx_pcalloc(): | |
1631 * | |
1632 * conf->upstream.bufs.num = 0; | |
1633 * conf->upstream.next_upstream = 0; | |
1634 * conf->upstream.temp_path = NULL; | |
649 | 1635 * conf->upstream.hide_headers_hash = { NULL, 0 }; |
1636 * conf->upstream.hide_headers = NULL; | |
1637 * conf->upstream.pass_headers = NULL; | |
509 | 1638 * conf->upstream.schema = { 0, NULL }; |
1639 * conf->upstream.uri = { 0, NULL }; | |
1640 * conf->upstream.location = NULL; | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1641 * conf->upstream.store_lengths = NULL; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1642 * conf->upstream.store_values = NULL; |
509 | 1643 * |
561 | 1644 * conf->method = NULL; |
509 | 1645 * conf->headers_source = NULL; |
1646 * conf->headers_set_len = NULL; | |
1647 * conf->headers_set = NULL; | |
1648 * conf->headers_set_hash = NULL; | |
577 | 1649 * conf->body_set_len = NULL; |
1650 * conf->body_set = NULL; | |
1651 * conf->body_source = { 0, NULL }; | |
509 | 1652 * conf->rewrite_locations = NULL; |
507 | 1653 */ |
577 | 1654 |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1655 conf->upstream.store = NGX_CONF_UNSET; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1656 conf->upstream.store_access = NGX_CONF_UNSET_UINT; |
581 | 1657 conf->upstream.buffering = NGX_CONF_UNSET; |
629 | 1658 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; |
581 | 1659 |
507 | 1660 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
1661 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
1662 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
1663 | |
1664 conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE; | |
581 | 1665 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; |
529 | 1666 |
1667 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | |
577 | 1668 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; |
529 | 1669 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; |
509 | 1670 |
1671 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | |
1672 conf->upstream.pass_request_body = NGX_CONF_UNSET; | |
561 | 1673 |
657 | 1674 conf->upstream.intercept_errors = NGX_CONF_UNSET; |
507 | 1675 |
1676 /* "proxy_cyclic_temp_file" is disabled */ | |
1677 conf->upstream.cyclic_temp_file = 0; | |
1678 | |
509 | 1679 conf->redirect = NGX_CONF_UNSET; |
649 | 1680 conf->upstream.change_buffering = 1; |
507 | 1681 |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1682 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
|
1683 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
|
1684 |
507 | 1685 return conf; |
1686 } | |
1687 | |
1688 | |
1689 static char * | |
1690 ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
1691 { | |
1692 ngx_http_proxy_loc_conf_t *prev = parent; | |
1693 ngx_http_proxy_loc_conf_t *conf = child; | |
1694 | |
509 | 1695 u_char *p; |
1696 size_t size; | |
1697 uintptr_t *code; | |
649 | 1698 ngx_str_t *header; |
1699 ngx_uint_t i, j; | |
1700 ngx_array_t hide_headers; | |
1701 ngx_keyval_t *src, *s, *h; | |
1702 ngx_hash_key_t *hk; | |
1703 ngx_hash_init_t hash; | |
509 | 1704 ngx_http_proxy_redirect_t *pr; |
1705 ngx_http_script_compile_t sc; | |
1706 ngx_http_script_copy_code_t *copy; | |
1707 | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1708 if (conf->upstream.store != 0) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1709 ngx_conf_merge_value(conf->upstream.store, |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1710 prev->upstream.store, 0); |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1711 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1712 if (conf->upstream.store_lengths == NULL) { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1713 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
|
1714 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
|
1715 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1716 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1717 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
1718 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
|
1719 prev->upstream.store_access, 0600); |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1244
diff
changeset
|
1720 |
581 | 1721 ngx_conf_merge_value(conf->upstream.buffering, |
1722 prev->upstream.buffering, 1); | |
1723 | |
629 | 1724 ngx_conf_merge_value(conf->upstream.ignore_client_abort, |
1725 prev->upstream.ignore_client_abort, 0); | |
1726 | |
507 | 1727 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
1728 prev->upstream.connect_timeout, 60000); | |
1729 | |
1730 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1731 prev->upstream.send_timeout, 60000); | |
1732 | |
1733 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1734 prev->upstream.read_timeout, 60000); | |
1735 | |
1736 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1737 prev->upstream.send_lowat, 0); | |
1738 | |
581 | 1739 ngx_conf_merge_size_value(conf->upstream.buffer_size, |
1740 prev->upstream.buffer_size, | |
507 | 1741 (size_t) ngx_pagesize); |
1742 | |
1743 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1744 8, ngx_pagesize); | |
1745 | |
1746 if (conf->upstream.bufs.num < 2) { | |
577 | 1747 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
507 | 1748 "there must be at least 2 \"proxy_buffers\""); |
1749 return NGX_CONF_ERROR; | |
1750 } | |
577 | 1751 |
507 | 1752 |
581 | 1753 size = conf->upstream.buffer_size; |
577 | 1754 if (size < conf->upstream.bufs.size) { |
507 | 1755 size = conf->upstream.bufs.size; |
1756 } | |
1757 | |
1758 | |
529 | 1759 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, |
1760 prev->upstream.busy_buffers_size_conf, | |
507 | 1761 NGX_CONF_UNSET_SIZE); |
1762 | |
529 | 1763 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1764 conf->upstream.busy_buffers_size = 2 * size; |
529 | 1765 } else { |
1766 conf->upstream.busy_buffers_size = | |
1767 conf->upstream.busy_buffers_size_conf; | |
1768 } | |
577 | 1769 |
529 | 1770 if (conf->upstream.busy_buffers_size < size) { |
507 | 1771 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1772 "\"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
|
1773 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1774 "one of the \"proxy_buffers\""); |
1775 | |
1776 return NGX_CONF_ERROR; | |
529 | 1777 } |
507 | 1778 |
529 | 1779 if (conf->upstream.busy_buffers_size |
1780 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
507 | 1781 { |
1782 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1783 "\"proxy_busy_buffers_size\" must be less than " | |
1784 "the size of all \"proxy_buffers\" minus one buffer"); | |
1785 | |
1786 return NGX_CONF_ERROR; | |
1787 } | |
529 | 1788 |
507 | 1789 |
529 | 1790 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, |
1791 prev->upstream.temp_file_write_size_conf, | |
507 | 1792 NGX_CONF_UNSET_SIZE); |
1793 | |
529 | 1794 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1795 conf->upstream.temp_file_write_size = 2 * size; |
529 | 1796 } else { |
1797 conf->upstream.temp_file_write_size = | |
1798 conf->upstream.temp_file_write_size_conf; | |
1799 } | |
577 | 1800 |
529 | 1801 if (conf->upstream.temp_file_write_size < size) { |
507 | 1802 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1803 "\"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
|
1804 "maximum of the value of \"proxy_buffer_size\" and " |
507 | 1805 "one of the \"proxy_buffers\""); |
1806 | |
1807 return NGX_CONF_ERROR; | |
1808 } | |
1809 | |
529 | 1810 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, |
1811 prev->upstream.max_temp_file_size_conf, | |
507 | 1812 NGX_CONF_UNSET_SIZE); |
1813 | |
529 | 1814 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { |
507 | 1815 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; |
529 | 1816 } else { |
1817 conf->upstream.max_temp_file_size = | |
1818 conf->upstream.max_temp_file_size_conf; | |
1819 } | |
507 | 1820 |
529 | 1821 if (conf->upstream.max_temp_file_size != 0 |
1822 && conf->upstream.max_temp_file_size < size) | |
507 | 1823 { |
1824 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
561 | 1825 "\"proxy_max_temp_file_size\" must be equal to zero to disable " |
507 | 1826 "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
|
1827 "maximum of the value of \"proxy_buffer_size\" and " |
561 | 1828 "one of the \"proxy_buffers\""); |
507 | 1829 |
1830 return NGX_CONF_ERROR; | |
1831 } | |
1832 | |
529 | 1833 |
507 | 1834 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, |
1835 prev->upstream.next_upstream, | |
1836 (NGX_CONF_BITMASK_SET | |
1837 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1838 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1839 | |
665 | 1840 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { |
1841 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1842 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1843 } | |
1844 | |
509 | 1845 ngx_conf_merge_path_value(conf->upstream.temp_path, |
1846 prev->upstream.temp_path, | |
1847 NGX_HTTP_PROXY_TEMP_PATH, 1, 2, 0, | |
1848 ngx_garbage_collector_temp_handler, cf); | |
507 | 1849 |
561 | 1850 if (conf->method.len == 0) { |
1851 conf->method = prev->method; | |
1852 | |
1853 } else { | |
1854 conf->method.data[conf->method.len] = ' '; | |
1855 conf->method.len++; | |
509 | 1856 } |
1857 | |
1858 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1859 prev->upstream.pass_request_headers, 1); | |
1860 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1861 prev->upstream.pass_request_body, 1); | |
1862 | |
657 | 1863 ngx_conf_merge_value(conf->upstream.intercept_errors, |
1864 prev->upstream.intercept_errors, 0); | |
509 | 1865 |
1866 ngx_conf_merge_value(conf->redirect, prev->redirect, 1); | |
1867 | |
1868 if (conf->redirect) { | |
507 | 1869 |
509 | 1870 if (conf->redirects == NULL) { |
1871 conf->redirects = prev->redirects; | |
1872 } | |
1873 | |
1658 | 1874 if (conf->redirects == NULL && conf->url.data) { |
509 | 1875 |
1876 conf->redirects = ngx_array_create(cf->pool, 1, | |
1877 sizeof(ngx_http_proxy_redirect_t)); | |
1878 if (conf->redirects == NULL) { | |
1879 return NGX_CONF_ERROR; | |
1880 } | |
1881 | |
1882 pr = ngx_array_push(conf->redirects); | |
1883 if (pr == NULL) { | |
1884 return NGX_CONF_ERROR; | |
1885 } | |
1886 | |
1887 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 1888 pr->redirect = conf->url; |
1889 | |
1890 if (conf->vars.uri.len) { | |
1891 pr->replacement.text = conf->location; | |
653 | 1892 |
1893 } else { | |
1894 pr->replacement.text.len = 0; | |
1895 pr->replacement.text.data = NULL; | |
1896 } | |
509 | 1897 } |
1898 } | |
1899 | |
1658 | 1900 /* STUB */ |
1901 if (prev->proxy_lengths) { | |
1902 conf->proxy_lengths = prev->proxy_lengths; | |
1903 conf->proxy_values = prev->proxy_values; | |
1904 } | |
1905 | |
1180
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1906 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
|
1907 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
|
1908 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1909 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
|
1910 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
|
1911 |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1912 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
|
1913 ngx_cacheline_size); |
1666b7b0bafc
proxy_headers_hash_max_size and proxy_headers_hash_bucket_size
Igor Sysoev <igor@sysoev.ru>
parents:
1125
diff
changeset
|
1914 |
649 | 1915 if (conf->upstream.hide_headers == NULL |
1916 && conf->upstream.pass_headers == NULL) | |
1917 { | |
1918 conf->upstream.hide_headers = prev->upstream.hide_headers; | |
1919 conf->upstream.pass_headers = prev->upstream.pass_headers; | |
1920 conf->upstream.hide_headers_hash = prev->upstream.hide_headers_hash; | |
1921 | |
1922 if (conf->upstream.hide_headers_hash.buckets) { | |
1923 goto peers; | |
1924 } | |
1925 | |
1926 } else { | |
1927 if (conf->upstream.hide_headers == NULL) { | |
1928 conf->upstream.hide_headers = prev->upstream.hide_headers; | |
1929 } | |
1930 | |
1931 if (conf->upstream.pass_headers == NULL) { | |
1932 conf->upstream.pass_headers = prev->upstream.pass_headers; | |
1933 } | |
1934 } | |
1935 | |
1936 if (ngx_array_init(&hide_headers, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | |
1937 != NGX_OK) | |
1938 { | |
1939 return NGX_CONF_ERROR; | |
1940 } | |
1941 | |
1942 for (header = ngx_http_proxy_hide_headers; header->len; header++) { | |
1943 hk = ngx_array_push(&hide_headers); | |
1944 if (hk == NULL) { | |
1945 return NGX_CONF_ERROR; | |
1946 } | |
1947 | |
1948 hk->key = *header; | |
1949 hk->key_hash = ngx_hash_key_lc(header->data, header->len); | |
1950 hk->value = (void *) 1; | |
1951 } | |
1952 | |
1953 if (conf->upstream.hide_headers) { | |
1954 | |
1955 header = conf->upstream.hide_headers->elts; | |
1956 | |
1957 for (i = 0; i < conf->upstream.hide_headers->nelts; i++) { | |
1958 | |
1959 hk = hide_headers.elts; | |
1960 | |
1961 for (j = 0; j < hide_headers.nelts; j++) { | |
1962 if (ngx_strcasecmp(header[i].data, hk[j].key.data) == 0) { | |
1963 goto exist; | |
1964 } | |
1965 } | |
1966 | |
1967 hk = ngx_array_push(&hide_headers); | |
1968 if (hk == NULL) { | |
1969 return NGX_CONF_ERROR; | |
1970 } | |
1971 | |
1972 hk->key = header[i]; | |
1973 hk->key_hash = ngx_hash_key_lc(header[i].data, header[i].len); | |
1974 hk->value = (void *) 1; | |
1975 | |
1976 exist: | |
1977 | |
1978 continue; | |
1979 } | |
1980 } | |
1981 | |
1982 if (conf->upstream.pass_headers) { | |
1983 | |
1984 hk = hide_headers.elts; | |
1985 header = conf->upstream.pass_headers->elts; | |
1986 | |
1987 for (i = 0; i < conf->upstream.pass_headers->nelts; i++) { | |
1988 for (j = 0; j < hide_headers.nelts; j++) { | |
1989 | |
1990 if (hk[j].key.data == NULL) { | |
1991 continue; | |
1992 } | |
1993 | |
1994 if (ngx_strcasecmp(header[i].data, hk[j].key.data) == 0) { | |
1995 hk[j].key.data = NULL; | |
1996 break; | |
1997 } | |
1998 } | |
1999 } | |
2000 } | |
2001 | |
2002 hash.hash = &conf->upstream.hide_headers_hash; | |
2003 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
|
2004 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
|
2005 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
|
2006 hash.name = "proxy_headers_hash"; |
649 | 2007 hash.pool = cf->pool; |
2008 hash.temp_pool = NULL; | |
2009 | |
2010 if (ngx_hash_init(&hash, hide_headers.elts, hide_headers.nelts) != NGX_OK) { | |
2011 return NGX_CONF_ERROR; | |
2012 } | |
2013 | |
2014 peers: | |
507 | 2015 |
884 | 2016 if (conf->upstream.upstream == NULL) { |
2017 conf->upstream.upstream = prev->upstream.upstream; | |
629 | 2018 |
1658 | 2019 conf->vars = prev->vars; |
629 | 2020 conf->upstream.schema = prev->upstream.schema; |
507 | 2021 } |
2022 | |
577 | 2023 |
2024 if (conf->body_source.data == NULL) { | |
2025 conf->body_source = prev->body_source; | |
2026 conf->body_set_len = prev->body_set_len; | |
2027 conf->body_set = prev->body_set; | |
2028 } | |
2029 | |
579 | 2030 if (conf->body_source.data && conf->body_set_len == NULL) { |
577 | 2031 |
2032 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2033 | |
2034 sc.cf = cf; | |
2035 sc.source = &conf->body_source; | |
2036 sc.flushes = &conf->flushes; | |
2037 sc.lengths = &conf->body_set_len; | |
2038 sc.values = &conf->body_set; | |
2039 sc.complete_lengths = 1; | |
2040 sc.complete_values = 1; | |
2041 | |
2042 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2043 return NGX_CONF_ERROR; | |
2044 } | |
2045 | |
2046 if (conf->headers_source == NULL) { | |
2047 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 2048 sizeof(ngx_keyval_t)); |
577 | 2049 if (conf->headers_source == NULL) { |
2050 return NGX_CONF_ERROR; | |
2051 } | |
2052 } | |
2053 | |
2054 s = ngx_array_push(conf->headers_source); | |
2055 if (s == NULL) { | |
2056 return NGX_CONF_ERROR; | |
2057 } | |
2058 | |
2059 s->key.len = sizeof("Content-Length") - 1; | |
2060 s->key.data = (u_char *) "Content-Length"; | |
2061 s->value.len = sizeof("$proxy_internal_body_length") - 1; | |
2062 s->value.data = (u_char *) "$proxy_internal_body_length"; | |
2063 } | |
2064 | |
2065 | |
509 | 2066 if (conf->headers_source == NULL) { |
573 | 2067 conf->flushes = prev->flushes; |
507 | 2068 conf->headers_set_len = prev->headers_set_len; |
2069 conf->headers_set = prev->headers_set; | |
2070 conf->headers_set_hash = prev->headers_set_hash; | |
573 | 2071 conf->headers_source = prev->headers_source; |
507 | 2072 } |
2073 | |
649 | 2074 if (conf->headers_set_hash.buckets) { |
509 | 2075 return NGX_CONF_OK; |
2076 } | |
2077 | |
2078 | |
649 | 2079 conf->headers_names = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t)); |
509 | 2080 if (conf->headers_names == NULL) { |
2081 return NGX_CONF_ERROR; | |
2082 } | |
2083 | |
2084 if (conf->headers_source == NULL) { | |
2085 conf->headers_source = ngx_array_create(cf->pool, 4, | |
649 | 2086 sizeof(ngx_keyval_t)); |
509 | 2087 if (conf->headers_source == NULL) { |
2088 return NGX_CONF_ERROR; | |
2089 } | |
2090 } | |
507 | 2091 |
509 | 2092 conf->headers_set_len = ngx_array_create(cf->pool, 64, 1); |
2093 if (conf->headers_set_len == NULL) { | |
2094 return NGX_CONF_ERROR; | |
2095 } | |
2096 | |
2097 conf->headers_set = ngx_array_create(cf->pool, 512, 1); | |
2098 if (conf->headers_set == NULL) { | |
2099 return NGX_CONF_ERROR; | |
2100 } | |
2101 | |
2102 | |
2103 src = conf->headers_source->elts; | |
2104 | |
2105 for (h = ngx_http_proxy_headers; h->key.len; h++) { | |
2106 | |
2107 for (i = 0; i < conf->headers_source->nelts; i++) { | |
2108 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { | |
2109 goto next; | |
507 | 2110 } |
2111 } | |
2112 | |
509 | 2113 s = ngx_array_push(conf->headers_source); |
2114 if (s == NULL) { | |
507 | 2115 return NGX_CONF_ERROR; |
2116 } | |
2117 | |
509 | 2118 *s = *h; |
507 | 2119 |
517 | 2120 src = conf->headers_source->elts; |
2121 | |
509 | 2122 next: |
507 | 2123 |
509 | 2124 continue; |
2125 } | |
507 | 2126 |
577 | 2127 |
2128 src = conf->headers_source->elts; | |
509 | 2129 for (i = 0; i < conf->headers_source->nelts; i++) { |
507 | 2130 |
649 | 2131 hk = ngx_array_push(conf->headers_names); |
2132 if (hk == NULL) { | |
507 | 2133 return NGX_CONF_ERROR; |
2134 } | |
2135 | |
649 | 2136 hk->key = src[i].key; |
2137 hk->key_hash = ngx_hash_key_lc(src[i].key.data, src[i].key.len); | |
2138 hk->value = (void *) 1; | |
509 | 2139 |
519 | 2140 if (src[i].value.len == 0) { |
2141 continue; | |
2142 } | |
2143 | |
509 | 2144 if (ngx_http_script_variables_count(&src[i].value) == 0) { |
2145 copy = ngx_array_push_n(conf->headers_set_len, | |
2146 sizeof(ngx_http_script_copy_code_t)); | |
2147 if (copy == NULL) { | |
2148 return NGX_CONF_ERROR; | |
2149 } | |
2150 | |
2151 copy->code = (ngx_http_script_code_pt) | |
2152 ngx_http_script_copy_len_code; | |
2153 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2154 + src[i].value.len + sizeof(CRLF) - 1; | |
507 | 2155 |
2156 | |
509 | 2157 size = (sizeof(ngx_http_script_copy_code_t) |
2158 + src[i].key.len + sizeof(": ") - 1 | |
2159 + src[i].value.len + sizeof(CRLF) - 1 | |
2160 + sizeof(uintptr_t) - 1) | |
2161 & ~(sizeof(uintptr_t) - 1); | |
2162 | |
2163 copy = ngx_array_push_n(conf->headers_set, size); | |
2164 if (copy == NULL) { | |
2165 return NGX_CONF_ERROR; | |
2166 } | |
2167 | |
2168 copy->code = ngx_http_script_copy_code; | |
2169 copy->len = src[i].key.len + sizeof(": ") - 1 | |
2170 + src[i].value.len + sizeof(CRLF) - 1; | |
2171 | |
2172 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2173 | |
2174 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2175 *p++ = ':'; *p++ = ' '; | |
2176 p = ngx_cpymem(p, src[i].value.data, src[i].value.len); | |
2177 *p++ = CR; *p = LF; | |
2178 | |
2179 } else { | |
2180 copy = ngx_array_push_n(conf->headers_set_len, | |
2181 sizeof(ngx_http_script_copy_code_t)); | |
2182 if (copy == NULL) { | |
2183 return NGX_CONF_ERROR; | |
2184 } | |
2185 | |
2186 copy->code = (ngx_http_script_code_pt) | |
2187 ngx_http_script_copy_len_code; | |
2188 copy->len = src[i].key.len + sizeof(": ") - 1; | |
507 | 2189 |
2190 | |
509 | 2191 size = (sizeof(ngx_http_script_copy_code_t) |
2192 + src[i].key.len + sizeof(": ") - 1 + sizeof(uintptr_t) - 1) | |
2193 & ~(sizeof(uintptr_t) - 1); | |
2194 | |
2195 copy = ngx_array_push_n(conf->headers_set, size); | |
2196 if (copy == NULL) { | |
2197 return NGX_CONF_ERROR; | |
2198 } | |
2199 | |
2200 copy->code = ngx_http_script_copy_code; | |
2201 copy->len = src[i].key.len + sizeof(": ") - 1; | |
2202 | |
2203 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2204 p = ngx_cpymem(p, src[i].key.data, src[i].key.len); | |
2205 *p++ = ':'; *p = ' '; | |
2206 | |
2207 | |
2208 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2209 | |
2210 sc.cf = cf; | |
2211 sc.source = &src[i].value; | |
573 | 2212 sc.flushes = &conf->flushes; |
509 | 2213 sc.lengths = &conf->headers_set_len; |
2214 sc.values = &conf->headers_set; | |
2215 | |
2216 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2217 return NGX_CONF_ERROR; | |
2218 } | |
2219 | |
2220 | |
2221 copy = ngx_array_push_n(conf->headers_set_len, | |
2222 sizeof(ngx_http_script_copy_code_t)); | |
2223 if (copy == NULL) { | |
2224 return NGX_CONF_ERROR; | |
2225 } | |
2226 | |
2227 copy->code = (ngx_http_script_code_pt) | |
2228 ngx_http_script_copy_len_code; | |
2229 copy->len = sizeof(CRLF) - 1; | |
2230 | |
2231 | |
2232 size = (sizeof(ngx_http_script_copy_code_t) | |
2233 + sizeof(CRLF) - 1 + sizeof(uintptr_t) - 1) | |
2234 & ~(sizeof(uintptr_t) - 1); | |
2235 | |
2236 copy = ngx_array_push_n(conf->headers_set, size); | |
2237 if (copy == NULL) { | |
2238 return NGX_CONF_ERROR; | |
2239 } | |
2240 | |
2241 copy->code = ngx_http_script_copy_code; | |
2242 copy->len = sizeof(CRLF) - 1; | |
2243 | |
2244 p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t); | |
2245 *p++ = CR; *p = LF; | |
507 | 2246 } |
2247 | |
509 | 2248 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2249 if (code == NULL) { | |
507 | 2250 return NGX_CONF_ERROR; |
2251 } | |
2252 | |
509 | 2253 *code = (uintptr_t) NULL; |
2254 | |
2255 code = ngx_array_push_n(conf->headers_set, sizeof(uintptr_t)); | |
2256 if (code == NULL) { | |
2257 return NGX_CONF_ERROR; | |
2258 } | |
2259 | |
2260 *code = (uintptr_t) NULL; | |
507 | 2261 } |
2262 | |
509 | 2263 code = ngx_array_push_n(conf->headers_set_len, sizeof(uintptr_t)); |
2264 if (code == NULL) { | |
2265 return NGX_CONF_ERROR; | |
507 | 2266 } |
2267 | |
509 | 2268 *code = (uintptr_t) NULL; |
507 | 2269 |
2270 | |
649 | 2271 hash.hash = &conf->headers_set_hash; |
2272 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
|
2273 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
|
2274 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
|
2275 hash.name = "proxy_headers_hash"; |
649 | 2276 hash.pool = cf->pool; |
2277 hash.temp_pool = NULL; | |
2278 | |
2279 if (ngx_hash_init(&hash, conf->headers_names->elts, | |
2280 conf->headers_names->nelts) | |
2281 != NGX_OK) | |
2282 { | |
2283 return NGX_CONF_ERROR; | |
2284 } | |
2285 | |
509 | 2286 return NGX_CONF_OK; |
507 | 2287 } |
2288 | |
2289 | |
2290 static char * | |
2291 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
2292 { | |
509 | 2293 ngx_http_proxy_loc_conf_t *plcf = conf; |
507 | 2294 |
1658 | 2295 size_t add; |
2296 u_short port; | |
2297 ngx_str_t *value, *url; | |
2298 ngx_url_t u; | |
2299 ngx_uint_t n; | |
2300 ngx_http_core_loc_conf_t *clcf; | |
2301 ngx_http_script_compile_t sc; | |
507 | 2302 |
555 | 2303 if (plcf->upstream.schema.len) { |
2304 return "is duplicate"; | |
2305 } | |
2306 | |
1658 | 2307 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
2308 | |
507 | 2309 value = cf->args->elts; |
2310 | |
2311 url = &value[1]; | |
2312 | |
1658 | 2313 n = ngx_http_script_variables_count(url); |
2314 | |
2315 if (n) { | |
2316 | |
2317 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2318 | |
2319 sc.cf = cf; | |
2320 sc.source = url; | |
2321 sc.lengths = &plcf->proxy_lengths; | |
2322 sc.values = &plcf->proxy_values; | |
2323 sc.variables = n; | |
2324 sc.complete_lengths = 1; | |
2325 sc.complete_values = 1; | |
1679
ca317d9b5c09
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1671
diff
changeset
|
2326 |
1658 | 2327 if (ngx_http_script_compile(&sc) != NGX_OK) { |
2328 return NGX_CONF_ERROR; | |
2329 } | |
2330 | |
2331 #if (NGX_HTTP_SSL) | |
2332 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { | |
2333 return NGX_CONF_ERROR; | |
2334 } | |
2335 #endif | |
2336 | |
2337 clcf->handler = ngx_http_proxy_handler; | |
2338 | |
2339 return NGX_CONF_OK; | |
2340 } | |
2341 | |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2342 if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) { |
577 | 2343 add = 7; |
591 | 2344 port = 80; |
577 | 2345 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
969
diff
changeset
|
2346 } else if (ngx_strncasecmp(url->data, (u_char *) "https://", 8) == 0) { |
577 | 2347 |
2348 #if (NGX_HTTP_SSL) | |
1658 | 2349 if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) { |
2350 return NGX_CONF_ERROR; | |
2351 } | |
577 | 2352 |
2353 add = 8; | |
591 | 2354 port = 443; |
577 | 2355 #else |
2356 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2357 "https protocol requires SSL support"); | |
2358 return NGX_CONF_ERROR; | |
2359 #endif | |
2360 | |
2361 } else { | |
507 | 2362 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix"); |
2363 return NGX_CONF_ERROR; | |
2364 } | |
2365 | |
651 | 2366 ngx_memzero(&u, sizeof(ngx_url_t)); |
2367 | |
2368 u.url.len = url->len - add; | |
2369 u.url.data = url->data + add; | |
906 | 2370 u.default_port = port; |
2371 u.uri_part = 1; | |
884 | 2372 u.no_resolve = 1; |
2373 | |
2374 plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); | |
2375 if (plcf->upstream.upstream == NULL) { | |
507 | 2376 return NGX_CONF_ERROR; |
2377 } | |
2378 | |
1658 | 2379 if (ngx_http_proxy_set_vars(cf->pool, &u, &plcf->vars) != NGX_OK) { |
2380 return NGX_CONF_ERROR; | |
906 | 2381 } |
2382 | |
591 | 2383 plcf->upstream.schema.len = add; |
2384 plcf->upstream.schema.data = url->data; | |
1658 | 2385 plcf->location = clcf->name; |
507 | 2386 |
2387 clcf->handler = ngx_http_proxy_handler; | |
2388 | |
1353 | 2389 if (clcf->named |
507 | 2390 #if (NGX_PCRE) |
1353 | 2391 || clcf->regex |
2392 #endif | |
2393 || clcf->noname) | |
2394 { | |
1658 | 2395 if (plcf->vars.uri.len) { |
573 | 2396 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2397 "\"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
|
2398 "location given by regular expression, " |
1353 | 2399 "or inside named location, " |
843
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2400 "or inside the \"if\" statement, " |
ebab9490204c
allow proxy_pass inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
812
diff
changeset
|
2401 "or inside the \"limit_except\" block"); |
573 | 2402 return NGX_CONF_ERROR; |
2403 } | |
2404 | |
1658 | 2405 plcf->location.len = 0; |
555 | 2406 } |
2407 | |
1658 | 2408 plcf->url = *url; |
509 | 2409 |
507 | 2410 if (clcf->name.data[clcf->name.len - 1] == '/') { |
2411 clcf->auto_redirect = 1; | |
2412 } | |
2413 | |
2414 return NGX_CONF_OK; | |
2415 } | |
2416 | |
2417 | |
2418 static char * | |
509 | 2419 ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
507 | 2420 { |
509 | 2421 ngx_http_proxy_loc_conf_t *plcf = conf; |
2422 | |
2423 ngx_str_t *value; | |
2424 ngx_array_t *vars_lengths, *vars_values; | |
2425 ngx_http_script_compile_t sc; | |
2426 ngx_http_proxy_redirect_t *pr; | |
2427 | |
2428 if (plcf->redirect == 0) { | |
2429 return NGX_CONF_OK; | |
2430 } | |
2431 | |
2432 value = cf->args->elts; | |
2433 | |
2434 if (ngx_strcmp(value[1].data, "off") == 0) { | |
2435 plcf->redirect = 0; | |
2436 plcf->redirects = NULL; | |
2437 return NGX_CONF_OK; | |
2438 } | |
2439 | |
2440 if (plcf->redirects == NULL) { | |
2441 plcf->redirects = ngx_array_create(cf->pool, 1, | |
2442 sizeof(ngx_http_proxy_redirect_t)); | |
2443 if (plcf->redirects == NULL) { | |
2444 return NGX_CONF_ERROR; | |
2445 } | |
2446 } | |
2447 | |
2448 pr = ngx_array_push(plcf->redirects); | |
2449 if (pr == NULL) { | |
2450 return NGX_CONF_ERROR; | |
2451 } | |
2452 | |
2453 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "default") == 0) { | |
1658 | 2454 if (plcf->url.data == NULL) { |
509 | 2455 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2456 "\"proxy_rewrite_location default\" must go " | |
2457 "after the \"proxy_pass\" directive"); | |
2458 return NGX_CONF_ERROR; | |
2459 } | |
2460 | |
2461 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
1658 | 2462 pr->redirect = plcf->url; |
2463 | |
2464 if (plcf->vars.uri.len) { | |
2465 pr->replacement.text = plcf->location; | |
653 | 2466 |
2467 } else { | |
2468 pr->replacement.text.len = 0; | |
2469 pr->replacement.text.data = NULL; | |
2470 } | |
509 | 2471 |
2472 return NGX_CONF_OK; | |
2473 } | |
2474 | |
2475 if (ngx_http_script_variables_count(&value[2]) == 0) { | |
2476 pr->handler = ngx_http_proxy_rewrite_redirect_text; | |
2477 pr->redirect = value[1]; | |
2478 pr->replacement.text = value[2]; | |
2479 | |
2480 return NGX_CONF_OK; | |
2481 } | |
2482 | |
2483 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
2484 | |
2485 vars_lengths = NULL; | |
2486 vars_values = NULL; | |
2487 | |
2488 sc.cf = cf; | |
2489 sc.source = &value[2]; | |
2490 sc.lengths = &vars_lengths; | |
2491 sc.values = &vars_values; | |
2492 sc.complete_lengths = 1; | |
2493 sc.complete_values = 1; | |
2494 | |
2495 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
2496 return NGX_CONF_ERROR; | |
2497 } | |
2498 | |
2499 pr->handler = ngx_http_proxy_rewrite_redirect_vars; | |
2500 pr->redirect = value[1]; | |
2501 pr->replacement.vars.lengths = vars_lengths->elts; | |
2502 pr->replacement.vars.values = vars_values->elts; | |
2503 | |
507 | 2504 return NGX_CONF_OK; |
2505 } | |
2506 | |
2507 | |
2508 static char * | |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2509 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
|
2510 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2511 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
|
2512 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2513 ngx_str_t *value; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2514 ngx_http_script_compile_t sc; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2515 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2516 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
|
2517 { |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2518 return "is duplicate"; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2519 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2520 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2521 value = cf->args->elts; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2522 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2523 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
|
2524 plcf->upstream.store = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2525 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2526 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2527 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2528 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
|
2529 plcf->upstream.store = 0; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2530 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2531 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2532 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2533 /* include the terminating '\0' into script */ |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2534 value[1].len++; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2535 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2536 ngx_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
|
2537 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2538 sc.cf = cf; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2539 sc.source = &value[1]; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2540 sc.lengths = &plcf->upstream.store_lengths; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2541 sc.values = &plcf->upstream.store_values; |
1563
022ec9420f80
style fix: remove double semicolons
Igor Sysoev <igor@sysoev.ru>
parents:
1488
diff
changeset
|
2542 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
|
2543 sc.complete_lengths = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2544 sc.complete_values = 1; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2545 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2546 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
|
2547 return NGX_CONF_ERROR; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2548 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2549 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2550 return NGX_CONF_OK; |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2551 } |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2552 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2553 |
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
2554 static char * |
507 | 2555 ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data) |
2556 { | |
2557 #if (NGX_FREEBSD) | |
2558 ssize_t *np = data; | |
2559 | |
673 | 2560 if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) { |
507 | 2561 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2562 "\"proxy_send_lowat\" must be less than %d " | |
2563 "(sysctl net.inet.tcp.sendspace)", | |
2564 ngx_freebsd_net_inet_tcp_sendspace); | |
2565 | |
2566 return NGX_CONF_ERROR; | |
2567 } | |
2568 | |
2569 #elif !(NGX_HAVE_SO_SNDLOWAT) | |
2570 ssize_t *np = data; | |
2571 | |
2572 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2573 "\"proxy_send_lowat\" is not supported, ignored"); | |
2574 | |
2575 *np = 0; | |
2576 | |
2577 #endif | |
2578 | |
2579 return NGX_CONF_OK; | |
2580 } | |
884 | 2581 |
2582 | |
2583 static char * | |
2584 ngx_http_proxy_upstream_max_fails_unsupported(ngx_conf_t *cf, | |
2585 ngx_command_t *cmd, void *conf) | |
2586 { | |
2587 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2588 "\"proxy_upstream_max_fails\" is not supported, " | |
2589 "use the \"max_fails\" parameter of the \"server\" directive ", | |
2590 "inside the \"upstream\" block"); | |
2591 | |
2592 return NGX_CONF_ERROR; | |
2593 } | |
2594 | |
2595 | |
2596 static char * | |
2597 ngx_http_proxy_upstream_fail_timeout_unsupported(ngx_conf_t *cf, | |
2598 ngx_command_t *cmd, void *conf) | |
2599 { | |
2600 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2601 "\"proxy_upstream_fail_timeout\" is not supported, " | |
2602 "use the \"fail_timeout\" parameter of the \"server\" directive ", | |
2603 "inside the \"upstream\" block"); | |
2604 | |
2605 return NGX_CONF_ERROR; | |
2606 } | |
1658 | 2607 |
2608 | |
2609 #if (NGX_HTTP_SSL) | |
2610 | |
2611 static ngx_int_t | |
2612 ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf) | |
2613 { | |
2614 ngx_pool_cleanup_t *cln; | |
2615 | |
2616 plcf->upstream.ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); | |
2617 if (plcf->upstream.ssl == NULL) { | |
2618 return NGX_ERROR; | |
2619 } | |
2620 | |
2621 plcf->upstream.ssl->log = cf->log; | |
2622 | |
2623 if (ngx_ssl_create(plcf->upstream.ssl, | |
2624 NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1, NULL) | |
2625 != NGX_OK) | |
2626 { | |
2627 return NGX_ERROR; | |
2628 } | |
2629 | |
2630 cln = ngx_pool_cleanup_add(cf->pool, 0); | |
2631 if (cln == NULL) { | |
2632 return NGX_ERROR; | |
2633 } | |
2634 | |
2635 cln->handler = ngx_ssl_cleanup_ctx; | |
2636 cln->data = plcf->upstream.ssl; | |
2637 | |
2638 return NGX_OK; | |
2639 } | |
2640 | |
2641 #endif | |
2642 | |
2643 | |
2644 static ngx_int_t | |
2645 ngx_http_proxy_set_vars(ngx_pool_t *pool, ngx_url_t *u, | |
2646 ngx_http_proxy_vars_t *v) | |
2647 { | |
2648 if (!u->unix_socket) { | |
2649 if (u->no_port || u->port == u->default_port) { | |
2650 v->host_header = u->host; | |
2651 | |
2652 if (u->default_port == 80) { | |
2653 v->port.len = sizeof("80") - 1; | |
2654 v->port.data = (u_char *) "80"; | |
2655 | |
2656 } else { | |
2657 v->port.len = sizeof("443") - 1; | |
2658 v->port.data = (u_char *) "443"; | |
2659 } | |
2660 | |
2661 } 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
|
2662 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
|
2663 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
|
2664 v->port = u->port_text; |
1658 | 2665 } |
2666 | |
2667 } else { | |
2668 v->host_header.len = sizeof("localhost") - 1; | |
2669 v->host_header.data = (u_char *) "localhost"; | |
2670 v->port.len = 0; | |
2671 v->port.data = (u_char *) ""; | |
2672 } | |
2673 | |
2674 v->uri = u->uri; | |
2675 | |
2676 return NGX_OK; | |
2677 } |