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