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