Skip to content

Commit ec6cd95

Browse files
committed
checked in missing files in the last commit.
1 parent 787c9a3 commit ec6cd95

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ src/rds.h
5959
src/utils.h
6060
src/handler.c
6161
src/handler.h
62+
src/var.[ch]
6263
util/bench
6364
*.html
6465
trace.out*

src/ngx_http_srcache_var.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#ifndef DDEBUG
2+
#define DDEBUG 0
3+
#endif
4+
#include "ddebug.h"
5+
6+
7+
#include "ngx_http_srcache_var.h"
8+
9+
10+
static ngx_int_t ngx_http_srcache_expire_variable(ngx_http_request_t *r,
11+
ngx_http_variable_value_t *v, uintptr_t data);
12+
13+
14+
static ngx_http_variable_t ngx_http_srcache_variables[] = {
15+
16+
{ ngx_string("srcache_expire"), NULL,
17+
ngx_http_srcache_expire_variable, 0,
18+
0, 0 },
19+
20+
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
21+
};
22+
23+
24+
static ngx_int_t
25+
ngx_http_srcache_expire_variable(ngx_http_request_t *r,
26+
ngx_http_variable_value_t *v, uintptr_t data)
27+
{
28+
ngx_http_srcache_ctx_t *ctx;
29+
u_char *p;
30+
31+
v->valid = 1;
32+
v->no_cacheable = 0;
33+
v->not_found = 0;
34+
35+
ctx = ngx_http_get_module_ctx(r, ngx_http_srcache_filter_module);
36+
37+
if (ctx->valid_sec == 0) {
38+
v->not_found = 1;
39+
return NGX_OK;
40+
}
41+
42+
p = ngx_palloc(r->pool, NGX_TIME_T_LEN);
43+
if (p == NULL) {
44+
return NGX_ERROR;
45+
}
46+
47+
v->data = p;
48+
p = ngx_sprintf(p, "%T", ctx->valid_sec - ngx_time());
49+
v->len = p - v->data;
50+
51+
return NGX_OK;
52+
}
53+
54+
55+
ngx_int_t
56+
ngx_http_srcache_add_variables(ngx_conf_t *cf)
57+
{
58+
ngx_http_variable_t *var, *v;
59+
60+
for (v = ngx_http_srcache_variables; v->name.len; v++) {
61+
var = ngx_http_add_variable(cf, &v->name, v->flags);
62+
if (var == NULL) {
63+
return NGX_ERROR;
64+
}
65+
66+
var->get_handler = v->get_handler;
67+
var->data = v->data;
68+
}
69+
70+
return NGX_OK;
71+
}
72+

src/ngx_http_srcache_var.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef NGX_HTTP_SRCACHE_VAR_H
2+
#define NGX_HTTP_SRCACHE_VAR_H
3+
4+
5+
#include "ngx_http_srcache_filter_module.h"
6+
7+
8+
ngx_int_t ngx_http_srcache_add_variables(ngx_conf_t *cf);
9+
10+
11+
#endif /* NGX_HTTP_SRCACHE_VAR_H */
12+

0 commit comments

Comments
 (0)