Class Rack::Handler::WEBrick
In: lib/rack/handler/webrick.rb
Parent: ::WEBrick::HTTPServlet::AbstractServlet

Methods

new   run   service  

Public Class methods

[Source]

    # File lib/rack/handler/webrick.rb, line 15
15:       def initialize(server, app)
16:         super server
17:         @app = app
18:       end

[Source]

    # File lib/rack/handler/webrick.rb, line 7
 7:       def self.run(app, options={})
 8:         server = ::WEBrick::HTTPServer.new(options)
 9:         server.mount "/", Rack::Handler::WEBrick, app
10:         trap(:INT) { server.shutdown }
11:         yield server  if block_given?
12:         server.start
13:       end

Public Instance methods

[Source]

    # File lib/rack/handler/webrick.rb, line 20
20:       def service(req, res)
21:         env = req.meta_vars
22:         env.delete_if { |k, v| v.nil? }
23: 
24:         env.update({"rack.version" => [0,1],
25:                      "rack.input" => StringIO.new(req.body.to_s),
26:                      "rack.errors" => STDERR,
27: 
28:                      "rack.multithread" => true,
29:                      "rack.multiprocess" => false,
30:                      "rack.run_once" => false,
31: 
32:                      "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
33:                    })
34: 
35:         env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
36:         env["QUERY_STRING"] ||= ""
37:         env["REQUEST_PATH"] ||= "/"
38:         env.delete "PATH_INFO"  if env["PATH_INFO"] == ""
39: 
40:         status, headers, body = @app.call(env)
41:         begin
42:           res.status = status.to_i
43:           headers.each { |k, vs|
44:             if k.downcase == "set-cookie"
45:               res.cookies.concat vs.to_a
46:             else
47:               vs.each { |v|
48:                 res[k] = v
49:               }
50:             end
51:           }
52:           body.each { |part|
53:             res.body << part
54:           }
55:         ensure
56:           body.close  if body.respond_to? :close
57:         end
58:       end

[Validate]