Skip to main content
Version: 3.14.x.x LTS

Setting up static lookup tables

If you plan to implement for example a translation table, then do not initialize this table on every request, do this before.

Bad pattern

Let's do a lookup table where we replace a header value by the looked up value in the defined InputHeaderFunction named "inputHeader" in this example.

function inputHeader(req, res)
lookup = { }
lookup = "c"
lookup[foobar] = "hello"
...
result = lookup
req:setHeader("X-MyHeader", result)
end

If this table is big, doing it on every request could be expensive. Rather build this up on script load.

Good pattern

Let us improve the bad pattern above.

lookup = { }
lookup = "c"
lookup = "hello"
...

function inputHeader(req, res)
result = lookup
req:setHeader("X-MyHeader", result)
end

Now the lookup table is generated once on proxy start-up.