<div dir="ltr">Hello,<div><br></div><div>We are using such variable for more than a year, and I suggest to add ability to extract request_id from header. It's very usefull for systems with frontend and backend installed on different servers.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 7:38 PM, Vladimir Homutov <span dir="ltr"><<a href="mailto:vl@nginx.com" target="_blank">vl@nginx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">details:   <a href="http://hg.nginx.org/nginx/rev/59f8f2dd8b31" rel="noreferrer" target="_blank">http://hg.nginx.org/nginx/rev/59f8f2dd8b31</a><br>
branches:<br>
changeset: 6531:59f8f2dd8b31<br>
user:      Vladimir Homutov <<a href="mailto:vl@nginx.com">vl@nginx.com</a>><br>
date:      Tue Apr 26 19:31:46 2016 +0300<br>
description:<br>
Variable $request_id.<br>
<br>
The variable contains text representation based on random data, usable as<br>
a unique request identifier.<br>
<br>
diffstat:<br>
<br>
 src/http/ngx_http_variables.c |  47 +++++++++++++++++++++++++++++++++++++++++++<br>
 1 files changed, 47 insertions(+), 0 deletions(-)<br>
<br>
diffs (71 lines):<br>
<br>
diff -r 1d0e03db9f8e -r 59f8f2dd8b31 src/http/ngx_http_variables.c<br>
--- a/src/http/ngx_http_variables.c     Fri Dec 18 19:05:27 2015 +0300<br>
+++ b/src/http/ngx_http_variables.c     Tue Apr 26 19:31:46 2016 +0300<br>
@@ -98,6 +98,8 @@ static ngx_int_t ngx_http_variable_reque<br>
     ngx_http_variable_value_t *v, uintptr_t data);<br>
 static ngx_int_t ngx_http_variable_request_time(ngx_http_request_t *r,<br>
     ngx_http_variable_value_t *v, uintptr_t data);<br>
+static ngx_int_t ngx_http_variable_request_id(ngx_http_request_t *r,<br>
+    ngx_http_variable_value_t *v, uintptr_t data);<br>
 static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r,<br>
     ngx_http_variable_value_t *v, uintptr_t data);<br>
<br>
@@ -274,6 +276,10 @@ static ngx_http_variable_t  ngx_http_cor<br>
     { ngx_string("request_time"), NULL, ngx_http_variable_request_time,<br>
       0, NGX_HTTP_VAR_NOCACHEABLE, 0 },<br>
<br>
+    { ngx_string("request_id"), NULL,<br>
+      ngx_http_variable_request_id,<br>
+      0, 0, 0 },<br>
+<br>
     { ngx_string("status"), NULL,<br>
       ngx_http_variable_status, 0,<br>
       NGX_HTTP_VAR_NOCACHEABLE, 0 },<br>
@@ -2068,6 +2074,47 @@ ngx_http_variable_request_time(ngx_http_<br>
<br>
<br>
 static ngx_int_t<br>
+ngx_http_variable_request_id(ngx_http_request_t *r,<br>
+    ngx_http_variable_value_t *v, uintptr_t data)<br>
+{<br>
+    u_char  *id;<br>
+<br>
+#if (NGX_OPENSSL)<br>
+    u_char   random_bytes[16];<br>
+#endif<br>
+<br>
+    id = ngx_pnalloc(r->pool, 32);<br>
+    if (id == NULL) {<br>
+        return NGX_ERROR;<br>
+    }<br>
+<br>
+    v->valid = 1;<br>
+    v->no_cacheable = 0;<br>
+    v->not_found = 0;<br>
+<br>
+    v->len = 32;<br>
+    v->data = id;<br>
+<br>
+#if (NGX_OPENSSL)<br>
+<br>
+    if (RAND_bytes(random_bytes, 16) == 1) {<br>
+        ngx_hex_dump(id, random_bytes, 16);<br>
+        return NGX_OK;<br>
+    }<br>
+<br>
+    ngx_ssl_error(NGX_LOG_ERR, r->connection->log, 0, "RAND_bytes() failed");<br>
+<br>
+#endif<br>
+<br>
+    ngx_sprintf(id, "%08xD%08xD%08xD%08xD",<br>
+                (uint32_t) ngx_random(), (uint32_t) ngx_random(),<br>
+                (uint32_t) ngx_random(), (uint32_t) ngx_random());<br>
+<br>
+    return NGX_OK;<br>
+}<br>
+<br>
+<br>
+static ngx_int_t<br>
 ngx_http_variable_connection(ngx_http_request_t *r,<br>
     ngx_http_variable_value_t *v, uintptr_t data)<br>
 {<br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br></div>