20: def service(req, res)
21: env = req.meta_vars
22: env.delete_if { |k, v| v.nil? }
23:
24: env.update({"rack.version" => [0,1],
25: "rack.input" => StringIO.new(req.body.to_s),
26: "rack.errors" => STDERR,
27:
28: "rack.multithread" => true,
29: "rack.multiprocess" => false,
30: "rack.run_once" => false,
31:
32: "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
33: })
34:
35: env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
36: env["QUERY_STRING"] ||= ""
37: env["REQUEST_PATH"] ||= "/"
38: env.delete "PATH_INFO" if env["PATH_INFO"] == ""
39:
40: status, headers, body = @app.call(env)
41: begin
42: res.status = status.to_i
43: headers.each { |k, vs|
44: if k.downcase == "set-cookie"
45: res.cookies.concat vs.to_a
46: else
47: vs.each { |v|
48: res[k] = v
49: }
50: end
51: }
52: body.each { |part|
53: res.body << part
54: }
55: ensure
56: body.close if body.respond_to? :close
57: end
58: end