diff src/http/ngx_http_variables.c @ 571:458b6c3fea65 release-0.3.7

nginx-0.3.7-RELEASE import *) Feature: the "access_log" supports the "buffer=" parameter. *) Bugfix: nginx could not be built on platforms different from i386, amd64, sparc, and ppc; the bug had appeared in 0.3.2.
author Igor Sysoev <igor@sysoev.ru>
date Thu, 27 Oct 2005 15:46:13 +0000
parents 174f1e853e1e
children 58475592100c
line wrap: on
line diff
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -36,6 +36,8 @@ static ngx_http_variable_value_t *
     ngx_http_variable_request_method(ngx_http_request_t *r, uintptr_t data);
 static ngx_http_variable_value_t *
     ngx_http_variable_remote_user(ngx_http_request_t *r, uintptr_t data);
+static ngx_http_variable_value_t *
+    ngx_http_variable_sent(ngx_http_request_t *r, uintptr_t data);
 
 
 /*
@@ -44,8 +46,7 @@ static ngx_http_variable_value_t *
  *                 REMOTE_HOST (null), REMOTE_IDENT (null),
  *                 SERVER_SOFTWARE
  *
- *     Apache SSI: DATE_GMT, DOCUMENT_NAME, LAST_MODIFIED,
- *                 USER_NAME (file owner)
+ *     Apache SSI: DOCUMENT_NAME, LAST_MODIFIED, USER_NAME (file owner)
  */
 
 static ngx_http_variable_t  ngx_http_core_variables[] = {
@@ -116,6 +117,10 @@ static ngx_http_variable_t  ngx_http_cor
 
     { ngx_string("remote_user"), ngx_http_variable_remote_user, 0, 0, 0 },
 
+    { ngx_string("sent"), ngx_http_variable_sent, 0, 0, 0 },
+
+    { ngx_string("apache_sent"), ngx_http_variable_sent, 1, 0, 0 },
+
     { ngx_null_string, NULL, 0, 0, 0 }
 };
 
@@ -699,6 +704,41 @@ ngx_http_variable_remote_user(ngx_http_r
 }
 
 
+static ngx_http_variable_value_t *
+ngx_http_variable_sent(ngx_http_request_t *r, uintptr_t data)
+{
+    off_t                       sent;
+    u_char                     *p;
+    ngx_http_variable_value_t  *vv;
+
+    vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+    if (vv == NULL) {
+        return NULL;
+    }
+
+    sent = r->connection->sent;
+
+    if (data) {
+        sent -= r->header_size;
+
+        if (sent < 0) {
+            sent = 0;
+        }
+    }
+
+    p = ngx_palloc(r->pool, NGX_OFF_T_LEN);
+    if (p == NULL) {
+        return NULL;
+    }
+
+    vv->value = 0;
+    vv->text.len = ngx_sprintf(p, "%O", sent) - p;
+    vv->text.data = p;
+
+    return vv;
+}
+
+
 ngx_int_t
 ngx_http_variables_add_core_vars(ngx_conf_t *cf)
 {