You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2012/06/12 17:51:36 UTC

[16/50] git commit: Implement LuaRemapRewrite

Implement LuaRemapRewrite


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0d1c4c2e
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0d1c4c2e
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0d1c4c2e

Branch: refs/heads/jpeach/lua
Commit: 0d1c4c2e2f1e3f32ed974f24abae722ec08f7032
Parents: 58f5215
Author: James Peach <jp...@apache.org>
Authored: Mon Apr 16 22:12:42 2012 -0700
Committer: James Peach <jp...@apache.org>
Committed: Tue Jun 12 08:48:36 2012 -0700

----------------------------------------------------------------------
 plugins/lua/lapi.cc |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0d1c4c2e/plugins/lua/lapi.cc
----------------------------------------------------------------------
diff --git a/plugins/lua/lapi.cc b/plugins/lua/lapi.cc
index 91350b1..92ed744 100644
--- a/plugins/lua/lapi.cc
+++ b/plugins/lua/lapi.cc
@@ -149,9 +149,31 @@ LuaRemapRedirect(lua_State * lua)
   return 1;
 }
 
+static int
+LuaRemapRewrite(lua_State * lua)
+{
+  LuaRemapRequest * rq;
+
+  rq = LuaRemapRequest::get(lua, 1);
+  luaL_checktype(lua, 2, LUA_TTABLE);
+
+  TSDebug("lua", "rewriting request %p", rq->rri);
+  lua_pushvalue(lua, 2);
+  LuaPopUrl(lua, rq->rri->requestBufp, rq->rri->requestUrl);
+  lua_pop(lua, 1);
+
+  // A rewrite updates the request URL but never terminates plugin chain evaluation.
+  rq->status = TSREMAP_DID_REMAP;
+
+  // Return true back to Lua-space.
+  lua_pushboolean(lua, 1);
+  return 1;
+}
+
 static const luaL_Reg RRI[] =
 {
   { "redirect", LuaRemapRedirect },
+  { "rewrite", LuaRemapRewrite },
   { NULL, NULL}
 };