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
90 lines (64 loc) · 1.77 KB
/
Copy pathngx_http_lua_phase.c
File metadata and controls
90 lines (64 loc) · 1.77 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
/*
* 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_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;
default:
return luaL_error(L, "unknown phase: %d", (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");
}
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */