Mercurial > hg > nginx-vendor-0-7
comparison src/http/modules/ngx_http_memcached_module.c @ 278:704622b2528a NGINX_0_5_9
nginx 0.5.9
*) Change: now the ngx_http_memcached_module uses the $memcached_key
variable value as a key.
*) Feature: the $memcached_key variable.
*) Feature: the "clean" parameter in the "client_body_in_file_only"
directive.
*) Feature: the "env" directive.
*) Feature: the "sendfile" directive is available inside the "if" block.
*) Feature: now on failure of the writing to access nginx logs a
message to error_log, but not more often than once a minute.
*) Bugfix: the "access_log off" directive did not always turn off the
logging.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 25 Jan 2007 00:00:00 +0300 |
parents | 251bcd11a5b8 |
children | 675a39fd14cd |
comparison
equal
deleted
inserted
replaced
277:b3aec7787b8e | 278:704622b2528a |
---|---|
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 | 11 |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 ngx_http_upstream_conf_t upstream; | 14 ngx_http_upstream_conf_t upstream; |
15 ngx_int_t index; | |
15 } ngx_http_memcached_loc_conf_t; | 16 } ngx_http_memcached_loc_conf_t; |
16 | 17 |
17 | 18 |
18 typedef struct { | 19 typedef struct { |
19 size_t rest; | 20 size_t rest; |
145 NULL, /* exit master */ | 146 NULL, /* exit master */ |
146 NGX_MODULE_V1_PADDING | 147 NGX_MODULE_V1_PADDING |
147 }; | 148 }; |
148 | 149 |
149 | 150 |
151 static ngx_str_t ngx_http_memcached_key = ngx_string("memcached_key"); | |
152 | |
153 | |
150 #define NGX_HTTP_MEMCACHED_END (sizeof(ngx_http_memcached_end) - 1) | 154 #define NGX_HTTP_MEMCACHED_END (sizeof(ngx_http_memcached_end) - 1) |
151 static u_char ngx_http_memcached_end[] = CRLF "END" CRLF; | 155 static u_char ngx_http_memcached_end[] = CRLF "END" CRLF; |
152 | 156 |
153 | 157 |
154 static ngx_int_t | 158 static ngx_int_t |
219 | 223 |
220 | 224 |
221 static ngx_int_t | 225 static ngx_int_t |
222 ngx_http_memcached_create_request(ngx_http_request_t *r) | 226 ngx_http_memcached_create_request(ngx_http_request_t *r) |
223 { | 227 { |
224 size_t len; | 228 size_t len; |
225 ngx_buf_t *b; | 229 ngx_buf_t *b; |
226 ngx_chain_t *cl; | 230 ngx_chain_t *cl; |
227 ngx_http_memcached_ctx_t *ctx; | 231 ngx_http_memcached_ctx_t *ctx; |
228 | 232 ngx_http_variable_value_t *vv; |
229 len = sizeof("get ") - 1 + r->uri.len + sizeof(" " CRLF) - 1; | 233 ngx_http_memcached_loc_conf_t *mlcf; |
230 if (r->args.len) { | 234 |
231 len += 1 + r->args.len; | 235 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module); |
236 | |
237 vv = ngx_http_get_indexed_variable(r, mlcf->index); | |
238 | |
239 if (vv == NULL || vv->not_found || vv->len == 0) { | |
240 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
241 "the \"$memcached_key\" variable is not set"); | |
242 return NGX_ERROR; | |
243 } | |
244 | |
245 len = sizeof("get ") - 1 + vv->len + sizeof(" " CRLF) - 1; | |
246 if (vv->len) { | |
247 len += 1 + vv->len; | |
232 } | 248 } |
233 | 249 |
234 b = ngx_create_temp_buf(r->pool, len); | 250 b = ngx_create_temp_buf(r->pool, len); |
235 if (b == NULL) { | 251 if (b == NULL) { |
236 return NGX_ERROR; | 252 return NGX_ERROR; |
250 | 266 |
251 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); | 267 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); |
252 | 268 |
253 ctx->key.data = b->last; | 269 ctx->key.data = b->last; |
254 | 270 |
255 b->last = ngx_copy(b->last, r->uri.data, r->uri.len); | 271 b->last = ngx_copy(b->last, vv->data, vv->len); |
256 | |
257 if (r->args.len) { | |
258 *b->last++ = '?'; | |
259 b->last = ngx_copy(b->last, r->args.data, r->args.len); | |
260 } | |
261 | 272 |
262 ctx->key.len = b->last - ctx->key.data; | 273 ctx->key.len = b->last - ctx->key.data; |
263 | 274 |
264 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 275 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
265 "http memcached request: \"%V\"", &ctx->key); | 276 "http memcached request: \"%V\"", &ctx->key); |
502 * conf->upstream.temp_path = NULL; | 513 * conf->upstream.temp_path = NULL; |
503 * conf->upstream.schema = { 0, NULL }; | 514 * conf->upstream.schema = { 0, NULL }; |
504 * conf->upstream.uri = { 0, NULL }; | 515 * conf->upstream.uri = { 0, NULL }; |
505 * conf->upstream.location = NULL; | 516 * conf->upstream.location = NULL; |
506 * | 517 * |
507 * conf->peers = NULL; | 518 * conf->index = 0; |
508 */ | 519 */ |
509 | 520 |
510 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; | 521 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC; |
511 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; | 522 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; |
512 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; | 523 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; |
602 | 613 |
603 if (clcf->name.data[clcf->name.len - 1] == '/') { | 614 if (clcf->name.data[clcf->name.len - 1] == '/') { |
604 clcf->auto_redirect = 1; | 615 clcf->auto_redirect = 1; |
605 } | 616 } |
606 | 617 |
618 lcf->index = ngx_http_get_variable_index(cf, &ngx_http_memcached_key); | |
619 | |
620 if (lcf->index == NGX_ERROR) { | |
621 return NGX_CONF_ERROR; | |
622 } | |
623 | |
607 return NGX_CONF_OK; | 624 return NGX_CONF_OK; |
608 } | 625 } |
609 | 626 |
610 | 627 |
611 static char * | 628 static char * |