Class Rack::Handler::CGI
In: lib/rack/handler/cgi.rb
Parent: Object

Methods

run   send_body   send_headers   serve  

Public Class methods

[Source]

   # File lib/rack/handler/cgi.rb, line 4
4:       def self.run(app, options=nil)
5:         serve app
6:       end

[Source]

    # File lib/rack/handler/cgi.rb, line 49
49:       def self.send_body(body)
50:         body.each { |part|
51:           STDOUT.print part
52:           STDOUT.flush
53:         }
54:       end

[Source]

    # File lib/rack/handler/cgi.rb, line 38
38:       def self.send_headers(status, headers)
39:         STDOUT.print "Status: #{status}\r\n"
40:         headers.each { |k, vs|
41:           vs.each { |v|
42:             STDOUT.print "#{k}: #{v}\r\n"
43:           }
44:         }
45:         STDOUT.print "\r\n"
46:         STDOUT.flush
47:       end

[Source]

    # File lib/rack/handler/cgi.rb, line 8
 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

[Validate]