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