comparison src/http/ngx_http_variables.c @ 4913:002f2c783d7c

Variables $request_time and $msec. Log module counterparts are preserved for efficiency.
author Ruslan Ermilov <ru@nginx.com>
date Fri, 16 Nov 2012 09:37:14 +0000
parents e89bd9896fea
children fbc0791bebb2
comparison
equal deleted inserted replaced
4912:e8ef31c58d43 4913:002f2c783d7c
77 ngx_http_variable_value_t *v, uintptr_t data); 77 ngx_http_variable_value_t *v, uintptr_t data);
78 static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r, 78 static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
79 ngx_http_variable_value_t *v, uintptr_t data); 79 ngx_http_variable_value_t *v, uintptr_t data);
80 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r, 80 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
81 ngx_http_variable_value_t *v, uintptr_t data); 81 ngx_http_variable_value_t *v, uintptr_t data);
82 static ngx_int_t ngx_http_variable_request_time(ngx_http_request_t *r,
83 ngx_http_variable_value_t *v, uintptr_t data);
82 static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r, 84 static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r,
83 ngx_http_variable_value_t *v, uintptr_t data); 85 ngx_http_variable_value_t *v, uintptr_t data);
84 86
85 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r, 87 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r,
86 ngx_http_variable_value_t *v, uintptr_t data); 88 ngx_http_variable_value_t *v, uintptr_t data);
105 static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r, 107 static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r,
106 ngx_http_variable_value_t *v, uintptr_t data); 108 ngx_http_variable_value_t *v, uintptr_t data);
107 static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r, 109 static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r,
108 ngx_http_variable_value_t *v, uintptr_t data); 110 ngx_http_variable_value_t *v, uintptr_t data);
109 static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r, 111 static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r,
112 ngx_http_variable_value_t *v, uintptr_t data);
113 static ngx_int_t ngx_http_variable_msec(ngx_http_request_t *r,
110 ngx_http_variable_value_t *v, uintptr_t data); 114 ngx_http_variable_value_t *v, uintptr_t data);
111 115
112 /* 116 /*
113 * TODO: 117 * TODO:
114 * Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED 118 * Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED
235 239
236 { ngx_string("request_body_file"), NULL, 240 { ngx_string("request_body_file"), NULL,
237 ngx_http_variable_request_body_file, 241 ngx_http_variable_request_body_file,
238 0, 0, 0 }, 242 0, 0, 0 },
239 243
244 { ngx_string("request_time"), NULL, ngx_http_variable_request_time,
245 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
246
240 { ngx_string("status"), NULL, 247 { ngx_string("status"), NULL,
241 ngx_http_variable_status, 0, 248 ngx_http_variable_status, 0,
242 NGX_HTTP_VAR_NOCACHEABLE, 0 }, 249 NGX_HTTP_VAR_NOCACHEABLE, 0 },
243 250
244 { ngx_string("sent_http_content_type"), NULL, 251 { ngx_string("sent_http_content_type"), NULL,
282 { ngx_string("hostname"), NULL, ngx_http_variable_hostname, 289 { ngx_string("hostname"), NULL, ngx_http_variable_hostname,
283 0, 0, 0 }, 290 0, 0, 0 },
284 291
285 { ngx_string("pid"), NULL, ngx_http_variable_pid, 292 { ngx_string("pid"), NULL, ngx_http_variable_pid,
286 0, 0, 0 }, 293 0, 0, 0 },
294
295 { ngx_string("msec"), NULL, ngx_http_variable_msec,
296 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
287 297
288 #if (NGX_HAVE_TCP_INFO) 298 #if (NGX_HAVE_TCP_INFO)
289 { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo, 299 { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo,
290 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, 300 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
291 301
1823 return NGX_OK; 1833 return NGX_OK;
1824 } 1834 }
1825 1835
1826 1836
1827 static ngx_int_t 1837 static ngx_int_t
1838 ngx_http_variable_request_time(ngx_http_request_t *r,
1839 ngx_http_variable_value_t *v, uintptr_t data)
1840 {
1841 u_char *p;
1842 ngx_time_t *tp;
1843 ngx_msec_int_t ms;
1844
1845 p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
1846 if (p == NULL) {
1847 return NGX_ERROR;
1848 }
1849
1850 tp = ngx_timeofday();
1851
1852 ms = (ngx_msec_int_t)
1853 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec));
1854 ms = ngx_max(ms, 0);
1855
1856 v->len = ngx_sprintf(p, "%T.%03M", ms / 1000, ms % 1000) - p;
1857 v->valid = 1;
1858 v->no_cacheable = 0;
1859 v->not_found = 0;
1860 v->data = p;
1861
1862 return NGX_OK;
1863 }
1864
1865
1866 static ngx_int_t
1828 ngx_http_variable_connection(ngx_http_request_t *r, 1867 ngx_http_variable_connection(ngx_http_request_t *r,
1829 ngx_http_variable_value_t *v, uintptr_t data) 1868 ngx_http_variable_value_t *v, uintptr_t data)
1830 { 1869 {
1831 u_char *p; 1870 u_char *p;
1832 1871
1904 if (p == NULL) { 1943 if (p == NULL) {
1905 return NGX_ERROR; 1944 return NGX_ERROR;
1906 } 1945 }
1907 1946
1908 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; 1947 v->len = ngx_sprintf(p, "%P", ngx_pid) - p;
1948 v->valid = 1;
1949 v->no_cacheable = 0;
1950 v->not_found = 0;
1951 v->data = p;
1952
1953 return NGX_OK;
1954 }
1955
1956
1957 static ngx_int_t
1958 ngx_http_variable_msec(ngx_http_request_t *r,
1959 ngx_http_variable_value_t *v, uintptr_t data)
1960 {
1961 u_char *p;
1962 ngx_time_t *tp;
1963
1964 p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
1965 if (p == NULL) {
1966 return NGX_ERROR;
1967 }
1968
1969 tp = ngx_timeofday();
1970
1971 v->len = ngx_sprintf(p, "%T.%03M", tp->sec, tp->msec) - p;
1909 v->valid = 1; 1972 v->valid = 1;
1910 v->no_cacheable = 0; 1973 v->no_cacheable = 0;
1911 v->not_found = 0; 1974 v->not_found = 0;
1912 v->data = p; 1975 v->data = p;
1913 1976