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