Request object methods
Method | Description | Sample |
---|---|---|
request:getHeader(headerName) | Get a specific request header. | request:getHeader("Content-Type") |
request:setHeader(headerName, value) | Set and overwrite a specific request header even if the header exists multiple times. | request:setHeader("X-Foobar", "my value") |
request:removeHeader(headerName) | Remove a specific request header even if the header exists multiple times. | request:removeHeader("Content-Length") |
request: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
Method | Description | Sample |
---|---|---|
request:setEnv(name, value) | Sets a specific environment value to the request. | request:setEnv("aName", "aValue") |
request:getEnv(envName) | Get an environment variable value. | request:getEnv("REQUEST_URI") |
request: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") |
request: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"") |
request: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
Method | Description | Sample |
---|---|---|
request:getRequestUri() | Returns the URI of the request. The URI consists of the context path, the servlet path and the path info, if given. | |
request:setRequestUri(uri) | Sets the URI of the request. Only use this method for modifying the request URI of a side call request, as the modification of the original request's URI may result in undefined behavior. | request:setRequestUri("/set/side/call/uri") |
request:getQuery() | Get the request query string. | request:getQuery() |
request:setQuery(query-string) | Set a query string. | request:setQuery("param=value&anyother=this") |
request:getMethod() | Get method of request. | request:getMethod() |
request:setMethod(method-string) | Set a request method. | request:setMethod("HEAD") |
request: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") |
request:getDispatcher(name) | Get a dispatcher to send a side call to another party. A dispatcher is normally a connector servlet. | dispatcher = request:getDispatcher("HttpSideCallConnectorServlet")If the requested connector do not exist you will get a Lua nil object. |
request:getTracer() | Get a tracer object (see Tracer object methods below). | trace = request:getTracer() |
request:getSession(boolean) | A session object (for more information see below 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 |
request:getParameter(parameterName) | Get a specific request parameter. Returns nil if the parameter was not found. | request:getParameter("param") |
request:iterateParameters() | Iterate over all request parameters. | parameters = {} for n,v in request:iterateParameters() do table.insert(parameters, "param: "..n.." and value: "..v) end result = table.concat(parameters, "\n") |
request:getServerPort() | Returns the port on which the server (Apache) is listening. | port = request:getServerPort() |
request:setServerPort() | 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
Method | Description | Sample |
---|---|---|
request: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 | |
request:getServerName() | Returns the name of the server on which this request has been received or set. | |
request:getContextPath() | Returns the context path on which the web.xml is mapped (see navajo.xml). | |
request:setContextPath(path) | Overwrites the context path; the overwritten context path is visible to all filters mapped after this LuaFilter. | |
request: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". | |
request: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. | |
request: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. | |
request:getRemotePort() | Returns the source port of the client that sent the request. | remotePort = request:getRemotePort |
request:getRemoteAddr() | Returns the IP address of the client that sent the request. | remoteAddr = request:getRemoteAddr |
request:setServletPath() | Sets the part of the request's URL that calls the servlet. | req:setServletPath("/servlet/") |