Skip to content

Proxy mutator planned work #1184

@dormando

Description

@dormando

Issue to track current API and planned API for the mutator object

Complete basic example:

    -- basic; no flags or outside info
    local mut_mgreq = mcp.req_mutator_new(
        { t = "cmdset", cmd = "mg" },
        { t = "keyset", str = "override" }
    )

    mgfg:ready({
        n = "mgtest", f = function(rctx)
            -- make blank request objects for handing to mutator

            -- these objects must be made per slot (rctx)
            -- they're made via the rctx so it can release memory inbetween
            -- requests.
            local nreq = rctx:request_new()
            local nres = rctx:response_new()

            return function(r)
                    -- creates a static request of "mg override\r\n" to use instead of 'r'
                    local ret = mut_mgreq(nreq)
                    -- if ret == false etc
                    return rctx:enqueue_and_wait(nreq, mgfgh)
            end
        end
    })

Implemented steps

Note: Some of these are partially implemented as of this writing. ie; not all types of arguments accepted.

  -- manually set the command
  { t = "cmdset", cmd = "ma" },

  -- inherit the command
  { t = "cmdcopy", idx = 1 },

  -- copy the key wholesale from req or res
  -- if res, must be meta and have 'k' flag (unimplemented)
  { t = "keycopy", idx = 1 },

  -- set key to exact string
  { t = "keyset", val = "foo" },

  -- set result to code. maybe int instead?
  { t = "rescodeset", val = "code" },

  -- copy res code from another res
  { t = "rescodecopy", idx = 1 },

  -- set "SERVER_ERROR|CLIENT_ERROR|ERROR msg\r\n"
  { t = "reserr", mode = "server|client|error", msg = "blah blah" },\

  -- set flag. sets token if val supplied
  { t = "flagset", flag = "f", val = 1234},

  -- copy flag from idx
  { t = "flagcopy", flag = "f", idx = 1},

  -- inherit the value from idx 1
  -- works with strings, requests. does not currently work with results as inputs
  { t = "valcopy", idx = 1},

  -- directly set the value here
  { t = "valset", val = num|string },

Steps TODO

Note: not all steps will be completed in this PR. 'o' in front of the { means optional but planned

  -- format string version of reserr
  -- runs once against the test array table when making the object
  { t = "resfmterr", mode = "server|client|error", msg = "blah %d blah %s blah",
    test = { 5, "foo" } },

  -- copy key but trim until char is found
  -- also add "count" to trim specifically n chars?
  { t = "keycopytrim", idx = 1, until = "/" },

  -- assemble the key from multiple args with optional sep
  { t = "keycombine", sidx = 1, eidx = 2, sep = "/" },

  -- copy flag/token from one flag to another
  { t = "flagcopyfrom", dflag = "F", sflag = "f", idx = 1},

  -- copy all flags + tokens from idx to dst
  -- unless specified in 'except'
  -- ie: copy everything but O, replace with our own O
  { t = "flagcopyall", idx = 1, except = "abcd"},

  -- for copying ascii command arguments
  { t = "tokencopy", tok = 2, idx = 1},

  -- for converting commands?
  { t = "tokentoflag", tok = 2, flag = "f", idx = 1},

  -- for ascii commands.
  -- add shortcut strings for set-ttl or something?
  -- name -> tok
  { t = "tokenset", tok = 2, val = 1234},

  -- set the value from strings or objs in args 1 through 2
  -- with optional separator
  o { t = "valcombine", sidx = 1, eidx = 2, sep = "|" },

  -- walk an array table and combine into the value
  -- with optional separator
  o { t = "valtcombine", tidx = 1, sep = "|"},

  -- TODO: val splitter? maybe that's something else
  -- for taking a req and splitting it into N things

Metadata

Metadata

Assignees

No one assigned

    Labels

    proxyworklogs and issues related to proxy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions