Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_memcached_module.c @ 5565:b8e6297358b5 stable-1.4
SPDY: fixed possible segfault.
While processing a DATA frame, the link to related stream is stored in spdy
connection object as part of connection state. But this stream can be closed
between receiving parts of the frame.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Wed, 22 Jan 2014 04:58:19 +0400 |
parents | fd84344f1df7 |
children | a30ea5c6451d |
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->rest = NGX_HTTP_MEMCACHED_END; | |
201 ctx->request = r; | |
202 | |
597 | 203 ngx_http_set_ctx(r, ctx, ngx_http_memcached_module); |
204 | |
581 | 205 u->input_filter_init = ngx_http_memcached_filter_init; |
206 u->input_filter = ngx_http_memcached_filter; | |
207 u->input_filter_ctx = ctx; | |
208 | |
3061
f444f291ed38
fix request counter for memcached, introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3006
diff
changeset
|
209 r->main->count++; |
f444f291ed38
fix request counter for memcached, introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3006
diff
changeset
|
210 |
581 | 211 ngx_http_upstream_init(r); |
212 | |
213 return NGX_DONE; | |
214 } | |
215 | |
216 | |
217 static ngx_int_t | |
218 ngx_http_memcached_create_request(ngx_http_request_t *r) | |
219 { | |
1076 | 220 size_t len; |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
221 uintptr_t escape; |
1076 | 222 ngx_buf_t *b; |
223 ngx_chain_t *cl; | |
224 ngx_http_memcached_ctx_t *ctx; | |
225 ngx_http_variable_value_t *vv; | |
226 ngx_http_memcached_loc_conf_t *mlcf; | |
227 | |
228 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); | |
581 | 229 |
1076 | 230 vv = ngx_http_get_indexed_variable(r, mlcf->index); |
231 | |
232 if (vv == NULL || vv->not_found || vv->len == 0) { | |
233 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
234 "the \"$memcached_key\" variable is not set"); | |
235 return NGX_ERROR; | |
236 } | |
237 | |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
238 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
|
239 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
240 len = sizeof("get ") - 1 + vv->len + escape + sizeof(CRLF) - 1; |
581 | 241 |
242 b = ngx_create_temp_buf(r->pool, len); | |
243 if (b == NULL) { | |
244 return NGX_ERROR; | |
245 } | |
246 | |
247 cl = ngx_alloc_chain_link(r->pool); | |
248 if (cl == NULL) { | |
249 return NGX_ERROR; | |
250 } | |
251 | |
252 cl->buf = b; | |
253 cl->next = NULL; | |
254 | |
255 r->upstream->request_bufs = cl; | |
256 | |
257 *b->last++ = 'g'; *b->last++ = 'e'; *b->last++ = 't'; *b->last++ = ' '; | |
258 | |
597 | 259 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); |
260 | |
261 ctx->key.data = b->last; | |
262 | |
1333
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
263 if (escape == 0) { |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
264 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
|
265 |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
266 } else { |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
267 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
|
268 NGX_ESCAPE_MEMCACHED); |
07ebeeb55700
escape space, etc in $memcached_key
Igor Sysoev <igor@sysoev.ru>
parents:
1332
diff
changeset
|
269 } |
581 | 270 |
597 | 271 ctx->key.len = b->last - ctx->key.data; |
581 | 272 |
273 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
597 | 274 "http memcached request: \"%V\"", &ctx->key); |
581 | 275 |
1088
2d8e72584534
eliminate the useless space symbol
Igor Sysoev <igor@sysoev.ru>
parents:
1076
diff
changeset
|
276 *b->last++ = CR; *b->last++ = LF; |
581 | 277 |
278 return NGX_OK; | |
279 } | |
280 | |
281 | |
282 static ngx_int_t | |
283 ngx_http_memcached_reinit_request(ngx_http_request_t *r) | |
284 { | |
285 return NGX_OK; | |
286 } | |
287 | |
288 | |
289 static ngx_int_t | |
290 ngx_http_memcached_process_header(ngx_http_request_t *r) | |
291 { | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
292 u_char *p, *start; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
293 ngx_str_t line; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
294 ngx_uint_t flags; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
295 ngx_table_elt_t *h; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
296 ngx_http_upstream_t *u; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
297 ngx_http_memcached_ctx_t *ctx; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
298 ngx_http_memcached_loc_conf_t *mlcf; |
581 | 299 |
300 u = r->upstream; | |
301 | |
302 for (p = u->buffer.pos; p < u->buffer.last; p++) { | |
303 if (*p == LF) { | |
304 goto found; | |
305 } | |
306 } | |
307 | |
308 return NGX_AGAIN; | |
309 | |
310 found: | |
311 | |
312 *p = '\0'; | |
313 | |
314 line.len = p - u->buffer.pos - 1; | |
315 line.data = u->buffer.pos; | |
316 | |
317 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
318 "memcached: \"%V\"", &line); | |
319 | |
320 p = u->buffer.pos; | |
321 | |
597 | 322 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
|
323 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); |
597 | 324 |
581 | 325 if (ngx_strncmp(p, "VALUE ", sizeof("VALUE ") - 1) == 0) { |
326 | |
327 p += sizeof("VALUE ") - 1; | |
328 | |
597 | 329 if (ngx_strncmp(p, ctx->key.data, ctx->key.len) != 0) { |
581 | 330 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
331 "memcached sent invalid key in response \"%V\" " | |
332 "for key \"%V\"", | |
597 | 333 &line, &ctx->key); |
581 | 334 |
335 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
336 } | |
337 | |
597 | 338 p += ctx->key.len; |
581 | 339 |
340 if (*p++ != ' ') { | |
341 goto no_valid; | |
342 } | |
343 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
344 /* flags */ |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
345 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
346 start = p; |
581 | 347 |
348 while (*p) { | |
349 if (*p++ == ' ') { | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
350 if (mlcf->gzip_flag) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
351 goto flags; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
352 } else { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
353 goto length; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
354 } |
581 | 355 } |
356 } | |
357 | |
358 goto no_valid; | |
359 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
360 flags: |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
361 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
362 flags = ngx_atoi(start, p - start - 1); |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
363 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
364 if (flags == (ngx_uint_t) NGX_ERROR) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
365 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
|
366 "memcached sent invalid flags in response \"%V\" " |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
367 "for key \"%V\"", |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
368 &line, &ctx->key); |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
369 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
370 } |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
371 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
372 if (flags & mlcf->gzip_flag) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
373 h = ngx_list_push(&r->headers_out.headers); |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
374 if (h == NULL) { |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
375 return NGX_ERROR; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
376 } |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
377 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
378 h->hash = 1; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
379 h->key.len = sizeof("Content-Encoding") - 1; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
380 h->key.data = (u_char *) "Content-Encoding"; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
381 h->value.len = sizeof("gzip") - 1; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
382 h->value.data = (u_char *) "gzip"; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
383 |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
384 r->headers_out.content_encoding = h; |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
385 } |
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
386 |
581 | 387 length: |
388 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
389 start = p; |
581 | 390 |
391 while (*p && *p++ != CR) { /* void */ } | |
392 | |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
393 u->headers_in.content_length_n = ngx_atoof(start, p - start - 1); |
4117
103b0d9afe07
Upstream: content_length_n API change.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3523
diff
changeset
|
394 if (u->headers_in.content_length_n == -1) { |
581 | 395 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
396 "memcached sent invalid length in response \"%V\" " | |
397 "for key \"%V\"", | |
597 | 398 &line, &ctx->key); |
581 | 399 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
400 } | |
401 | |
402 u->headers_in.status_n = 200; | |
1567
31d4278d51c0
memcached did not set $upstream_response_time
Igor Sysoev <igor@sysoev.ru>
parents:
1554
diff
changeset
|
403 u->state->status = 200; |
581 | 404 u->buffer.pos = p + 1; |
405 | |
406 return NGX_OK; | |
407 } | |
408 | |
409 if (ngx_strcmp(p, "END\x0d") == 0) { | |
410 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, | |
597 | 411 "key: \"%V\" was not found by memcached", &ctx->key); |
581 | 412 |
413 u->headers_in.status_n = 404; | |
1567
31d4278d51c0
memcached did not set $upstream_response_time
Igor Sysoev <igor@sysoev.ru>
parents:
1554
diff
changeset
|
414 u->state->status = 404; |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
415 u->keepalive = 1; |
581 | 416 |
417 return NGX_OK; | |
418 } | |
419 | |
420 no_valid: | |
421 | |
422 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
423 "memcached sent invalid response: \"%V\"", &line); | |
424 | |
425 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
426 } | |
427 | |
428 | |
429 static ngx_int_t | |
430 ngx_http_memcached_filter_init(void *data) | |
431 { | |
432 ngx_http_memcached_ctx_t *ctx = data; | |
433 | |
434 ngx_http_upstream_t *u; | |
435 | |
436 u = ctx->request->upstream; | |
437 | |
438 u->length += NGX_HTTP_MEMCACHED_END; | |
439 | |
440 return NGX_OK; | |
441 } | |
442 | |
443 | |
444 static ngx_int_t | |
445 ngx_http_memcached_filter(void *data, ssize_t bytes) | |
446 { | |
447 ngx_http_memcached_ctx_t *ctx = data; | |
448 | |
449 u_char *last; | |
450 ngx_buf_t *b; | |
451 ngx_chain_t *cl, **ll; | |
452 ngx_http_upstream_t *u; | |
453 | |
454 u = ctx->request->upstream; | |
455 b = &u->buffer; | |
456 | |
4118
dbddec65fdab
Upstream: r->upstream->length type change to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4117
diff
changeset
|
457 if (u->length == (ssize_t) ctx->rest) { |
581 | 458 |
459 if (ngx_strncmp(b->last, | |
1548 | 460 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
|
461 bytes) |
1548 | 462 != 0) |
581 | 463 { |
464 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0, | |
465 "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
|
466 |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
467 u->length = 0; |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
468 ctx->rest = 0; |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
469 |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
470 return NGX_OK; |
581 | 471 } |
472 | |
3487
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
473 u->length -= bytes; |
5d2acf153153
revert partially r1555 and fix the error "memcached sent invalid trailer"
Igor Sysoev <igor@sysoev.ru>
parents:
3399
diff
changeset
|
474 ctx->rest -= bytes; |
581 | 475 |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
476 if (u->length == 0) { |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
477 u->keepalive = 1; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
478 } |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
479 |
581 | 480 return NGX_OK; |
481 } | |
482 | |
483 for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) { | |
484 ll = &cl->next; | |
485 } | |
486 | |
487 cl = ngx_chain_get_free_buf(ctx->request->pool, &u->free_bufs); | |
488 if (cl == NULL) { | |
489 return NGX_ERROR; | |
490 } | |
491 | |
492 cl->buf->flush = 1; | |
493 cl->buf->memory = 1; | |
494 | |
495 *ll = cl; | |
496 | |
1554
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
497 last = b->last; |
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
498 cl->buf->pos = last; |
581 | 499 b->last += bytes; |
500 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
|
501 cl->buf->tag = u->output.tag; |
581 | 502 |
503 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, | |
504 "memcached filter bytes:%z size:%z length:%z rest:%z", | |
505 bytes, b->last - b->pos, u->length, ctx->rest); | |
506 | |
1554
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
507 if (bytes <= (ssize_t) (u->length - NGX_HTTP_MEMCACHED_END)) { |
581 | 508 u->length -= bytes; |
509 return NGX_OK; | |
510 } | |
511 | |
1554
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
512 last += u->length - NGX_HTTP_MEMCACHED_END; |
581 | 513 |
514 if (ngx_strncmp(last, ngx_http_memcached_end, b->last - last) != 0) { | |
515 ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0, | |
516 "memcached sent invalid trailer"); | |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
517 |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
518 b->last = last; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
519 cl->buf->last = last; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
520 u->length = 0; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
521 ctx->rest = 0; |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
522 |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
523 return NGX_OK; |
581 | 524 } |
525 | |
1554
30fcc8478d85
two commits those go together by mistake
Igor Sysoev <igor@sysoev.ru>
parents:
1548
diff
changeset
|
526 ctx->rest -= b->last - last; |
581 | 527 b->last = last; |
528 cl->buf->last = last; | |
529 u->length = ctx->rest; | |
530 | |
4121
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
531 if (u->length == 0) { |
16c60162c35b
Keepalive support in memcached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4118
diff
changeset
|
532 u->keepalive = 1; |
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 |
581 | 535 return NGX_OK; |
536 } | |
537 | |
538 | |
539 static void | |
540 ngx_http_memcached_abort_request(ngx_http_request_t *r) | |
541 { | |
542 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
543 "abort http memcached request"); | |
544 return; | |
545 } | |
546 | |
547 | |
548 static void | |
549 ngx_http_memcached_finalize_request(ngx_http_request_t *r, ngx_int_t rc) | |
550 { | |
551 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
552 "finalize http memcached request"); | |
553 return; | |
554 } | |
555 | |
556 | |
557 static void * | |
558 ngx_http_memcached_create_loc_conf(ngx_conf_t *cf) | |
559 { | |
560 ngx_http_memcached_loc_conf_t *conf; | |
561 | |
562 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_memcached_loc_conf_t)); | |
563 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
|
564 return NULL; |
581 | 565 } |
566 | |
567 /* | |
568 * set by ngx_pcalloc(): | |
569 * | |
570 * conf->upstream.bufs.num = 0; | |
571 * conf->upstream.next_upstream = 0; | |
572 * conf->upstream.temp_path = NULL; | |
573 * conf->upstream.uri = { 0, NULL }; | |
574 * conf->upstream.location = NULL; | |
575 */ | |
576 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
4835
diff
changeset
|
577 conf->upstream.local = NGX_CONF_UNSET_PTR; |
581 | 578 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
579 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | |
580 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | |
581 | |
582 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; | |
583 | |
884 | 584 /* the hardcoded values */ |
581 | 585 conf->upstream.cyclic_temp_file = 0; |
629 | 586 conf->upstream.buffering = 0; |
587 conf->upstream.ignore_client_abort = 0; | |
581 | 588 conf->upstream.send_lowat = 0; |
589 conf->upstream.bufs.num = 0; | |
590 conf->upstream.busy_buffers_size = 0; | |
591 conf->upstream.max_temp_file_size = 0; | |
592 conf->upstream.temp_file_write_size = 0; | |
657 | 593 conf->upstream.intercept_errors = 1; |
675 | 594 conf->upstream.intercept_404 = 1; |
581 | 595 conf->upstream.pass_request_headers = 0; |
596 conf->upstream.pass_request_body = 0; | |
597 | |
1787
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
598 conf->index = NGX_CONF_UNSET; |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
599 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
|
600 |
581 | 601 return conf; |
602 } | |
603 | |
604 | |
605 static char * | |
606 ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
607 { | |
608 ngx_http_memcached_loc_conf_t *prev = parent; | |
609 ngx_http_memcached_loc_conf_t *conf = child; | |
610 | |
5008
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
4835
diff
changeset
|
611 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
|
612 prev->upstream.local, NULL); |
fd84344f1df7
Fixed and improved the "*_bind" directives of proxying modules.
Ruslan Ermilov <ru@nginx.com>
parents:
4835
diff
changeset
|
613 |
581 | 614 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, |
615 prev->upstream.connect_timeout, 60000); | |
616 | |
617 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
618 prev->upstream.send_timeout, 60000); | |
619 | |
620 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
621 prev->upstream.read_timeout, 60000); | |
622 | |
623 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
624 prev->upstream.buffer_size, | |
625 (size_t) ngx_pagesize); | |
626 | |
627 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
628 prev->upstream.next_upstream, | |
629 (NGX_CONF_BITMASK_SET | |
630 |NGX_HTTP_UPSTREAM_FT_ERROR | |
631 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
632 | |
665 | 633 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { |
634 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
635 |NGX_HTTP_UPSTREAM_FT_OFF; | |
636 } | |
637 | |
1787
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
638 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
|
639 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
|
640 } |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
641 |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
642 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
|
643 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
|
644 } |
a37fe5ceacc4
inherit $memached_key index and memcached_pass upstream inside "if" block
Igor Sysoev <igor@sysoev.ru>
parents:
1658
diff
changeset
|
645 |
4835
a4512d7737f6
Memcached: memcached_gzip_flag directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4499
diff
changeset
|
646 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
|
647 |
581 | 648 return NGX_CONF_OK; |
649 } | |
650 | |
651 | |
652 static char * | |
653 ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
654 { | |
2392 | 655 ngx_http_memcached_loc_conf_t *mlcf = conf; |
581 | 656 |
657 ngx_str_t *value; | |
807
3095bf59059b
now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
675
diff
changeset
|
658 ngx_url_t u; |
581 | 659 ngx_http_core_loc_conf_t *clcf; |
660 | |
2392 | 661 if (mlcf->upstream.upstream) { |
581 | 662 return "is duplicate"; |
663 } | |
664 | |
665 value = cf->args->elts; | |
666 | |
807
3095bf59059b
now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
675
diff
changeset
|
667 ngx_memzero(&u, sizeof(ngx_url_t)); |
581 | 668 |
807
3095bf59059b
now the "memcached_pass" directive uses ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
675
diff
changeset
|
669 u.url = value[1]; |
884 | 670 u.no_resolve = 1; |
815
b630109560b7
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
807
diff
changeset
|
671 |
2392 | 672 mlcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); |
673 if (mlcf->upstream.upstream == NULL) { | |
884 | 674 return NGX_CONF_ERROR; |
581 | 675 } |
676 | |
677 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
678 | |
679 clcf->handler = ngx_http_memcached_handler; | |
680 | |
681 if (clcf->name.data[clcf->name.len - 1] == '/') { | |
682 clcf->auto_redirect = 1; | |
683 } | |
684 | |
2392 | 685 mlcf->index = ngx_http_get_variable_index(cf, &ngx_http_memcached_key); |
1076 | 686 |
2392 | 687 if (mlcf->index == NGX_ERROR) { |
1076 | 688 return NGX_CONF_ERROR; |
689 } | |
690 | |
581 | 691 return NGX_CONF_OK; |
692 } |