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

Utils

FunctionDescription
nevis.crypto.base64This object can base64 encoding and decoding of given data.

Sample

base64 = nevis.crypto.base64.new()

result = base64:encode("hello world")
plain = base64:decode("aGVsbG8gd29ybGQK")
FunctionDescription
nevis.crypto.encrypterFor simple encrypting/decrypting data.

Sample

encrypter = nevis.crypto.encrypter.new()
result = encrypter:encrypt("hello world")
plain = encrypter:decrypt(result)
FunctionDescription
Utils = require "Utils"Utils.getWindowedProcessor(windowSize, function)The windowed processor provides a simple and powerful data window mechanism for the LuaFilter. You can specify the window size you want and provide a function which is then called on windowed buffers. For example, you are looking for a pattern in some chunked data, but the portion matching this pattern is split among more chunks. By buffering them in a common window, you can find the whole matching portion. The windowed processor is part of the package and therefore you have to include it with package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/?.lua"In this sample, all occurrences of "replaceThis" will be replaced with "withThis" in the sent body.

Sample

package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/?.lua"
Utils = require "Utils"

local myRewrite = Utils.getWindowedProcessor(256, function(window)
return string.gsub(window, "replaceThis", "withThis")
end)

function outputStream(req, resp, chunk)
return myRewrite(chunk)
end
FunctionDescription
local Utils = require "Utils"Iterator = Utils.iterateHeadersByName (request, headerName)Iterates over a header with multiple occurrences, like "Set-Cookie". It does not iterate over comma separated header values. To use this function, hand over either a request or a response object, then specify the header name and apply the returned iterator in a "for" loop.

Sample

local Utils = require "Utils"

for value in Utils.iterateHeadersByName(response, "Set-Cookie") do
print(value)
end
FunctionDescription
local Utils = require "Utils"Utils.parseCookieHeader(req)Parses the cookie header from the front end and puts the found value into a table. The cookie has to conform RFC6265:cookie-header = "Cookie:" OWS cookie-string OWScookie-string = cookie-pair ( ";" SP cookie-pair )cookie-pair = cookie-name "=" cookie-valuecookie-name = tokencookie-value =cookie-octet / ( DQUOTE *cookie-octet DQUOTE )cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E ; US-ASCII characters excluding CTLs, ; whitespace DQUOTE, comma, semicolon, ; and backslashtoken = <token, defined in, Section 2.2>

Sample

package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/Utils.lua"
local Utils = require "Utils"

function inputHeader(req, resp)
local cookies = Utils.parseCookieHeader(req)
for name, value in pairs(cookies) do
print(name, value)
end
end
FunctionDescription
local Utils = require "Utils"Utils.parseSetCookieHeaders).

Sample

package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/Utils.lua"
local Utils = require "Utils"
local cookies = Utils.parseSetCookieHeaders(resp)
for name, value in pairs(cookies) do
print(name, tostring(value))
end
FunctionDescription
local Utils = require "Utils"Utils.setResponseCookieHeaders).

Sample

package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/public/Utils.lua"
local Utils = require "Utils"
local cookies = {}
cookies[0] = bcx.servlet.http.Cookie.new("Cookie1", "Value1")
cookies[1] = bcx.servlet.http.Cookie.new("Cookie2", "Value2")
Utils.setResponseCookieHeaders(resp, cookies)
FunctionDescription
local Utils = require "Utils"Utils.setRequestCookieHeader(req, cookies)Sets the Cookie header towards the back end. It rewrites the incoming Cookie header with the new cookies. The following sample adds a new cookie "CookieAddedByLua" and removes the cookie "JSESSION" from the Cookie header.

Sample

package.path = package.path .. ";/opt/nevisproxy/webapp/WEB-INF/lib/lua/Utils.lua"
local Utils = require "Utils"

function inputHeader(req, resp)
local cookies = Utils.parseCookieHeader(req)
cookiesCookieAddedByLua = "SomeValue"
cookiesJSESSION = nil;
Utils.setRequestCookieHeader(req, cookies)
end
FunctionDescription
local Utils = require "Utils"Utils.getQueryParameters()Returns with a table containing the query parameters, where the key is the name of the parameter, and the value is another table containing all values for the given parameter.

Sample

local Utils = require "Utils"
local queryParams = Utils.getQueryParameters(req)
for name, values in pairs(queryParams) do
-- Processing the query parameters
for name, values in pairs(queryParams) do
if Helpers.tableLength(values) == 0 then
tracer:debug("Single query parameter, name: '"..tostring(name).."'")
else
for i, value in pairs(values) do
tracer:debug("Name-value query parameter, name: '"..tostring(name).."' value: "..tostring(value).."'")
end
end
end
end
FunctionDescription
local Utils = require "Utils"Utils.setQueryParameters(queryParams)Sets the query of the request. It will override all previous query parameters. The order of the query parameters is random.

Sample

local Utils = require "Utils"
local queryParams = {}
queryParamsparam1 = { "value1" }
queryParamsparam2 = { "value2", "value3" }
queryParamssingleSegment = {}

Utils.setQueryParameters(req, queryParams)
-- This will result in the following query: "param1=value1&param2=value2&param2=value3singleSegment"