comparison src/http/modules/ngx_http_memcached_module.c @ 1333:07ebeeb55700

escape space, etc in $memcached_key
author Igor Sysoev <igor@sysoev.ru>
date Sun, 22 Jul 2007 19:18:59 +0000
parents 483f0cd87acf
children cc114c85be0f
comparison
equal deleted inserted replaced
1332:483f0cd87acf 1333:07ebeeb55700
224 224
225 static ngx_int_t 225 static ngx_int_t
226 ngx_http_memcached_create_request(ngx_http_request_t *r) 226 ngx_http_memcached_create_request(ngx_http_request_t *r)
227 { 227 {
228 size_t len; 228 size_t len;
229 uintptr_t escape;
229 ngx_buf_t *b; 230 ngx_buf_t *b;
230 ngx_chain_t *cl; 231 ngx_chain_t *cl;
231 ngx_http_memcached_ctx_t *ctx; 232 ngx_http_memcached_ctx_t *ctx;
232 ngx_http_variable_value_t *vv; 233 ngx_http_variable_value_t *vv;
233 ngx_http_memcached_loc_conf_t *mlcf; 234 ngx_http_memcached_loc_conf_t *mlcf;
240 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 241 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
241 "the \"$memcached_key\" variable is not set"); 242 "the \"$memcached_key\" variable is not set");
242 return NGX_ERROR; 243 return NGX_ERROR;
243 } 244 }
244 245
245 len = sizeof("get ") - 1 + vv->len + sizeof(CRLF) - 1; 246 escape = 2 * ngx_escape_uri(NULL, vv->data, vv->len, NGX_ESCAPE_MEMCACHED);
247
248 len = sizeof("get ") - 1 + vv->len + escape + sizeof(CRLF) - 1;
246 249
247 b = ngx_create_temp_buf(r->pool, len); 250 b = ngx_create_temp_buf(r->pool, len);
248 if (b == NULL) { 251 if (b == NULL) {
249 return NGX_ERROR; 252 return NGX_ERROR;
250 } 253 }
263 266
264 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); 267 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module);
265 268
266 ctx->key.data = b->last; 269 ctx->key.data = b->last;
267 270
268 b->last = ngx_copy(b->last, vv->data, vv->len); 271 if (escape == 0) {
272 b->last = ngx_copy(b->last, vv->data, vv->len);
273
274 } else {
275 b->last = (u_char *) ngx_escape_uri(b->last, vv->data, vv->len,
276 NGX_ESCAPE_MEMCACHED);
277 }
269 278
270 ctx->key.len = b->last - ctx->key.data; 279 ctx->key.len = b->last - ctx->key.data;
271 280
272 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 281 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
273 "http memcached request: \"%V\"", &ctx->key); 282 "http memcached request: \"%V\"", &ctx->key);