31: def self.serve(request, app)
32: env = request.env
33: env.delete "HTTP_CONTENT_LENGTH"
34:
35: request.in.extend ProperStream
36:
37: env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
38:
39: env.update({"rack.version" => [0,1],
40: "rack.input" => request.in,
41: "rack.errors" => request.err,
42:
43: "rack.multithread" => false,
44: "rack.multiprocess" => true,
45: "rack.run_once" => false,
46:
47: "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
48: })
49:
50: env["QUERY_STRING"] ||= ""
51: env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
52: env["REQUEST_PATH"] ||= "/"
53: env.delete "PATH_INFO" if env["PATH_INFO"] == ""
54: env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == ""
55: env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == ""
56:
57: status, headers, body = app.call(env)
58: begin
59: send_headers request.out, status, headers
60: send_body request.out, body
61: ensure
62: body.close if body.respond_to? :close
63: request.finish
64: end
65: end