Class: WEBrick::CampingHandler

Inherits:
HTTPServlet::DefaultFileHandler
  • Object
show all
Defined in:
lib/camping/webrick.rb

Overview

a decent choice, for sure!

Instance Method Summary collapse

Constructor Details

#initialize(server, klass) ⇒ CampingHandler

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



39
40
41
42
# File 'lib/camping/webrick.rb', line 39

def initialize(server, klass)
    super(server, klass)
    @klass = klass
end

Instance Method Details

#service(req, resp) ⇒ Object

Handler for WEBrick requests (also aliased as do_POST).



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/camping/webrick.rb', line 44

def service(req, resp)
    controller = @klass.run((req.body and StringIO.new(req.body)), req.meta_vars)
    resp.status = controller.status
    @local_path = nil
    controller.headers.each do |k, v|
        if k =~ /^X-SENDFILE$/i
            @local_path = v
        else
            [*v].each do |vi|
                resp[k] = vi
            end
        end
    end

    if @local_path
        do_GET(req, res)
    else
        resp.body = controller.body.to_s
    end
end