Parent

Class Index [+]

Quicksearch

Rack::Handler::WEBrick

Public Class Methods

new(server, app) click to toggle source
    # File lib/rack/handler/webrick.rb, line 21
21:       def initialize(server, app)
22:         super server
23:         @app = Rack::ContentLength.new(app)
24:       end
run(app, options={}) click to toggle source
    # File lib/rack/handler/webrick.rb, line 8
 8:       def self.run(app, options={})
 9:         options[:BindAddress] = options.delete(:Host) if options[:Host]
10:         @server = ::WEBrick::HTTPServer.new(options)
11:         @server.mount "/", Rack::Handler::WEBrick, app
12:         yield @server  if block_given?
13:         @server.start
14:       end
shutdown() click to toggle source
    # File lib/rack/handler/webrick.rb, line 16
16:       def self.shutdown
17:         @server.shutdown
18:         @server = nil
19:       end

Public Instance Methods

service(req, res) click to toggle source
    # File lib/rack/handler/webrick.rb, line 26
26:       def service(req, res)
27:         env = req.meta_vars
28:         env.delete_if { |k, v| v.nil? }
29: 
30:         rack_input = StringIO.new(req.body.to_s)
31:         rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
32: 
33:         env.update({"rack.version" => Rack::VERSION,
34:                      "rack.input" => rack_input,
35:                      "rack.errors" => $stderr,
36: 
37:                      "rack.multithread" => true,
38:                      "rack.multiprocess" => false,
39:                      "rack.run_once" => false,
40: 
41:                      "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
42:                    })
43: 
44:         env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
45:         env["QUERY_STRING"] ||= ""
46:         env["REQUEST_PATH"] ||= "/"
47:         unless env["PATH_INFO"] == ""
48:           path, n = req.request_uri.path, env["SCRIPT_NAME"].length
49:           env["PATH_INFO"] = path[n, path.length-n]
50:         end
51: 
52:         status, headers, body = @app.call(env)
53:         begin
54:           res.status = status.to_i
55:           headers.each { |k, vs|
56:             if k.downcase == "set-cookie"
57:               res.cookies.concat vs.split("\n")
58:             else
59:               vs.split("\n").each { |v|
60:                 res[k] = v
61:               }
62:             end
63:           }
64:           body.each { |part|
65:             res.body << part
66:           }
67:         ensure
68:           body.close  if body.respond_to? :close
69:         end
70:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.