aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-05-14 11:40:51 +0000
committerIgor Sysoev <igor@sysoev.ru>2009-05-14 11:40:51 +0000
commitff07f319c9e992ffbf2fde78ad278eb519e534d5 (patch)
tree0005270661179a96280d57eccabdcd052f2776a1 /src
parente6460ea7bb407f078bf537776a55d2626d8067c4 (diff)
downloadnginx-ff07f319c9e992ffbf2fde78ad278eb519e534d5.tar.gz
nginx-ff07f319c9e992ffbf2fde78ad278eb519e534d5.zip
$request_body variable
Diffstat (limited to 'src')
-rw-r--r--src/http/ngx_http_variables.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index 0c46c35fa..dd28888fa 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -62,6 +62,8 @@ static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
@@ -202,6 +204,10 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
ngx_http_variable_request_completion,
0, 0, 0 },
+ { ngx_string("request_body"), NULL,
+ ngx_http_variable_request_body,
+ 0, 0, 0 },
+
{ ngx_string("request_body_file"), NULL,
ngx_http_variable_request_body_file,
0, 0, 0 },
@@ -1478,6 +1484,56 @@ ngx_http_variable_request_completion(ngx_http_request_t *r,
static ngx_int_t
+ngx_http_variable_request_body(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ u_char *p;
+ size_t len;
+ ngx_buf_t *buf, *next;
+ ngx_chain_t *cl;
+
+ if (r->request_body == NULL || r->request_body->temp_file) {
+ v->not_found = 1;
+
+ return NGX_OK;
+ }
+
+ cl = r->request_body->bufs;
+ buf = cl->buf;
+
+ if (cl->next == NULL) {
+ v->len = buf->last - buf->pos;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+ v->data = buf->pos;
+
+ return NGX_OK;
+ }
+
+ next = cl->next->buf;
+ len = (buf->last - buf->pos) + (next->last - next->pos);
+
+ p = ngx_pnalloc(r->pool, len);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ v->data = p;
+
+ p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
+ ngx_memcpy(p, next->pos, next->last - next->pos);
+
+ v->len = len;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_http_variable_request_body_file(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{