trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [17/50] git commit: Implement URL passing for LuaRemapRedirect
Date Tue, 12 Jun 2012 15:51:36 GMT
Implement URL passing for LuaRemapRedirect


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

Branch: refs/heads/jpeach/lua
Commit: 58f521566451b4ee31a3d3586304eeb4ad7bcaea
Parents: c55141a
Author: James Peach <jpeach@apache.org>
Authored: Mon Apr 16 22:07:24 2012 -0700
Committer: James Peach <jpeach@apache.org>
Committed: Tue Jun 12 08:48:36 2012 -0700

----------------------------------------------------------------------
 plugins/lua/lapi.cc |   50 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/58f52156/plugins/lua/lapi.cc
----------------------------------------------------------------------
diff --git a/plugins/lua/lapi.cc b/plugins/lua/lapi.cc
index dcaa6ae..91350b1 100644
--- a/plugins/lua/lapi.cc
+++ b/plugins/lua/lapi.cc
@@ -35,8 +35,51 @@ LuaRemapRequest::alloc(lua_State * lua)
   luaL_getmetatable(lua, "ts.meta.rri");
   lua_setmetatable(lua, -2);
 
-    return rq;
+  return rq;
+}
+
+// Given a URL table on the top of the stack, pop it's values into the URL buffer.
+bool
+LuaPopUrl(lua_State * lua, TSMBuffer buffer, TSMLoc url)
+{
+  const char *  strval;
+  size_t        len;
+
+#define SET_URL_COMPONENT(name, setter) do { \
+  lua_getfield(lua, -1, name); \
+  if (!lua_isnil(lua, -1)) { \
+    strval = luaL_checklstring(lua, -1, &len); \
+    if (strval) { \
+      setter(buffer, url, strval, len); \
+    } \
+  } \
+  lua_pop(lua, 1); \
+} while (0)
+
+  // We ignore the 'href' field. When constructing URL tables, it's convenient, but it doesn't
seem
+  // necessary here. Callers can easily construct the URL table.
+  SET_URL_COMPONENT("scheme", TSUrlSchemeSet);
+  SET_URL_COMPONENT("user", TSUrlUserSet);
+  SET_URL_COMPONENT("password", TSUrlPasswordSet);
+  SET_URL_COMPONENT("host", TSUrlHostSet);
+  SET_URL_COMPONENT("path", TSUrlPathSet);
+  SET_URL_COMPONENT("query", TSUrlHttpQuerySet);
+  SET_URL_COMPONENT("fragment", TSUrlHttpFragmentSet);
+
+  lua_getfield(lua, -1, "port");
+  if (lua_isnil(lua, -1)) {
+    TSDebug("lua", "port is nil?");
+  } else {
+    TSDebug("lua", "port is %d", (int)lua_tointeger(lua, -1));
+    TSUrlPortSet(buffer, url, luaL_checkint(lua, -1));
   }
+  lua_pop(lua, 1);
+
+  TSDebug("lua", "top of stack is %s", luaL_typename(lua, -1));
+
+#undef SET_URL_COMPONENT
+  return true;
+}
 
 bool
 LuaPushUrl(lua_State * lua, TSMBuffer buffer, TSMLoc url)
@@ -93,8 +136,9 @@ LuaRemapRedirect(lua_State * lua)
   luaL_checktype(lua, 2, LUA_TTABLE);
 
   TSDebug("lua", "redirecting request %p", rq->rri);
-
-  // XXX take the URL table argument and use it to rewrite rri->requestUrl ...
+  lua_pushvalue(lua, 2);
+  LuaPopUrl(lua, rq->rri->requestBufp, rq->rri->requestUrl);
+  lua_pop(lua, 1);
 
   // A redirect always terminates plugin chain evaluation.
   rq->rri->redirect = 1;


Mime
View raw message