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