forked from openresty/lua-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngx_http_lua_phase.c
More file actions
128 lines (92 loc) · 2.59 KB
/
Copy pathngx_http_lua_phase.c
File metadata and controls
128 lines (92 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (C) Yichun Zhang (agentzh)
*/
#ifndef DDEBUG
#define DDEBUG 0
#endif
#include "ddebug.h"
#include "ngx_http_lua_phase.h"
#include "ngx_http_lua_util.h"
#include "ngx_http_lua_ctx.h"
static int ngx_http_lua_ngx_get_phase(lua_State *L);
static int
ngx_http_lua_ngx_get_phase(lua_State *L)
{
ngx_http_request_t *r;
ngx_http_lua_ctx_t *ctx;
r = ngx_http_lua_get_req(L);
/* If we have no request object, assume we are called from the "init"
* phase. */
if (r == NULL) {
lua_pushliteral(L, "init");
return 1;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (ctx == NULL) {
return luaL_error(L, "no request ctx found");
}
switch (ctx->context) {
case NGX_HTTP_LUA_CONTEXT_INIT_WORKER:
lua_pushliteral(L, "init_worker");
break;
case NGX_HTTP_LUA_CONTEXT_SET:
lua_pushliteral(L, "set");
break;
case NGX_HTTP_LUA_CONTEXT_REWRITE:
lua_pushliteral(L, "rewrite");
break;
case NGX_HTTP_LUA_CONTEXT_ACCESS:
lua_pushliteral(L, "access");
break;
case NGX_HTTP_LUA_CONTEXT_CONTENT:
lua_pushliteral(L, "content");
break;
case NGX_HTTP_LUA_CONTEXT_LOG:
lua_pushliteral(L, "log");
break;
case NGX_HTTP_LUA_CONTEXT_HEADER_FILTER:
lua_pushliteral(L, "header_filter");
break;
case NGX_HTTP_LUA_CONTEXT_BODY_FILTER:
lua_pushliteral(L, "body_filter");
break;
case NGX_HTTP_LUA_CONTEXT_TIMER:
lua_pushliteral(L, "timer");
break;
case NGX_HTTP_LUA_CONTEXT_BALANCER:
lua_pushliteral(L, "balancer");
break;
case NGX_HTTP_LUA_CONTEXT_SSL_CERT:
lua_pushliteral(L, "ssl_cert");
break;
case NGX_HTTP_LUA_CONTEXT_SSL_SESS_STORE:
lua_pushliteral(L, "ssl_session_store");
break;
case NGX_HTTP_LUA_CONTEXT_SSL_SESS_FETCH:
lua_pushliteral(L, "ssl_session_fetch");
break;
default:
return luaL_error(L, "unknown phase: %#x", (int) ctx->context);
}
return 1;
}
void
ngx_http_lua_inject_phase_api(lua_State *L)
{
lua_pushcfunction(L, ngx_http_lua_ngx_get_phase);
lua_setfield(L, -2, "get_phase");
}
#ifndef NGX_LUA_NO_FFI_API
int
ngx_http_lua_ffi_get_phase(ngx_http_request_t *r, char **err)
{
ngx_http_lua_ctx_t *ctx;
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (ctx == NULL) {
*err = "no request context";
return NGX_ERROR;
}
return ctx->context;
}
#endif
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */