Class | WEBrick::CampingHandler |
In: |
lib/camping/webrick.rb
|
Parent: | WEBrick::HTTPServlet::DefaultFileHandler |
WEBrick::CampingHandler is a very simple handle for hosting Camping apps in a WEBrick server. It‘s used much like any other WEBrick handler.
Assuming Camping.goes(:Blog), the Blog application can be mounted alongside other WEBrick mounts.
s = WEBrick::HTTPServer.new(:BindAddress => host, :Port => port) s.mount "/blog", WEBrick::CampingHandler, Blog s.mount_proc("/") { ... }
Compared to other handlers, WEBrick is well-equipped in terms of features.
While WEBrick is a bit slower than Mongrel and FastCGI options, it‘s a decent choice, for sure!
Creates a CampingHandler, which answers for the application within klass.
# File lib/camping/webrick.rb, line 39 39: def initialize(server, klass) 40: super(server, klass) 41: @klass = klass 42: end
Handler for WEBrick requests (also aliased as do_POST).
# File lib/camping/webrick.rb, line 44 44: def service(req, resp) 45: controller = @klass.run((req.body and StringIO.new(req.body)), req.meta_vars) 46: resp.status = controller.status 47: @local_path = nil 48: controller.headers.each do |k, v| 49: if k =~ /^X-SENDFILE$/i 50: @local_path = v 51: else 52: [*v].each do |vi| 53: resp[k] = vi 54: end 55: end 56: end 57: 58: if @local_path 59: do_GET(req, res) 60: else 61: resp.body = controller.body.to_s 62: end 63: end