+
+
+ local host = self.vhosts[message.env.HTTP_HOST] or self.host
+ if not host then
+ self:error( client, 500, "Unable to find matching host" )
+ break;
+ end
+
+ coroutine.yield()
+
+ local response, sourceout = host:process(
+ message, sourcein, sinkerr,
+ client, io.stderr
+ )
+ if not response then
+ self:error( client, 500, "Error processing handler" )
+ end
+
+ coroutine.yield()
+
+ -- Post process response
+ local sinkmode = close and "close-when-done" or "keep-open"
+
+ if sourceout then
+ if not response.headers["Content-Length"] then
+ if message.http_version == 1.1 then
+ response.headers["Transfer-Encoding"] = "chunked"
+ sinkmode = "http-chunked"
+ else
+ close = true
+ sinkmode = "close-when-done"
+ end
+ end
+ end
+
+ if close then
+ response.headers["Connection"] = "close"
+ end
+
+
+ local sinkout = socket.sink(sinkmode, client)
+
+ local header =
+ message.env.SERVER_PROTOCOL .. " " ..
+ tostring(response.status) .. " " ..
+ luci.http.protocol.statusmsg[response.status] .. "\r\n"
+
+
+ for k,v in pairs(response.headers) do
+ header = header .. k .. ": " .. v .. "\r\n"
+ end
+
+ client:send(header .. "\r\n")
+
+ if sourceout then
+ local eof = false
+ repeat
+ coroutine.yield()
+ eof = not ltn12.pump.step(sourceout, sinkout)
+ until eof
+ end
+ until close
+
+ client:close()