| Class | Rack::Handler::FastCGI |
| In: |
lib/rack/handler/fastcgi.rb
|
| Parent: | Object |
# File lib/rack/handler/fastcgi.rb, line 7
7: def self.run(app, options={})
8: file = options[:File] and STDIN.reopen(UNIXServer.new(file))
9: port = options[:Port] and STDIN.reopen(TCPServer.new(port))
10: FCGI.each { |request|
11: serve request, app
12: }
13: end
# File lib/rack/handler/fastcgi.rb, line 76
76: def self.send_body(out, body)
77: body.each { |part|
78: out.print part
79: out.flush
80: }
81: end
# File lib/rack/handler/fastcgi.rb, line 65
65: def self.send_headers(out, status, headers)
66: out.print "Status: #{status}\r\n"
67: headers.each { |k, vs|
68: vs.each { |v|
69: out.print "#{k}: #{v}\r\n"
70: }
71: }
72: out.print "\r\n"
73: out.flush
74: end
# File lib/rack/handler/fastcgi.rb, line 31
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:
55: status, headers, body = app.call(env)
56: begin
57: send_headers request.out, status, headers
58: send_body request.out, body
59: ensure
60: body.close if body.respond_to? :close
61: request.finish
62: end
63: end