Klaus Demo nginx / 3dc4fdf
$memcached_key Igor Sysoev 15 years ago
1 changed file(s) with 32 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
1111
1212 typedef struct {
1313 ngx_http_upstream_conf_t upstream;
14 ngx_int_t index;
1415 } ngx_http_memcached_loc_conf_t;
1516
1617
146147 };
147148
148149
150 static ngx_str_t ngx_http_memcached_key = ngx_string("memcached_key");
151
152
149153 #define NGX_HTTP_MEMCACHED_END (sizeof(ngx_http_memcached_end) - 1)
150154 static u_char ngx_http_memcached_end[] = CRLF "END" CRLF;
151155
220224 static ngx_int_t
221225 ngx_http_memcached_create_request(ngx_http_request_t *r)
222226 {
223 size_t len;
224 ngx_buf_t *b;
225 ngx_chain_t *cl;
226 ngx_http_memcached_ctx_t *ctx;
227
228 len = sizeof("get ") - 1 + r->uri.len + sizeof(" " CRLF) - 1;
229 if (r->args.len) {
230 len += 1 + r->args.len;
227 size_t len;
228 ngx_buf_t *b;
229 ngx_chain_t *cl;
230 ngx_http_memcached_ctx_t *ctx;
231 ngx_http_variable_value_t *vv;
232 ngx_http_memcached_loc_conf_t *mlcf;
233
234 mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);
235
236 vv = ngx_http_get_indexed_variable(r, mlcf->index);
237
238 if (vv == NULL || vv->not_found || vv->len == 0) {
239 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
240 "the \"$memcached_key\" variable is not set");
241 return NGX_ERROR;
242 }
243
244 len = sizeof("get ") - 1 + vv->len + sizeof(" " CRLF) - 1;
245 if (vv->len) {
246 len += 1 + vv->len;
231247 }
232248
233249 b = ngx_create_temp_buf(r->pool, len);
251267
252268 ctx->key.data = b->last;
253269
254 b->last = ngx_copy(b->last, r->uri.data, r->uri.len);
255
256 if (r->args.len) {
257 *b->last++ = '?';
258 b->last = ngx_copy(b->last, r->args.data, r->args.len);
259 }
270 b->last = ngx_copy(b->last, vv->data, vv->len);
260271
261272 ctx->key.len = b->last - ctx->key.data;
262273
503514 * conf->upstream.uri = { 0, NULL };
504515 * conf->upstream.location = NULL;
505516 *
506 * conf->peers = NULL;
517 * conf->index = 0;
507518 */
508519
509520 conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
603614 clcf->auto_redirect = 1;
604615 }
605616
617 lcf->index = ngx_http_get_variable_index(cf, &ngx_http_memcached_key);
618
619 if (lcf->index == NGX_ERROR) {
620 return NGX_CONF_ERROR;
621 }
622
606623 return NGX_CONF_OK;
607624 }
608625