author | Mahlon E. Smith <mahlon@laika.com> |
Tue, 24 Jul 2012 12:12:07 -0700 | |
changeset 29 | c5d00a24af56 |
parent 22 | 822094314703 |
child 33 | ba41bfbe87a2 |
permissions | -rw-r--r-- |
22
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1 |
|
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2 |
-- examine the request. |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3 |
-- this emits to stderr! |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4 |
-- |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5 |
for k,v in pairs( request ) do print( string.format("request.%-6s --> %s", k, v) ) end |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6 |
|
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7 |
-- all variables need to be declared using local scoping! |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
8 |
-- |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
9 |
local redir = 302 |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
10 |
|
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
11 |
-- temporary redirect to a different site, every other second. |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
12 |
-- why would you want to do this? you probably wouldn't. just illustrating |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
13 |
-- how easy it is to do custom stuff. |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
14 |
-- |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
15 |
if os.time() % 2 == 0 then |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
16 |
return string.format( "%d:http://example.com%s", redir, request.path ) |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
17 |
end |
822094314703
Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
18 |