13: def self.serve(app)
14: app = Rack::ContentLength.new(app)
15:
16: env = ENV.to_hash
17: env.delete "HTTP_CONTENT_LENGTH"
18: env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
19:
20: rack_input = RewindableInput.new($stdin.read.to_s)
21:
22: env.update(
23: "rack.version" => Rack::VERSION,
24: "rack.input" => rack_input,
25: "rack.errors" => $stderr,
26: "rack.multithread" => false,
27: "rack.multiprocess" => true,
28: "rack.run_once" => false,
29: "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
30: )
31:
32: env["QUERY_STRING"] ||= ""
33: env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
34: env["REQUEST_PATH"] ||= "/"
35: status, headers, body = app.call(env)
36: begin
37: send_headers status, headers
38: send_body body
39: ensure
40: body.close if body.respond_to? :close
41: end
42: ensure
43: rack_input.close
44: end