Skip to content

Commit

Permalink
proxy: improve mutator constructor consistency
Browse files Browse the repository at this point in the history
instead of 'str' just take 'val' for the 'value' part of a step
specification. previously was sometimes val and sometimes str.
  • Loading branch information
dormando committed Oct 30, 2024
1 parent 1c8f59f commit e368cd2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions proxy_mutator.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ mut_step_r(keycopy) {
mut_step_c(keyset) {
size_t len = 0;

if (lua_getfield(L, tidx, "str") != LUA_TNIL) {
if (lua_getfield(L, tidx, "val") != LUA_TNIL) {
lua_tolstring(L, -1, &len);
if (len < 1) {
proxy_lua_ferror(L, "mutator step %d: 'str' must have nonzero length", tidx);
proxy_lua_ferror(L, "mutator step %d: 'val' must have nonzero length", tidx);
}
} else {
proxy_lua_ferror(L, "mutator step %d: must provide 'str' argument", tidx);
proxy_lua_ferror(L, "mutator step %d: must provide 'val' argument", tidx);
}
lua_pop(L, 1); // val or nil

Expand All @@ -360,7 +360,7 @@ mut_step_i(keyset) {
size_t len = 0;

// store our match string in the arena space that we reserved before.
if (lua_getfield(L, tidx, "str") != LUA_TNIL) {
if (lua_getfield(L, tidx, "val") != LUA_TNIL) {
const char *str = lua_tolstring(L, -1, &len);
c->str = mut->aused;
c->len = len;
Expand Down Expand Up @@ -391,15 +391,15 @@ mut_step_r(keyset) {
// TODO: ensure step is first
// TODO: pre-validate that it's an accepted code?
mut_step_c(rescodeset) {
return _mut_check_strlen(L, tidx, "str");
return _mut_check_strlen(L, tidx, "val");
}

mut_step_i(rescodeset) {
struct mcp_mut_step *s = &mut->steps[sc];
struct mcp_mut_string *c = &s->c.string;
size_t len = 0;

if (lua_getfield(L, tidx, "str") != LUA_TNIL) {
if (lua_getfield(L, tidx, "val") != LUA_TNIL) {
const char *str = lua_tolstring(L, -1, &len);
c->str = mut->aused;
c->len = len;
Expand Down
12 changes: 6 additions & 6 deletions t/proxymut.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function mcp_config_routes(p)
-- basic; no flags at all.
local mut_mgreq = mcp.req_mutator_new(
{ t = "cmdset", cmd = "mg" },
{ t = "keyset", str = "override" }
{ t = "keyset", val = "override" }
)

-- set a bunch of flags
local mut_mgflagreq = mcp.req_mutator_new(
{ t = "cmdset", cmd = "mg" },
{ t = "keyset", str = "override" },
{ t = "keyset", val = "override" },
{ t = "flagset", flag = "s" },
{ t = "flagset", flag = "t" },
{ t = "flagset", flag = "O", val = "opaque" },
Expand All @@ -34,18 +34,18 @@ function mcp_config_routes(p)

-- basic res: no flags.
local mut_mgres = mcp.res_mutator_new(
{ t = "rescodeset", str = "HD" }
{ t = "rescodeset", val = "HD" }
)

-- res with value.
local mut_mgresval = mcp.res_mutator_new(
{ t = "rescodeset", str = "VA" },
{ t = "valcopy", idx = 1, arg = "string" }
{ t = "rescodeset", val = "VA" },
{ t = "valcopy", idx = 1 }
)

-- res with flags.
local mut_mgresflag = mcp.res_mutator_new(
{ t = "rescodeset", str = "HD" },
{ t = "rescodeset", val = "HD" },
{ t = "flagset", flag = "t", val = "37" },
{ t = "flagcopy", flag = "O", idx = 1 }
)
Expand Down

0 comments on commit e368cd2

Please sign in to comment.