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