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