comparison src/http/ngx_http_variables.c @ 2844:2f3c80ff2123

$request_body variable
author Igor Sysoev <igor@sysoev.ru>
date Thu, 14 May 2009 11:40:51 +0000
parents 051e9b12428e
children 507fc5ac9839
comparison
equal deleted inserted replaced
2843:eb461016d980 2844:2f3c80ff2123
59 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r, 59 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r,
60 ngx_http_variable_value_t *v, uintptr_t data); 60 ngx_http_variable_value_t *v, uintptr_t data);
61 static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, 61 static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r,
62 ngx_http_variable_value_t *v, uintptr_t data); 62 ngx_http_variable_value_t *v, uintptr_t data);
63 static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r, 63 static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r,
64 ngx_http_variable_value_t *v, uintptr_t data);
65 static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
64 ngx_http_variable_value_t *v, uintptr_t data); 66 ngx_http_variable_value_t *v, uintptr_t data);
65 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r, 67 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
66 ngx_http_variable_value_t *v, uintptr_t data); 68 ngx_http_variable_value_t *v, uintptr_t data);
67 69
68 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r, 70 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r,
200 202
201 { ngx_string("request_completion"), NULL, 203 { ngx_string("request_completion"), NULL,
202 ngx_http_variable_request_completion, 204 ngx_http_variable_request_completion,
203 0, 0, 0 }, 205 0, 0, 0 },
204 206
207 { ngx_string("request_body"), NULL,
208 ngx_http_variable_request_body,
209 0, 0, 0 },
210
205 { ngx_string("request_body_file"), NULL, 211 { ngx_string("request_body_file"), NULL,
206 ngx_http_variable_request_body_file, 212 ngx_http_variable_request_body_file,
207 0, 0, 0 }, 213 0, 0, 0 },
208 214
209 { ngx_string("sent_http_content_type"), NULL, 215 { ngx_string("sent_http_content_type"), NULL,
1476 return NGX_OK; 1482 return NGX_OK;
1477 } 1483 }
1478 1484
1479 1485
1480 static ngx_int_t 1486 static ngx_int_t
1487 ngx_http_variable_request_body(ngx_http_request_t *r,
1488 ngx_http_variable_value_t *v, uintptr_t data)
1489 {
1490 u_char *p;
1491 size_t len;
1492 ngx_buf_t *buf, *next;
1493 ngx_chain_t *cl;
1494
1495 if (r->request_body == NULL || r->request_body->temp_file) {
1496 v->not_found = 1;
1497
1498 return NGX_OK;
1499 }
1500
1501 cl = r->request_body->bufs;
1502 buf = cl->buf;
1503
1504 if (cl->next == NULL) {
1505 v->len = buf->last - buf->pos;
1506 v->valid = 1;
1507 v->no_cacheable = 0;
1508 v->not_found = 0;
1509 v->data = buf->pos;
1510
1511 return NGX_OK;
1512 }
1513
1514 next = cl->next->buf;
1515 len = (buf->last - buf->pos) + (next->last - next->pos);
1516
1517 p = ngx_pnalloc(r->pool, len);
1518 if (p == NULL) {
1519 return NGX_ERROR;
1520 }
1521
1522 v->data = p;
1523
1524 p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
1525 ngx_memcpy(p, next->pos, next->last - next->pos);
1526
1527 v->len = len;
1528 v->valid = 1;
1529 v->no_cacheable = 0;
1530 v->not_found = 0;
1531
1532 return NGX_OK;
1533 }
1534
1535
1536 static ngx_int_t
1481 ngx_http_variable_request_body_file(ngx_http_request_t *r, 1537 ngx_http_variable_request_body_file(ngx_http_request_t *r,
1482 ngx_http_variable_value_t *v, uintptr_t data) 1538 ngx_http_variable_value_t *v, uintptr_t data)
1483 { 1539 {
1484 if (r->request_body == NULL || r->request_body->temp_file == NULL) { 1540 if (r->request_body == NULL || r->request_body->temp_file == NULL) {
1485 v->not_found = 1; 1541 v->not_found = 1;