Permalink
Browse files

refactor all

  • Loading branch information...
1 parent 20d2d47 commit a326521994d1b6436f398217c79f45332a310b85 @alacner committed May 7, 2011
Showing with 716 additions and 292 deletions.
  1. +5 −10 README
  2. +1 −1 config
  3. +44 −0 example/kit.lua
  4. +37 −29 example/t1.lua
  5. +0 −13 src/ddebug.h
  6. +0 −28 src/ngx_http_lua_core.c
  7. +0 −2 src/ngx_http_lua_core.h
  8. +617 −208 src/ngx_http_lua_module.c
  9. +12 −1 src/strtok_r.h
View
15 README
@@ -1,12 +1,7 @@
--- exapmle:
- location ~/test {
- lua_file "/usr/local/nginx/conf/test.lua";
- }
+-- example:
- location ~/lua {
- lua_file "/usr/local/nginx/conf/lua.lua";
- }
+ lua_file "/usr/local/nginx/conf/test.lua";
-
-
-Tue Apr 26 16:30:00 MST 2011
+ location ~/test {
+ lua_file "/usr/local/nginx/conf/test.lua";
+ }
View
2 config
@@ -141,7 +141,7 @@ fi
ngx_addon_name=ngx_http_lua_module
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_lua_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_lua_module.c $ngx_addon_dir/src/strtok_r.c"
-NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/strtok_r.h"
+NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/strtok_r.h"
CFLAGS="$CFLAGS -DNDK_SET_VAR"
ngx_feature="export symbols by default"
View
@@ -0,0 +1,44 @@
+--Copyright (c) 2011-2015 Zhihua Zhang (alacner@gmail.com)
+module('kit', package.seeall)
+
+function print_r(sth)
+ if type(sth) ~= "table" then
+ if type(sth) == "nil" then
+ sth = "nil"
+ end
+ print(sth)
+ return
+ end
+
+ local space, deep = string.rep(' ', 4), 0
+ local function _dump(t)
+ for k,v in pairs(t) do
+ local key = tostring(k)
+
+ if type(v) == "table" then
+ deep = deep + 2
+ print(string.format("%s[%s] => Table\r\n%s(\r\n",
+ string.rep(space, deep - 1),
+ key,
+ string.rep(space, deep)
+ )
+ ) --print.
+ _dump(v)
+
+ print(string.format("%s)\r\n",string.rep(space, deep)))
+ deep = deep - 2
+ else
+ print(string.format("%s[%s] => %s\r\n",
+ string.rep(space, deep + 1),
+ key,
+ tostring(v)
+ )
+ ) --print.
+ end
+ end
+ end
+
+ print(string.format("Table\r\n(\r\n"))
+ _dump(sth)
+ print(string.format(")\r\n"))
+end
View
@@ -1,57 +1,65 @@
--Copyright (c) 2011-2015 Zhihua Zhang (alacner@gmail.com)
--ngx.set_header('Location', "http://www.google.com");
---do return end
-local log = print
+--ngx.set_cookie('love', '123456') -- name, value, expire, path, domain, secure
+--ngx.set_cookie('aa', 'ssssss') -- name, value, expire, path, domain, secure
print = ngx.print
local kit = require("kit")
local print_r = kit.print_r
-ngx.set_header('Content-Type', "image/png");
---ngx.set_header('Content-Type', "text/html");
+--ngx.set_header('Content-Type', "image/png");
+ngx.set_header('Content-Type', "text/html");
--local f = io.open('/root/repos/nginx_lua_module/example/t1.lua', 'rb')
--local f = io.open('/root/test.jpg', 'rb')
+--local t = f:read("*a")
+--ngx.print(t)
local f = io.open('/root/480x480.png', 'rb')
---local a = f:read("*a")
+--local t = f:read("*a")
--log(a)
-local t = f:read(8192)
-ngx.print(t)
-do return end
-print_r(ngx)
+--local t = f:read(8192)
+--ngx.print(t)
+--print_r(ngx)
+--ngx.flush()
+--ngx.print(t)
+--print_r(ngx)
+--ngx.flush()
+--ngx.print(t)
+--print_r(ngx)
--local f = io.open('/root/test.jpg', 'rb')
--local f = assert(io.open(arg[1], "rb"))
---[[
-local block = 10
-while true do
- local bytes = f:read(block)
- if not bytes then break end
- for b in string.gfind(bytes, ".") do
- print_r(string.format("%02X ", string.byte(b)))
- end
- print_r(string.rep(" ", block - string.len(bytes) + 1))
- print_r(string.gsub(bytes, "%c", "."), "\n")
-end
---]]
-
f:close()
+--ngx.print(ngx.set_cookie)
+local t = os.time()
+ngx.set_cookie('love1', "me") -- name, value, expire, path, domain, secure
+--ngx.set_cookie('love2', "me", 100) -- name, value, expire, path, domain, secure
+--ngx.set_cookie('love3', '123456') -- name, value, expire, path, domain, secure
+--ngx.set_cookie('isopen', 'true', 1000, '/', '192.168.137.126') -- name, value, expire, path, domain, secure
+ngx.set_header('X-Memc-Flags', "11111111111111");
+ngx.set_header('X-Memc-Flags', "2222222222222222222222222");
+ngx.set_header('X-Memc-Flags', "f1111122222222333333334444445");
print_r(ngx)
---print_r(t)
+ngx.eof()
+do return end
+
+local http = require("socket.http")
+local r, e, h, l = http.request("http://www.6uu.com")
+print_r(h)
+print_r(l)
+print_r(m)
+ngx.eof()
do return end
---ngx.print(ngx.set_cookie)
-ngx.set_cookie('love', '123456') -- name, value, expire, path, domain, secure
-ngx.set_cookie('isopen', 'true', 1000, '/', '192.168.137.126') -- name, value, expire, path, domain, secure
-print_r(ngx)
local socket = require("socket")
local tcp = socket.tcp()
tcp:settimeout(1)
-local n,e,h = tcp:connect("www.6uu.com","80")
+local n,e,h = tcp:connect("www.google.com","80")
print_r(n)
-print_r(e)
+--print_r(e)
print_r(h)
+ngx.eof()
do return end
View
@@ -1,13 +0,0 @@
-#if defined(DDEBUG) && (DDEBUG)
-# define dd(...) fprintf(stderr, "lua *** %s: ", __func__); \
- fprintf(stderr, __VA_ARGS__); \
- fprintf(stderr, " at %s line %d.\n", __FILE__, __LINE__)
-
-# else
-
-#include <stdarg.h>
-
-static void dd(const char *fmt, ...) {
-}
-
-# endif
View
@@ -1,28 +0,0 @@
-#include "ngx_http_lua_core.h"
-
-static int luaM_print (lua_State *L);
-#if 0
-static int luaM_get_header (lua_State *L);
-static int luaM_set_header (lua_State *L);
-
-static int luaM_get_request (lua_State *L);
-static int luaM_get_get (lua_State *L);
-static int luaM_get_post (lua_State *L);
-static int luaM_get_files (lua_State *L);
-
-static int luaM_get_cookie (lua_State *L);
-static int luaM_set_cookie (lua_State *L);
-#endif
-
-static int
-luaM_print (lua_State *L) {
- const char *str = luaL_optstring(L, 1, NULL);
-
- lua_getglobal(L, LUA_NGX_REQUEST);
- ngx_http_request_t *r = lua_touserdata(L, -1);
- lua_pop(L, 1);
-
-
-
- return 0;
-}
View
@@ -1,2 +0,0 @@
-#define LUA_NGX_REQUEST "ngx.request" /* nginx request pointer */
-
Oops, something went wrong.

0 comments on commit a326521

Please sign in to comment.