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