Skip to content

Instantly share code, notes, and snippets.

@esigler
Created March 28, 2012 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esigler/2228568 to your computer and use it in GitHub Desktop.
Save esigler/2228568 to your computer and use it in GitHub Desktop.
Patch to add "start_time" HTTP variable to Nginx 1.0.14
--- src/http/ngx_http_variables.c.orig 2012-03-23 15:38:22.000000000 -0700
+++ src/http/ngx_http_variables.c 2012-03-23 15:44:24.000000000 -0700
@@ -94,6 +94,9 @@
static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_start_time(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
+
/*
* TODO:
* Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED
@@ -255,6 +258,9 @@
{ ngx_string("pid"), NULL, ngx_http_variable_pid,
0, 0, 0 },
+ { ngx_string("start_time"), NULL, ngx_http_variable_start_time,
+ 0, 0, 0 },
+
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};
@@ -1678,6 +1684,27 @@
}
+static ngx_int_t
+ngx_http_variable_start_time(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ u_char *p;
+
+ p = ngx_pnalloc(r->pool, NGX_INT64_LEN);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ uint64_t usec = (((uint64_t)r->start_sec * 1000 * 1000) + ((uint64_t)r->start_msec * 1000));
+
+ v->len = ngx_sprintf(p, "%L", usec) - p;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+ v->data = p;
+ return NGX_OK;
+}
+
void *
ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map, ngx_str_t *match)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment