require 'securerandom' require 'json' require 'unicorn-cuba-base/stats' module Plugin module ResponseHelpers extend Stats def_stats( :total_write_multipart, :total_write, :total_write_part, :total_write_error, :total_write_error_part ) def write(code, content_type, body, headers = {}) req.body.read # read all remaining upload before we send response so that client will read it res.status = code res["Content-Type"] = content_type headers.each do |key, value| res[key] = value end ResponseHelpers.stats.incr_total_write res.write body end def write_text(code, content_type, msg, headers = {}) msg = msg.join("\r\n") if msg.is_a? Array write code, content_type, (msg.gsub(/(? code) end def write_epilogue res.write "--#{@boundary}--\r\n" end end end