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