<HTML><BODY>Index: src/http/ngx_http_variables.c<br>===================================================================<br>--- src/http/ngx_http_variables.c    (revision 4872)<br>+++ src/http/ngx_http_variables.c    (working copy)<br>@@ -487,12 +487,14 @@<br>         } else {<br> <br>             vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));<br>-<br>-            if (vv && v->get_handler(r, vv, v->data) == NGX_OK) {<br>-                return vv;<br>+            if (vv) {<br>+                <br>+                vv->len = 0;<br>+                if (v->get_handler(r, vv, v->data) != NGX_OK) {<br>+                    vv = NULL;<br>+                }<br>             }<br>-<br>-            return NULL;<br>+            return vv;<br>         }<br>     }<br> <br>Index: src/http/modules/ngx_http_log_module.c<br>===================================================================<br>--- src/http/modules/ngx_http_log_module.c    (revision 4872)<br>+++ src/http/modules/ngx_http_log_module.c    (working copy)<br>@@ -114,6 +114,7 @@<br> static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf);<br> static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent,<br>     void *child);<br>+static ngx_int_t ngx_http_log_add_variables(ngx_conf_t *cf);<br> static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,<br>     void *conf);<br> static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,<br>@@ -154,7 +155,7 @@<br> <br> <br> static ngx_http_module_t  ngx_http_log_module_ctx = {<br>-    NULL,                                  /* preconfiguration */<br>+    ngx_http_log_add_variables,            /* preconfiguration */<br>     ngx_http_log_init,                     /* postconfiguration */<br> <br>     ngx_http_log_create_main_conf,         /* create main configuration */<br>@@ -1338,6 +1339,70 @@<br> <br> <br> static ngx_int_t<br>+ngx_http_log_get_variable(ngx_http_request_t *r, ngx_variable_value_t *value, uintptr_t data)<br>+{<br>+    ngx_http_log_var_t *v;<br>+<br>+    v = (ngx_http_log_var_t *)data;<br>+<br>+    if (!value->len) {<br>+        value->data = ngx_pnalloc(r->pool, v->len);<br>+        if (value->data == NULL) {<br>+            return NGX_ERROR;<br>+        }<br>+    }<br>+<br>+    value->len = v->run(r, value->data, NULL) - value->data;<br>+    <br>+    value->not_found = 0;<br>+    value->valid = 1;<br>+<br>+    return NGX_OK;<br>+}<br>+<br>+<br>+static ngx_int_t<br>+ngx_http_log_add_variables(ngx_conf_t *cf)<br>+{<br>+    ngx_http_log_var_t *v;<br>+    ngx_http_variable_t *var;<br>+    ngx_http_core_main_conf_t *cmcf;<br>+<br>+    ngx_int_t rc;<br>+<br>+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);<br>+    <br>+    var = NULL;<br>+<br>+    for (v = ngx_http_log_vars; v->name.len; v++) {<br>+<br>+        if (var == NULL) {<br>+            var = ngx_pcalloc(cf->pool, sizeof(ngx_http_variable_t));<br>+            if (var == NULL) {<br>+                return NGX_ERROR;<br>+            }<br>+        }<br>+<br>+        var->name = v->name;<br>+        <br>+        rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, var,<br>+                              NGX_HASH_READONLY_KEY);<br>+<br>+        if (rc == NGX_BUSY) {<br>+            continue;<br>+        }<br>+<br>+        var->get_handler = ngx_http_log_get_variable;<br>+        var->data = (uintptr_t)v;<br>+        var->flags = NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE;<br>+<br>+        var = NULL;<br>+    }<br>+<br>+    return NGX_OK;<br>+}<br>+        <br>+static ngx_int_t<br> ngx_http_log_init(ngx_conf_t *cf)<br> {<br>     ngx_str_t                  *value;</BODY></HTML>