Request object methods
getHeader(headerName)
Get a specific request header.
request:getHeader("Content-Type")
setHeader(headerName, value)
Set and overwrite a specific request header even if the header exists multiple times.
request:setHeader("X-Foobar", "my value")
removeHeader(headerName)
Remove a specific request header even if the header exists multiple times.
request:removeHeader("Content-Length")
iterateHeaders()
Iterate over all request headers.
trace = request:getTracer()
for n,v in request:iterateHeaders() do
trace:debug("name is "..n.." and value is "..v)
end
setEnv(name, value)
Sets a specific environment value to the request.
request:setEnv("aName", "aValue")
getEnv(envName)
Get an environment variable value.
request:getEnv("REQUEST_URI")
getAttribute(name)
Returns the request attribute with the given name. Depending on the Java-based type of the attribute (String, Float, Double, Boolean, ByteArray), it will be mapped to a Lua type (string, number, number, bool, string, respectively). Other types cannot be mapped. In this case, nil will be returned.
request:getAttribute("aName")
setAttribute(name, value)
Sets a request attribute with the given name. Depending on the Lua type of the attribute (string, number, bool), it will be mapped to a Java-based type (String, Double or Long, Boolean, respectively). Other types cannot be mapped and will not be set.
request:setAttribute("aName", "aValue")
iterateAttributes()
Iterates over all request attributes. Attributes having null values will also be returned.
for n,v in request:iterateAttributes() do
request:setHeader(n, v);
end
getRequestPath()
Returns the Path of the request. The Path consists of the context path, the servlet path and the path info, if given. No query is included. The path is URL-decoded.
setRequestPath(path)
Sets the Path of the request. Only use this method for modifying the request Path of a side call request, as the modification of the original request's Path may result in undefined behavior. The path will be URL-encoded before sending it to the backend. This means that the path can't contain any query. Question marks will be URL-encoded.
request:setRequestPath("/set/side/call/path")
getQuery()
Get the request query string.
request:getQuery()
setQuery(query-string)
Set a query string.
request:setQuery("param=value&anyother=this")
getMethod()
Get method of request.
request:getMethod()
setMethod(method-string)
Set a request method.
request:setMethod("HEAD")
setBody(string)
Set a request body. It's also possible to set binary strings, as in Lua a string is not null terminated and can hold any char. This is only possible in the defined Script.InputHeaderFunction Lua function, else an error will appear in the navajo.log and the body is silently skipped.
request:setBody("param=value¶m2=anyothervalue&p3=1234"
getDispatcher(name)
Get a dispatcher to send a side call to another party. A dispatcher is normally a connector servlet. If the requested connector do not exist you will get a Lua nil object.
dispatcher = request:getDispatcher("HttpSideCallConnectorServlet")
getTracer()
Get a tracer object (see Tracer object methods).
trace = request:getTracer()
getSession(boolean)
A session object (for more information see the session object methods chapter) or nil will be returned. If boolean is true, a new session will be created if it does not exist yet. If boolean is false, nil will be returned if no session exists.
session = request:getSession(false)
if session then
session:setAttribute("name", "value")
end
getParameter(parameterName)
Get a specific request parameter. Returns nil if the parameter was not found.
request:getParameter("param")
iterateParameters()
Iterate over all request parameters.
local parameters = {}
for n,v in request:iterateParameters() do
table.insert(parameters, "param: "..n.." and value: "..v)
end
local result = table.concat(parameters, "\n")
getServerPort()
Returns the port on which the server (Apache) is listening.
port = request:getServerPort()
setServerPort(port)
Overwrites the port on which the server (Apache) is listening. This does not modify the listening port of Apache, but all following filters in the chain will assume that Apache is listening on that port.
You may want to delegate the listening port of Apache to a sidecall. Then you can do this:
function inputStream(request, response)
local requestCall = nevis.filter.lua.request.new()
local responseCall = nevis.filter.lua.response.new()
requestCall:setServerPort(request:getServerPort())
dispatcher = request:getDispatcher("SideCallConnectorServlet")
dispatcher:forward(requestCall, responseCall)
end
setServerName(string)
Overwrites or sets the server name that is configured in the request. All following filters will assume that this request was received on the configured server name. This server name is also available through the environment variable ENV:SERVER_NAME
.
getServerName()
Returns the name of the server on which this request has been received or set.
getContextPath()
Returns the context path on which the web.xml is mapped (see navajo.xml).
setContextPath(path)
Overwrites the context path; the overwritten context path is visible to all filters mapped after this LuaFilter.
getServletPath()
Returns the part of the request's URL that calls the servlet. For example, if the servlet servicing this request was mapped to "/connector/servlet" in the web.xml, then this method will return the string "/connector/servlet".
getPathInfo()
Returns any extra path information associated with the URL sent by the client when it made this request. That is, the part of the URI between the servlet path and the query, which can contain for example the filter mapping or resource identification.
renegotiateSSL()
Renegotiate the current TLS session. It removes the current TLS entry, closes the Keep-Alive connection, and starts an TLS handshake. In the end, a new TLS session ID will be generated.
reauthenticate()
Reasks an already logged in session for authentication. This triggers a reauthentication on an IdentityCreationFilter or AuthenticationFilter (the LuaFilter has to be mapped before the ICF or AF).
getRemotePort()
Returns the source port of the client that sent the request.
remotePort = request:getRemotePort()
getRemoteAddr()
Returns the IP address of the client that sent the request.
remoteAddr = request:getRemoteAddr()
setServletPath()
Sets the part of the request's URL that calls the servlet.
req:setServletPath("/servlet/")
getPeerCertificate(require)
Get a X509Certificate object (see X509Certificate object methods). If 'require' is true the proxy will reask the client to send a certificate if none was sent until now. The client can still decide to not send any certificate.
local cert = request:getPeerCertificate(true)
getScheme()
The scheme of the request. Usually either http
or https
local scheme = request:getScheme()