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

Response object methods

MethodDescriptionSample
response:getStatus()Get current response state.status = response:getStatus()
response:setStatus(status)Set HTTP response status code. In InputFunction methods response:send(status) should be used instead.response:setStatus(302)
response:getHeader(headerName)Get a specific response header.response:getHeader("Content-Type")
response:setHeader(headerName, value)Set and overwrite a specific response header even if the header exists multiple times.response:setHeader("X-Foobar", "my value")Set the Content-Length header at your own risk.
response:addHeader(headerName, value)Add a response header, can add the same header multiple times.response:addHeader("X-Foobar", "my value")Add the Content-Length header at your own risk.
response:removeHeader(headerName)Remove a specific response header even if the header exists multiple times.response:removeHeader("Content-Length")
response:iterateHeaders()Iterate over all response headers.trace = request:getTracer() for n,v in response:iterateHeaders() do trace:debug("name is "..n.." and value is "..v) end
response:setBody(string)Set a response body. It's also possible to set binary string, 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. It is recommended to set the PRUNE_ACCEPT_ENCODING
response:getBody()Get the response body. This only makes sense with newly created response with nevis.filter.lua.response.new() and a side call (see dispatcher object). It is recommended to set the PRUNE_ACCEPT_ENCODING
response:send(status)Send a response and terminate the chain on request.response:setHeader("Content-Type", "text/html") response:setBody("<body><h1>302 Found</h1></body></html/>") response:send(302)