Skip to main content
Version: 9.2605.x.x RR

Response

Class function

nevis.filter.lua.response.new()

Instantiates a fresh independent response object.

Sample:

newResp = nevis.filter.lua.response.new()

Object methods

response:getStatus()

Returns the current HTTP response status code.

Sample:

status = response:getStatus()

response:setStatus(status)

Sets the HTTP response status code. In InputFunction methods, use response:send(status) instead.

Sample:

response:setStatus(302)

response:getHeader(headerName)

Returns the value of a specific response header.

Sample:

response:getHeader("Content-Type")

response:setHeader(headerName, value)

Sets and overwrites a specific response header, even if the header exists multiple times. Set the Content-Length header at your own risk.

Sample:

response:setHeader("X-Foobar", "my value")

response:addHeader(headerName, value)

Adds a response header; the same header can be added multiple times. Add the Content-Length header at your own risk.

Sample:

response:addHeader("X-Foobar", "my value")

response:removeHeader(headerName)

Removes a specific response header, even if it exists multiple times.

Sample:

response:removeHeader("Content-Length")

response:iterateHeaders()

Iterates over all response headers.

Sample:

trace = request:getTracer()
for n,v in response:iterateHeaders() do
trace:debug("name is "..n.." and value is "..v)
end

response:setBody(string)

Sets the response body.

Sample:

response:setBody("<HTML><BODY>Hello world</BODY></HTML>")

response:getBody()

Returns the response body. Typically used with a fresh response object after a side call.

Sample:

newResp = nevis.filter.lua.response.new()
dispatcher = request:getDispatcher("MyHttpConnectorServlet")
dispatcher:forward(req, newResp)
body = newResp:getBody()

response:send(status)

Sends the response and terminates the filter chain on request.

Sample:

response:setHeader("Content-Type", "text/html")
response:setBody("<html><body><h1>302 Found</h1></body></html>")
response:send(302)