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