# File lib/puppet/network/http/webrick/rest.rb, line 9 def initialize(server, handler) raise ArgumentError, "server is required" unless server super(server) initialize_for_puppet(:server => server, :handler => handler) end
# File lib/puppet/network/http/webrick/rest.rb, line 27 def accept_header(request) request["accept"] end
# File lib/puppet/network/http/webrick/rest.rb, line 43 def body(request) request.body end
# File lib/puppet/network/http/webrick/rest.rb, line 47 def client_cert(request) request.client_cert end
Retrieve node/cert/ip information from the request object.
# File lib/puppet/network/http/webrick/rest.rb, line 66 def client_information(request) result = {} if peer = request.peeraddr and ip = peer[3] result[:ip] = ip end # If they have a certificate (which will almost always be true) # then we get the hostname from the cert, instead of via IP # info result[:authenticated] = false if cert = request.client_cert and nameary = cert.subject.to_a.find { |ary| ary[0] == "CN" } result[:node] = nameary[1] result[:authenticated] = true else result[:node] = resolve_node(result) end result end
# File lib/puppet/network/http/webrick/rest.rb, line 31 def content_type_header(request) request["content-type"] end
# File lib/puppet/network/http/webrick/rest.rb, line 35 def http_method(request) request.request_method end
Retrieve the request parameters, including authentication information.
# File lib/puppet/network/http/webrick/rest.rb, line 16 def params(request) result = request.query result = decode_params(result) result.merge(client_information(request)) end
# File lib/puppet/network/http/webrick/rest.rb, line 39 def path(request) request.path end
WEBrick uses a service method to respond to requests. Simply delegate to the handler response method.
# File lib/puppet/network/http/webrick/rest.rb, line 23 def service(request, response) process(request, response) end
Set the specified format as the content type of the response.
# File lib/puppet/network/http/webrick/rest.rb, line 52 def set_content_type(response, format) response["content-type"] = format_to_mime(format) end
# File lib/puppet/network/http/webrick/rest.rb, line 56 def set_response(response, result, status = 200) response.status = status if status >= 200 and status != 304 response.body = result response["content-length"] = result.stat.size if result.is_a?(File) end response.reason_phrase = result if status < 200 or status >= 300 end