8: def self.serve(app)
9: env = ENV.to_hash
10: env.delete "HTTP_CONTENT_LENGTH"
11:
12: env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
13:
14: env.update({"rack.version" => [0,1],
15: "rack.input" => STDIN,
16: "rack.errors" => STDERR,
17:
18: "rack.multithread" => false,
19: "rack.multiprocess" => true,
20: "rack.run_once" => true,
21:
22: "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
23: })
24:
25: env["QUERY_STRING"] ||= ""
26: env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
27: env["REQUEST_PATH"] ||= "/"
28:
29: status, headers, body = app.call(env)
30: begin
31: send_headers status, headers
32: send_body body
33: ensure
34: body.close if body.respond_to? :close
35: end
36: end