# class Puppet::Network::HTTP::WEBrickREST

### Public Class Methods

new(server, handler) click to toggle source
Calls superclass method

    # 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

### Public Instance Methods

accept_header(request) click to toggle source

    # File lib/puppet/network/http/webrick/rest.rb, line 27
    def accept_header(request)
      request["accept"]
    end

body(request) click to toggle source

    # File lib/puppet/network/http/webrick/rest.rb, line 43
    def body(request)
      request.body
    end

client_cert(request) click to toggle source

    # File lib/puppet/network/http/webrick/rest.rb, line 47
    def client_cert(request)
      request.client_cert
    end

client_information(request) click to toggle source

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

content_type_header(request) click to toggle source

    # File lib/puppet/network/http/webrick/rest.rb, line 31
    def content_type_header(request)
      request["content-type"]
    end

http_method(request) click to toggle source

    # File lib/puppet/network/http/webrick/rest.rb, line 35
    def http_method(request)
      request.request_method
    end

params(request) click to toggle source

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

path(request) click to toggle source

    # File lib/puppet/network/http/webrick/rest.rb, line 39
    def path(request)
      request.path
    end

service(request, response) click to toggle source

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_content_type(response, format) click to toggle source

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

set_response(response, result, status = 200) click to toggle source

    # 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