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