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

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 when using this method.response:setBody("<HTML><BODY>Hello world</BODY></HTML>")
response:getBody when using this method.newResp = nevis.filter.lua.response.new() dispatcher = request:getDispatcher("MyHttpConnectorServlet") dispatcher:forward(req, newResp) body = response:getBody()
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)