Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_memcached_module.c @ 5528:d5de6c25b759
SPDY: use frame->next pointer to chain free frames.
There is no need in separate "free" pointer and like it is for ngx_chain_t
the "next" pointer can be used. But after this change successfully handled
frame should not be accessed, so the frame handling cycle was improved to
store pointer to the next frame before processing.
Also worth noting that initializing "free" pointer to NULL in the original
code was surplus.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 22 Jan 2014 04:58:19 +0400 |
parents | 2fda9065d0f4 |
children | d80543940f9a |
rev | line source |
---|---|
581 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
581 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 typedef struct { | |
14 ngx_http_upstream_conf_t upstream; | |
1076 | 15 ngx_int_t index; |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
16 ngx_uint_t gzip_flag; |
581 | 17 } ngx_http_memcached_loc_conf_t; |
18 | |
19 | |
20 typedef struct { | |
21 size_t rest; | |
22 ngx_http_request_t *request; | |
597 | 23 ngx_str_t key; |
581 | 24 } ngx_http_memcached_ctx_t; |
25 | |
26 | |
27 static ngx_int_t ngx_http_memcached_create_request(ngx_http_request_t *r); | |
28 static ngx_int_t ngx_http_memcached_reinit_request(ngx_http_request_t *r); | |
29 static ngx_int_t ngx_http_memcached_process_header(ngx_http_request_t *r); | |
30 static ngx_int_t ngx_http_memcached_filter_init(void *data); | |
31 static ngx_int_t ngx_http_memcached_filter(void *data, ssize_t bytes); | |
32 static void ngx_http_memcached_abort_request(ngx_http_request_t *r); | |
33 static void ngx_http_memcached_finalize_request(ngx_http_request_t *r, | |
34 ngx_int_t rc); | |
35 | |
36 static void *ngx_http_memcached_create_loc_conf(ngx_conf_t *cf); | |
37 static char *ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, | |
38 void *parent, void *child); | |
39 | |
40 static char *ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, | |
41 void *conf); | |
42 | |
43 | |
44 static ngx_conf_bitmask_t ngx_http_memcached_next_upstream_masks[] = { | |
45 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, | |
46 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, | |
47 { ngx_string("invalid_response"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, | |
48 { ngx_string("not_found"), NGX_HTTP_UPSTREAM_FT_HTTP_404 }, | |
665 | 49 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, |
581 | 50 { ngx_null_string, 0 } |
51 }; | |
52 | |
53 | |
54 static ngx_command_t ngx_http_memcached_commands[] = { | |
55 | |
56 { ngx_string("memcached_pass"), | |
1788
f10228d7ea06
allow memached_pass inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1787
diff
changeset
|
57 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, |
581 | 58 ngx_http_memcached_pass, |
59 NGX_HTTP_LOC_CONF_OFFSET, | |
60 0, | |
61 NULL }, | |
62 | |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3061
diff
changeset
|
63 { ngx_string("memcached_bind"), |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3061
diff
changeset
|
64 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
3399 | 65 ngx_http_upstream_bind_set_slot, |
3271
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3061
diff
changeset
|
66 NGX_HTTP_LOC_CONF_OFFSET, |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3061
diff
changeset
|
67 offsetof(ngx_http_memcached_loc_conf_t, upstream.local), |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3061
diff
changeset
|
68 NULL }, |
fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
Igor Sysoev <igor@sysoev.ru>
parents:
3061
diff
changeset
|
69 |
581 | 70 { ngx_string("memcached_connect_timeout"), |
71 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
72 ngx_conf_set_msec_slot, | |
73 NGX_HTTP_LOC_CONF_OFFSET, | |
74 offsetof(ngx_http_memcached_loc_conf_t, upstream.connect_timeout), | |
75 NULL }, | |
76 | |
77 { ngx_string("memcached_send_timeout"), | |
78 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
79 ngx_conf_set_msec_slot, | |
80 NGX_HTTP_LOC_CONF_OFFSET, | |
81 offsetof(ngx_http_memcached_loc_conf_t, upstream.send_timeout), | |
82 NULL }, | |
83 | |
84 { ngx_string("memcached_buffer_size"), | |
85 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
86 ngx_conf_set_size_slot, | |
87 NGX_HTTP_LOC_CONF_OFFSET, | |
88 offsetof(ngx_http_memcached_loc_conf_t, upstream.buffer_size), | |
89 NULL }, | |
90 | |
91 { ngx_string("memcached_read_timeout"), | |
92 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
93 ngx_conf_set_msec_slot, | |
94 NGX_HTTP_LOC_CONF_OFFSET, | |
95 offsetof(ngx_http_memcached_loc_conf_t, upstream.read_timeout), | |
96 NULL }, | |
97 | |
98 { ngx_string("memcached_next_upstream"), | |
99 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
100 ngx_conf_set_bitmask_slot, | |
101 NGX_HTTP_LOC_CONF_OFFSET, | |
102 offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream), | |
103 &ngx_http_memcached_next_upstream_masks }, | |
104 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
105 { ngx_string("memcached_gzip_flag"), |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
107 ngx_conf_set_num_slot, |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
108 NGX_HTTP_LOC_CONF_OFFSET, |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
109 offsetof(ngx_http_memcached_loc_conf_t, gzip_flag), |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
110 NULL }, |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
111 |
581 | 112 ngx_null_command |
113 }; | |
114 | |
115 | |
667 | 116 static ngx_http_module_t ngx_http_memcached_module_ctx = { |
581 | 117 NULL, /* preconfiguration */ |
118 NULL, /* postconfiguration */ | |
119 | |
120 NULL, /* create main configuration */ | |
121 NULL, /* init main configuration */ | |
122 | |
123 NULL, /* create server configuration */ | |
124 NULL, /* merge server configuration */ | |
125 | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
126 ngx_http_memcached_create_loc_conf, /* create location configuration */ |
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
127 ngx_http_memcached_merge_loc_conf /* merge location configuration */ |
581 | 128 }; |
129 | |
130 | |
131 ngx_module_t ngx_http_memcached_module = { | |
132 NGX_MODULE_V1, | |
133 &ngx_http_memcached_module_ctx, /* module context */ | |
134 ngx_http_memcached_commands, /* module directives */ | |
135 NGX_HTTP_MODULE, /* module type */ | |
136 NULL, /* init master */ | |
137 NULL, /* init module */ | |
138 NULL, /* init process */ | |
139 NULL, /* init thread */ | |
140 NULL, /* exit thread */ | |
141 NULL, /* exit process */ | |
142 NULL, /* exit master */ | |
143 NGX_MODULE_V1_PADDING | |
144 }; | |
145 | |
146 | |
1076 | 147 static ngx_str_t ngx_http_memcached_key = ngx_string("memcached_key"); |
148 | |
149 | |
581 | 150 #define NGX_HTTP_MEMCACHED_END (sizeof(ngx_http_memcached_end) - 1) |
151 static u_char ngx_http_memcached_end[] = CRLF "END" CRLF; | |
152 | |
153 | |
154 static ngx_int_t | |
155 ngx_http_memcached_handler(ngx_http_request_t *r) | |
156 { | |
157 ngx_int_t rc; | |
158 ngx_http_upstream_t *u; | |
159 ngx_http_memcached_ctx_t *ctx; | |
160 ngx_http_memcached_loc_conf_t *mlcf; | |
161 | |
645 | 162 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) { |
581 | 163 return NGX_HTTP_NOT_ALLOWED; |
164 } | |
165 | |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
1333
diff
changeset
|
166 rc = ngx_http_discard_request_body(r); |
581 | 167 |
1374 | 168 if (rc != NGX_OK) { |
581 | 169 return rc; |
170 } | |
171 | |
172 if (ngx_http_set_content_type(r) != NGX_OK) { | |
173 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
174 } | |
175 | |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
176 if (ngx_http_upstream_create(r) != NGX_OK) { |
581 | 177 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
178 } | |
179 | |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
180 u = r->upstream; |
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
181 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3487
diff
changeset
|
182 ngx_str_set(&u->schema, "memcached://"); |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
183 u->output.tag = (ngx_buf_tag_t) &ngx_http_memcached_module; |
581 | 184 |
3006
95972b9e790b
ngx_http_upstream_create() to cleanup the previous upstream after
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
185 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); |
581 | 186 |
187 u->conf = &mlcf->upstream; | |
188 | |
189 u->create_request = ngx_http_memcached_create_request; | |
190 u->reinit_request = ngx_http_memcached_reinit_request; | |
191 u->process_header = ngx_http_memcached_process_header; | |
192 u->abort_request = ngx_http_memcached_abort_request; | |
193 u->finalize_request = ngx_http_memcached_finalize_request; | |
194 | |
195 ctx = ngx_palloc(r->pool, sizeof(ngx_http_memcached_ctx_t)); | |
196 if (ctx == NULL) { | |
197 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
198 } | |
199 | |
200 ctx->request = r; | |
201 | |
597 | 202 ngx_http_set_ctx(r, ctx, ngx_http_memcached_module); |
203 | |
581 | 204 u->input_filter_init = ngx_http_memcached_filter_init; |
205 u->input_filter = ngx_http_memcached_filter; | |
206 u->input_filter_ctx = ctx; | |
207 | |
3061
f444f291ed38
fix request counter for memcached, introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3006
diff
changeset
|
208 r->main->count++; |
f444f291ed38
fix request counter for memcached, introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3006
diff
changeset
|
209 |
581 | 210 ngx_http_upstream_init(r); |
211 | |
212 return NGX_DONE; | |
213 } | |
214 | |
215 | |
216 static ngx_int_t | |
217 ngx_http_memcached_create_request(ngx_http_request_t *r) | |
218 { | |
1076 | 219 size_t len; |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
220 uintptr_t escape; |
1076 | 221 ngx_buf_t *b; |
222 ngx_chain_t *cl; | |
223 ngx_http_memcached_ctx_t *ctx; | |
224 ngx_http_variable_value_t *vv; | |
225 ngx_http_memcached_loc_conf_t *mlcf; | |
226 | |
227 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); | |
581 | 228 |
1076 | 229 vv = ngx_http_get_indexed_variable(r, mlcf->index); |
230 | |
231 if (vv == NULL || vv->not_found || vv->len == 0) { | |
232 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
233 "the \"$memcached_key\" variable is not set"); | |
234 return NGX_ERROR; | |
235 } | |
236 | |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
237 escape = 2 * ngx_escape_uri(NULL, vv->data, vv->len, NGX_ESCAPE_MEMCACHED); |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
238 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
239 len = sizeof("get ") - 1 + vv->len + escape + sizeof(CRLF) - 1; |
581 | 240 |
241 b = ngx_create_temp_buf(r->pool, len); | |
242 if (b == NULL) { | |
243 return NGX_ERROR; | |
244 } | |
245 | |
246 cl = ngx_alloc_chain_link(r->pool); | |
247 if (cl == NULL) { | |
248 return NGX_ERROR; | |
249 } | |
250 | |
251 cl->buf = b; | |
252 cl->next = NULL; | |
253 | |
254 r->upstream->request_bufs = cl; | |
255 | |
256 *b->last++ = 'g'; *b->last++ = 'e'; *b->last++ = 't'; *b->last++ = ' '; | |
257 | |
597 | 258 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); |
259 | |
260 ctx->key.data = b->last; | |
261 | |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
262 if (escape == 0) { |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
263 b->last = ngx_copy(b->last, vv->data, vv->len); |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
264 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
265 } else { |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
266 b->last = (u_char *) ngx_escape_uri(b->last, vv->data, vv->len, |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
267 NGX_ESCAPE_MEMCACHED); |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
268 } |
581 | 269 |
597 | 270 ctx->key.len = b->last - ctx->key.data; |
581 | 271 |
272 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
597 | 273 "http memcached request: \"%V\"", &ctx->key); |
581 | 274 |
1088
2d8e72584534
eliminate the useless space symbol
Igor Sysoev <igor@sysoev.ru>
parents:
1076
diff
changeset
|
275 *b->last++ = CR; *b->last++ = LF; |
581 | 276 |
277 return NGX_OK; | |
278 } | |
279 | |
280 | |
281 static ngx_int_t | |
282 ngx_http_memcached_reinit_request(ngx_http_request_t *r) | |
283 { | |
284 return NGX_OK; | |
285 } | |
286 | |
287 | |
288 static ngx_int_t | |
289 ngx_http_memcached_process_header(ngx_http_request_t *r) | |
290 { | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
291 u_char *p, *start; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
292 ngx_str_t line; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
293 ngx_uint_t flags; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
294 ngx_table_elt_t *h; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
295 ngx_http_upstream_t *u; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
296 ngx_http_memcached_ctx_t *ctx; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
297 ngx_http_memcached_loc_conf_t *mlcf; |
581 | 298 |
299 u = r->upstream; | |
300 | |
301 for (p = u->buffer.pos; p < u->buffer.last; p++) { | |
302 if (*p == LF) { | |
303 goto found; | |
304 } | |
305 } | |
306 | |
307 return NGX_AGAIN; | |
308 | |
309 found: | |
310 | |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
311 line.data = u->buffer.pos; |
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
312 line.len = p - u->buffer.pos; |
581 | 313 |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
314 if (line.len == 0 || *(p - 1) != CR) { |
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
315 goto no_valid; |
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
316 } |
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
317 |
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
318 *p = '\0'; |
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
319 line.len--; |
581 | 320 |
321 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
322 "memcached: \"%V\"", &line); | |
323 | |
324 p = u->buffer.pos; | |
325 | |
597 | 326 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
327 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); |
597 | 328 |
581 | 329 if (ngx_strncmp(p, "VALUE ", sizeof("VALUE ") - 1) == 0) { |
330 | |
331 p += sizeof("VALUE ") - 1; | |
332 | |
597 | 333 if (ngx_strncmp(p, ctx->key.data, ctx->key.len) != 0) { |
581 | 334 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
335 "memcached sent invalid key in response \"%V\" " | |
336 "for key \"%V\"", | |
597 | 337 &line, &ctx->key); |
581 | 338 |
339 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
340 } | |
341 | |
597 | 342 p += ctx->key.len; |
581 | 343 |
344 if (*p++ != ' ') { | |
345 goto no_valid; | |
346 } | |
347 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
348 /* flags */ |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
349 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
350 start = p; |
581 | 351 |
352 while (*p) { | |
353 if (*p++ == ' ') { | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
354 if (mlcf->gzip_flag) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
355 goto flags; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
356 } else { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
357 goto length; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
358 } |
581 | 359 } |
360 } | |
361 | |
362 goto no_valid; | |
363 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
364 flags: |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
365 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
366 flags = ngx_atoi(start, p - start - 1); |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
367 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
368 if (flags == (ngx_uint_t) NGX_ERROR) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
369 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
370 "memcached sent invalid flags in response \"%V\" " |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
371 "for key \"%V\"", |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
372 &line, &ctx->key); |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
373 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
374 } |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
375 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
376 if (flags & mlcf->gzip_flag) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
377 h = ngx_list_push(&r->headers_out.headers); |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
378 if (h == NULL) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
379 return NGX_ERROR; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
380 } |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
381 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
382 h->hash = 1; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
383 h->key.len = sizeof("Content-Encoding") - 1; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
384 h->key.data = (u_char *) "Content-Encoding"; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
385 h->value.len = sizeof("gzip") - 1; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
386 h->value.data = (u_char *) "gzip"; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
387 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
388 r->headers_out.content_encoding = h; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
389 } |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
390 |
581 | 391 length: |
392 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
393 start = p; |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
394 p = line.data + line.len; |
581 | 395 |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
396 u->headers_in.content_length_n = ngx_atoof(start, p - start); |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3523
diff
changeset
|
397 if (u->headers_in.content_length_n == -1) { |
581 | 398 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
399 "memcached sent invalid length in response \"%V\" " | |
400 "for key \"%V\"", | |
597 | 401 &line, &ctx->key); |
581 | 402 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
403 } | |
404 | |
405 u->headers_in.status_n = 200; | |
1567
31d4278d51c0
memcached did not set $upstream_response_time
Igor Sysoev <igor@sysoev.ru>
parents:
1554
diff
changeset
|
406 u->state->status = 200; |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
407 u->buffer.pos = p + sizeof(CRLF) - 1; |
581 | 408 |
409 return NGX_OK; | |
410 } | |
411 | |
412 if (ngx_strcmp(p, "END\x0d") == 0) { | |
413 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, | |
597 | 414 "key: \"%V\" was not found by memcached", &ctx->key); |
581 | 415 |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
416 u->headers_in.content_length_n = 0; |
581 | 417 u->headers_in.status_n = 404; |
1567
31d4278d51c0
memcached did not set $upstream_response_time
Igor Sysoev <igor@sysoev.ru>
parents:
1554
diff
changeset
|
418 u->state->status = 404; |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
419 u->buffer.pos = p + sizeof("END" CRLF) - 1; |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
420 u->keepalive = 1; |
581 | 421 |
422 return NGX_OK; | |
423 } | |
424 | |
425 no_valid: | |
426 | |
427 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
428 "memcached sent invalid response: \"%V\"", &line); | |
429 | |
430 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
431 } | |
432 | |
433 | |
434 static ngx_int_t | |
435 ngx_http_memcached_filter_init(void *data) | |
436 { | |
437 ngx_http_memcached_ctx_t *ctx = data; | |
438 | |
439 ngx_http_upstream_t *u; | |
440 | |
441 u = ctx->request->upstream; | |
442 | |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
443 if (u->headers_in.status_n != 404) { |
5300
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5226
diff
changeset
|
444 u->length = u->headers_in.content_length_n + NGX_HTTP_MEMCACHED_END; |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
445 ctx->rest = NGX_HTTP_MEMCACHED_END; |
5300
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5226
diff
changeset
|
446 |
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5226
diff
changeset
|
447 } else { |
f538a67c9f77
Upstream: u->length now defaults to -1 (API change).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5226
diff
changeset
|
448 u->length = 0; |
5226
a30ea5c6451d
Memcached: stricten header validation.
Ruslan Ermilov <ru@nginx.com>
parents:
5008
diff
changeset
|
449 } |
581 | 450 |
451 return NGX_OK; | |
452 } | |
453 | |
454 | |
455 static ngx_int_t | |
456 ngx_http_memcached_filter(void *data, ssize_t bytes) | |
457 { | |
458 ngx_http_memcached_ctx_t *ctx = data; | |
459 | |
460 u_char *last; | |
461 ngx_buf_t *b; | |
462 ngx_chain_t *cl, **ll; | |
463 ngx_http_upstream_t *u; | |
464 | |
465 u = ctx->request->upstream; | |
466 b = &u->buffer; | |
467 | |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
468 if (u->length == (ssize_t) ctx->rest) { |
581 | 469 |
470 if (ngx_strncmp(b->last, | |
1548 | 471 ngx_http_memcached_end + NGX_HTTP_MEMCACHED_END - ctx->rest, |
3487
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
472 bytes) |
1548 | 473 != 0) |
581 | 474 { |
475 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0, | |
476 "memcached sent invalid trailer"); | |
3487
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
477 |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
478 u->length = 0; |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
479 ctx->rest = 0; |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
480 |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
481 return NGX_OK; |
581 | 482 } |
483 | |
3487
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
484 u->length -= bytes; |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
485 ctx->rest -= bytes; |
581 | 486 |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
487 if (u->length == 0) { |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
488 u->keepalive = 1; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
489 } |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
490 |
581 | 491 return NGX_OK; |
492 } | |
493 | |
494 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { | |
495 ll = &cl->next; | |
496 } | |
497 | |
498 cl = ngx_chain_get_free_buf(ctx->request->pool, &u->free_bufs); | |
499 if (cl == NULL) { | |
500 return NGX_ERROR; | |
501 } | |
502 | |
503 cl->buf->flush = 1; | |
504 cl->buf->memory = 1; | |
505 | |
506 *ll = cl; | |
507 | |
1554
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
508 last = b->last; |
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
509 cl->buf->pos = last; |
581 | 510 b->last += bytes; |
511 cl->buf->last = b->last; | |
1908
f2953601ed3c
fix memory leak in long-lived non buffered connections
Igor Sysoev <igor@sysoev.ru>
parents:
1788
diff
changeset
|
512 cl->buf->tag = u->output.tag; |
581 | 513 |
514 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, | |
515 "memcached filter bytes:%z size:%z length:%z rest:%z", | |
516 bytes, b->last - b->pos, u->length, ctx->rest); | |
517 | |
1554
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
518 if (bytes <= (ssize_t) (u->length - NGX_HTTP_MEMCACHED_END)) { |
581 | 519 u->length -= bytes; |
520 return NGX_OK; | |
521 } | |
522 | |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5300
diff
changeset
|
523 last += (size_t) (u->length - NGX_HTTP_MEMCACHED_END); |
581 | 524 |
525 if (ngx_strncmp(last, ngx_http_memcached_end, b->last - last) != 0) { | |
526 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0, | |
527 "memcached sent invalid trailer"); | |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
528 |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
529 b->last = last; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
530 cl->buf->last = last; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
531 u->length = 0; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
532 ctx->rest = 0; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
533 |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
534 return NGX_OK; |
581 | 535 } |
536 | |
1554
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
537 ctx->rest -= b->last - last; |
581 | 538 b->last = last; |
539 cl->buf->last = last; | |
540 u->length = ctx->rest; | |
541 | |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
542 if (u->length == 0) { |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
543 u->keepalive = 1; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
544 } |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
545 |
581 | 546 return NGX_OK; |
547 } | |
548 | |
549 | |
550 static void | |
551 ngx_http_memcached_abort_request(ngx_http_request_t *r) | |
552 { | |
553 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
554 "abort http memcached request"); | |
555 return; | |
556 } | |
557 | |
558 | |
559 static void | |
560 ngx_http_memcached_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
561 { | |
562 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
563 "finalize http memcached request"); | |
564 return; | |
565 } | |
566 | |
567 | |
568 static void * | |
569 ngx_http_memcached_create_loc_conf(ngx_conf_t *cf) | |
570 { | |
571 ngx_http_memcached_loc_conf_t *conf; | |
572 | |
573 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_memcached_loc_conf_t)); | |
574 if (conf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2392
diff
changeset
|
575 return NULL; |
581 | 576 } |
577 | |
578 /* | |
579 * set by ngx_pcalloc(): | |
580 * | |
581 * conf->upstream.bufs.num = 0; | |
582 * conf->upstream.next_upstream = 0; | |
583 * conf->upstream.temp_path = NULL; | |
584 * conf->upstream.uri = { 0, NULL }; | |
585 * conf->upstream.location = NULL; | |
586 */ | |
587 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
4835
diff
changeset
|
588 conf->upstream.local = NGX_CONF_UNSET_PTR; |
581 | 589 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
590 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
591 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
592 | |
593 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; | |
594 | |
884 | 595 /* the hardcoded values */ |
581 | 596 conf->upstream.cyclic_temp_file = 0; |
629 | 597 conf->upstream.buffering = 0; |
598 conf->upstream.ignore_client_abort = 0; | |
581 | 599 conf->upstream.send_lowat = 0; |
600 conf->upstream.bufs.num = 0; | |
601 conf->upstream.busy_buffers_size = 0; | |
602 conf->upstream.max_temp_file_size = 0; | |
603 conf->upstream.temp_file_write_size = 0; | |
657 | 604 conf->upstream.intercept_errors = 1; |
675 | 605 conf->upstream.intercept_404 = 1; |
581 | 606 conf->upstream.pass_request_headers = 0; |
607 conf->upstream.pass_request_body = 0; | |
608 | |
1787
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
609 conf->index = NGX_CONF_UNSET; |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
610 conf->gzip_flag = NGX_CONF_UNSET_UINT; |
1787
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
611 |
581 | 612 return conf; |
613 } | |
614 | |
615 | |
616 static char * | |
617 ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
618 { | |
619 ngx_http_memcached_loc_conf_t *prev = parent; | |
620 ngx_http_memcached_loc_conf_t *conf = child; | |
621 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
4835
diff
changeset
|
622 ngx_conf_merge_ptr_value(conf->upstream.local, |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
4835
diff
changeset
|
623 prev->upstream.local, NULL); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
4835
diff
changeset
|
624 |
581 | 625 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
626 prev->upstream.connect_timeout, 60000); | |
627 | |
628 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
629 prev->upstream.send_timeout, 60000); | |
630 | |
631 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
632 prev->upstream.read_timeout, 60000); | |
633 | |
634 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
635 prev->upstream.buffer_size, | |
636 (size_t) ngx_pagesize); | |
637 | |
638 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
639 prev->upstream.next_upstream, | |
640 (NGX_CONF_BITMASK_SET | |
641 |NGX_HTTP_UPSTREAM_FT_ERROR | |
642 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
643 | |
665 | 644 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { |
645 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
646 |NGX_HTTP_UPSTREAM_FT_OFF; | |
647 } | |
648 | |
1787
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
649 if (conf->upstream.upstream == NULL) { |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
650 conf->upstream.upstream = prev->upstream.upstream; |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
651 } |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
652 |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
653 if (conf->index == NGX_CONF_UNSET) { |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
654 conf->index = prev->index; |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
655 } |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
656 |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
657 ngx_conf_merge_uint_value(conf->gzip_flag, prev->gzip_flag, 0); |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
658 |
581 | 659 return NGX_CONF_OK; |
660 } | |
661 | |
662 | |
663 static char * | |
664 ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
665 { | |
2392 | 666 ngx_http_memcached_loc_conf_t *mlcf = conf; |
581 | 667 |
668 ngx_str_t *value; | |
807
3095bf59059b
now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
675
diff
changeset
|
669 ngx_url_t u; |
581 | 670 ngx_http_core_loc_conf_t *clcf; |
671 | |
2392 | 672 if (mlcf->upstream.upstream) { |
581 | 673 return "is duplicate"; |
674 } | |
675 | |
676 value = cf->args->elts; | |
677 | |
807
3095bf59059b
now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
675
diff
changeset
|
678 ngx_memzero(&u, sizeof(ngx_url_t)); |
581 | 679 |
807
3095bf59059b
now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
675
diff
changeset
|
680 u.url = value[1]; |
884 | 681 u.no_resolve = 1; |
815
b630109560b7
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
807
diff
changeset
|
682 |
2392 | 683 mlcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); |
684 if (mlcf->upstream.upstream == NULL) { | |
884 | 685 return NGX_CONF_ERROR; |
581 | 686 } |
687 | |
688 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
689 | |
690 clcf->handler = ngx_http_memcached_handler; | |
691 | |
692 if (clcf->name.data[clcf->name.len - 1] == '/') { | |
693 clcf->auto_redirect = 1; | |
694 } | |
695 | |
2392 | 696 mlcf->index = ngx_http_get_variable_index(cf, &ngx_http_memcached_key); |
1076 | 697 |
2392 | 698 if (mlcf->index == NGX_ERROR) { |
1076 | 699 return NGX_CONF_ERROR; |
700 } | |
701 | |
581 | 702 return NGX_CONF_OK; |
703 } |