Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

feature: allow use of the request body data in nginx variables for ma…

…in requests by always reading the request body. we used to always discard the request body just like the standard ngx_memcached module. thanks Ristona Hua for sharing this usage.
  • Loading branch information...
commit 997497529ce0ab2861660a3d2a0b61bc26f0fff8 1 parent 1e14554
@agentzh agentzh authored
Showing with 29 additions and 9 deletions.
  1. +4 −8 src/ngx_http_redis2_handler.c
  2. +25 −1 t/sanity.t
View
12 src/ngx_http_redis2_handler.c
@@ -28,12 +28,6 @@ ngx_http_redis2_handler(ngx_http_request_t *r)
ngx_str_t target;
ngx_url_t url;
- rc = ngx_http_discard_request_body(r);
-
- if (rc != NGX_OK) {
- return rc;
- }
-
if (ngx_http_set_content_type(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -101,9 +95,11 @@ ngx_http_redis2_handler(ngx_http_request_t *r)
u->input_filter = ngx_http_redis2_filter;
u->input_filter_ctx = ctx;
- r->main->count++;
+ rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
- ngx_http_upstream_init(r);
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
+ return rc;
+ }
return NGX_DONE;
}
View
26 t/sanity.t
@@ -5,7 +5,7 @@ use Test::Nginx::Socket;
repeat_each(2);
-plan tests => repeat_each() * 2 * blocks();
+plan tests => repeat_each() * (2 * blocks() + 1);
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
@@ -449,3 +449,27 @@ probe end {
--- response_body eval
"+OK\r\n\$5\r\nworld\r\n"
+
+
+=== TEST 20: request body
+--- config
+ location /t {
+ # these two settings must be the same to prevent
+ # automatic buffering large request bodies
+ # to temp files:
+ client_body_buffer_size 8k;
+ client_max_body_size 8k;
+
+ redis2_query flushall;
+ redis2_query lpush q1 $echo_request_body;
+ redis2_query lpop q1;
+ redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
+ }
+--- request
+POST /t
+hello world
+--- response_body eval
+"+OK\r\n:1\r\n\$11\r\nhello world\r\n"
+--- no_error_log
+[error]
+
Please sign in to comment.
Something went wrong with that request. Please try again.