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