comparison src/http/ngx_http_variables.c @ 501:98143f74eb3d NGINX_0_7_58

nginx 0.7.58 *) Feature: a "listen" directive of the mail proxy module supports IPv6. *) Feature: the "image_filter_jpeg_quality" directive. *) Feature: the "client_body_in_single_buffer" directive. *) Feature: the $request_body variable. *) Bugfix: in ngx_http_autoindex_module in file name links having a ":" symbol in the name. *) Bugfix: "make upgrade" procedure did not work; the bug had appeared in 0.7.53. Thanks to Denis F. Latypoff.
author Igor Sysoev <http://sysoev.ru>
date Mon, 18 May 2009 00:00:00 +0400
parents a8424ffa495c
children 499474178a11
comparison
equal deleted inserted replaced
500:bb2281a3edb6 501:98143f74eb3d
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,
930 u_char addr[NGX_SOCKADDR_STRLEN]; 936 u_char addr[NGX_SOCKADDR_STRLEN];
931 937
932 s.len = NGX_SOCKADDR_STRLEN; 938 s.len = NGX_SOCKADDR_STRLEN;
933 s.data = addr; 939 s.data = addr;
934 940
935 if (ngx_http_server_addr(r, &s) != NGX_OK) { 941 if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) {
936 return NGX_ERROR; 942 return NGX_ERROR;
937 } 943 }
938 944
939 s.data = ngx_pnalloc(r->pool, s.len); 945 s.data = ngx_pnalloc(r->pool, s.len);
940 if (s.data == NULL) { 946 if (s.data == NULL) {
966 v->len = 0; 972 v->len = 0;
967 v->valid = 1; 973 v->valid = 1;
968 v->no_cacheable = 0; 974 v->no_cacheable = 0;
969 v->not_found = 0; 975 v->not_found = 0;
970 976
971 if (ngx_http_server_addr(r, NULL) != NGX_OK) { 977 if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) {
972 return NGX_ERROR; 978 return NGX_ERROR;
973 } 979 }
974 980
975 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); 981 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
976 if (v->data == NULL) { 982 if (v->data == NULL) {
1470 v->len = 0; 1476 v->len = 0;
1471 v->valid = 1; 1477 v->valid = 1;
1472 v->no_cacheable = 0; 1478 v->no_cacheable = 0;
1473 v->not_found = 0; 1479 v->not_found = 0;
1474 v->data = (u_char *) ""; 1480 v->data = (u_char *) "";
1481
1482 return NGX_OK;
1483 }
1484
1485
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;
1475 1531
1476 return NGX_OK; 1532 return NGX_OK;
1477 } 1533 }
1478 1534
1479 1535