Mercurial > hg > nginx-vendor-0-7
comparison src/http/modules/ngx_http_memcached_module.c @ 146:36af50a5582d NGINX_0_3_20
nginx 0.3.20
*) Bugfix: in SSI handling.
*) Bugfix: the ngx_http_memcached_module did not support the keys in
the "/usr?args" form.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 11 Jan 2006 00:00:00 +0300 |
parents | 82d695e3d662 |
children | 87699398f955 |
comparison
equal
deleted
inserted
replaced
145:85a84f8da62b | 146:36af50a5582d |
---|---|
17 | 17 |
18 | 18 |
19 typedef struct { | 19 typedef struct { |
20 size_t rest; | 20 size_t rest; |
21 ngx_http_request_t *request; | 21 ngx_http_request_t *request; |
22 ngx_str_t key; | |
22 } ngx_http_memcached_ctx_t; | 23 } ngx_http_memcached_ctx_t; |
23 | 24 |
24 | 25 |
25 static ngx_int_t ngx_http_memcached_create_request(ngx_http_request_t *r); | 26 static ngx_int_t ngx_http_memcached_create_request(ngx_http_request_t *r); |
26 static ngx_int_t ngx_http_memcached_reinit_request(ngx_http_request_t *r); | 27 static ngx_int_t ngx_http_memcached_reinit_request(ngx_http_request_t *r); |
200 } | 201 } |
201 | 202 |
202 ctx->rest = NGX_HTTP_MEMCACHED_END; | 203 ctx->rest = NGX_HTTP_MEMCACHED_END; |
203 ctx->request = r; | 204 ctx->request = r; |
204 | 205 |
206 ngx_http_set_ctx(r, ctx, ngx_http_memcached_module); | |
207 | |
205 u->input_filter_init = ngx_http_memcached_filter_init; | 208 u->input_filter_init = ngx_http_memcached_filter_init; |
206 u->input_filter = ngx_http_memcached_filter; | 209 u->input_filter = ngx_http_memcached_filter; |
207 u->input_filter_ctx = ctx; | 210 u->input_filter_ctx = ctx; |
208 | 211 |
209 ngx_http_upstream_init(r); | 212 ngx_http_upstream_init(r); |
213 | 216 |
214 | 217 |
215 static ngx_int_t | 218 static ngx_int_t |
216 ngx_http_memcached_create_request(ngx_http_request_t *r) | 219 ngx_http_memcached_create_request(ngx_http_request_t *r) |
217 { | 220 { |
218 size_t len; | 221 size_t len; |
219 ngx_buf_t *b; | 222 ngx_buf_t *b; |
220 ngx_chain_t *cl; | 223 ngx_chain_t *cl; |
224 ngx_http_memcached_ctx_t *ctx; | |
221 | 225 |
222 len = sizeof("get ") - 1 + r->uri.len + sizeof(" " CRLF) - 1; | 226 len = sizeof("get ") - 1 + r->uri.len + sizeof(" " CRLF) - 1; |
223 if (r->args.len) { | 227 if (r->args.len) { |
224 len += 1+ r->args.len; | 228 len += 1 + r->args.len; |
225 } | 229 } |
226 | 230 |
227 b = ngx_create_temp_buf(r->pool, len); | 231 b = ngx_create_temp_buf(r->pool, len); |
228 if (b == NULL) { | 232 if (b == NULL) { |
229 return NGX_ERROR; | 233 return NGX_ERROR; |
239 | 243 |
240 r->upstream->request_bufs = cl; | 244 r->upstream->request_bufs = cl; |
241 | 245 |
242 *b->last++ = 'g'; *b->last++ = 'e'; *b->last++ = 't'; *b->last++ = ' '; | 246 *b->last++ = 'g'; *b->last++ = 'e'; *b->last++ = 't'; *b->last++ = ' '; |
243 | 247 |
248 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); | |
249 | |
250 ctx->key.data = b->last; | |
251 | |
244 b->last = ngx_copy(b->last, r->uri.data, r->uri.len); | 252 b->last = ngx_copy(b->last, r->uri.data, r->uri.len); |
245 | 253 |
246 if (r->args.len) { | 254 if (r->args.len) { |
247 *b->last++ = '?'; | 255 *b->last++ = '?'; |
248 b->last = ngx_copy(b->last, r->args.data, r->args.len); | 256 b->last = ngx_copy(b->last, r->args.data, r->args.len); |
249 } | 257 } |
250 | 258 |
251 #if (NGX_DEBUG) | 259 ctx->key.len = b->last - ctx->key.data; |
252 { | 260 |
253 ngx_str_t s; | |
254 | |
255 s.len = b->last - b->pos; | |
256 s.data = b->pos; | |
257 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 261 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
258 "http memcached request: \"%V\"", &s); | 262 "http memcached request: \"%V\"", &ctx->key); |
259 } | |
260 #endif | |
261 | 263 |
262 *b->last++ = ' '; *b->last++ = CR; *b->last++ = LF; | 264 *b->last++ = ' '; *b->last++ = CR; *b->last++ = LF; |
263 | 265 |
264 return NGX_OK; | 266 return NGX_OK; |
265 } | 267 } |
273 | 275 |
274 | 276 |
275 static ngx_int_t | 277 static ngx_int_t |
276 ngx_http_memcached_process_header(ngx_http_request_t *r) | 278 ngx_http_memcached_process_header(ngx_http_request_t *r) |
277 { | 279 { |
278 u_char *p, *len; | 280 u_char *p, *len; |
279 ngx_str_t line; | 281 ngx_str_t line; |
280 ngx_http_upstream_t *u; | 282 ngx_http_upstream_t *u; |
283 ngx_http_memcached_ctx_t *ctx; | |
281 | 284 |
282 u = r->upstream; | 285 u = r->upstream; |
283 | 286 |
284 for (p = u->buffer.pos; p < u->buffer.last; p++) { | 287 for (p = u->buffer.pos; p < u->buffer.last; p++) { |
285 if (*p == LF) { | 288 if (*p == LF) { |
299 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 302 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
300 "memcached: \"%V\"", &line); | 303 "memcached: \"%V\"", &line); |
301 | 304 |
302 p = u->buffer.pos; | 305 p = u->buffer.pos; |
303 | 306 |
307 ctx = ngx_http_get_module_ctx(r, ngx_http_memcached_module); | |
308 | |
304 if (ngx_strncmp(p, "VALUE ", sizeof("VALUE ") - 1) == 0) { | 309 if (ngx_strncmp(p, "VALUE ", sizeof("VALUE ") - 1) == 0) { |
305 | 310 |
306 p += sizeof("VALUE ") - 1; | 311 p += sizeof("VALUE ") - 1; |
307 | 312 |
308 if (ngx_strncmp(p, r->uri.data, r->uri.len) != 0) { | 313 if (ngx_strncmp(p, ctx->key.data, ctx->key.len) != 0) { |
309 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 314 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
310 "memcached sent invalid key in response \"%V\" " | 315 "memcached sent invalid key in response \"%V\" " |
311 "for key \"%V\"", | 316 "for key \"%V\"", |
312 &line, &r->uri); | 317 &line, &ctx->key); |
313 | 318 |
314 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | 319 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
315 } | 320 } |
316 | 321 |
317 p += r->uri.len; | 322 p += ctx->key.len; |
318 | 323 |
319 if (*p++ != ' ') { | 324 if (*p++ != ' ') { |
320 goto no_valid; | 325 goto no_valid; |
321 } | 326 } |
322 | 327 |
339 r->headers_out.content_length_n = ngx_atoof(len, p - len - 1); | 344 r->headers_out.content_length_n = ngx_atoof(len, p - len - 1); |
340 if (r->headers_out.content_length_n == -1) { | 345 if (r->headers_out.content_length_n == -1) { |
341 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 346 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
342 "memcached sent invalid length in response \"%V\" " | 347 "memcached sent invalid length in response \"%V\" " |
343 "for key \"%V\"", | 348 "for key \"%V\"", |
344 &line, &r->uri); | 349 &line, &ctx->key); |
345 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | 350 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
346 } | 351 } |
347 | 352 |
348 u->headers_in.status_n = 200; | 353 u->headers_in.status_n = 200; |
349 u->buffer.pos = p + 1; | 354 u->buffer.pos = p + 1; |
351 return NGX_OK; | 356 return NGX_OK; |
352 } | 357 } |
353 | 358 |
354 if (ngx_strcmp(p, "END\x0d") == 0) { | 359 if (ngx_strcmp(p, "END\x0d") == 0) { |
355 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, | 360 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, |
356 "key: \"%V\" was not found by memcached", &r->uri); | 361 "key: \"%V\" was not found by memcached", &ctx->key); |
357 | 362 |
358 u->headers_in.status_n = 404; | 363 u->headers_in.status_n = 404; |
359 | 364 |
360 return NGX_OK; | 365 return NGX_OK; |
361 } | 366 } |