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.

Mounting a Camping App

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("/") { ... }

How Does it Compare?

Compared to other handlers, WEBrick is well-equipped in terms of features.

  • The X-Sendfile header is supported, along with etags and modification time headers for the file served. Since this handler is a subclass of WEBrick::HTTPServlet::DefaultFileHandler, all of its logic is used.
  • IO is streaming up and down. When you upload a file, it is streamed to the server‘s filesystem. When you download a file, it is streamed to your browser.

While WEBrick is a bit slower than Mongrel and FastCGI options, it‘s a decent choice, for sure!

Methods

new   service  

Public Class methods

Creates a CampingHandler, which answers for the application within klass.

[Source]

    # File lib/camping/webrick.rb, line 39
39:     def initialize(server, klass)
40:         super(server, klass)
41:         @klass = klass
42:     end

Public Instance methods

Handler for WEBrick requests (also aliased as do_POST).

[Source]

    # 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

[Validate]