summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network/http/webrick/rest.rb
blob: dd0c84d617e8cd34f1ab5883ca7805da513683a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'puppet/network/http/handler'

class Puppet::Network::HTTP::WEBrickREST < Puppet::Network::HTTP::Handler

    # WEBrick uses a service() method to respond to requests.  Simply delegate to the handler response() method.
    def service(request, response)
        process(request, response)
    end

  private
    
    def register_handler
        @server.mount('/' + @handler.to_s, self)
        @server.mount('/' + @handler.to_s + 's', self)
    end

    def http_method(request)
        request.request_method
    end
    
    def path(request)
        '/' + request.path.split('/')[1]
    end
    
    def request_key(request)
        request.path.split('/')[2]
    end
    
    def body(request)
        request.body
    end
    
    def params(request)
        request.query
    end
    
    def encode_result(request, response, result, status = 200)
        response.status = status
        response.body = result
    end
end