Method: Puppet::Network::HTTP::Handler#process

Defined in:
lib/puppet/network/http/handler.rb

#process(request, response) ⇒ Object

handle an HTTP request



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet/network/http/handler.rb', line 44

def process(request, response)
  new_response = Puppet::Network::HTTP::Response.new(self, response)

  request_headers = headers(request)
  request_params = params(request)
  request_method = http_method(request)
  request_path = path(request)

  new_request = Puppet::Network::HTTP::Request.new(request_headers, request_params, request_method, request_path, request_path, client_cert(request), body(request))

  response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION] = Puppet.version

  profiler = configure_profiler(request_headers, request_params)

  Puppet::Util::Profiler.profile("Processed request #{request_method} #{request_path}", [:http, request_method, request_path]) do
    if route = @routes.find { |r| r.matches?(new_request) }
      route.process(new_request, new_response)
    else
      raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new("No route for #{new_request.method} #{new_request.path}", HANDLER_NOT_FOUND)
    end
  end

rescue Puppet::Network::HTTP::Error::HTTPError => e
  Puppet.info(e.message)
  new_response.respond_with(e.status, "application/json", e.to_json)
rescue StandardError => e
  http_e = Puppet::Network::HTTP::Error::HTTPServerError.new(e)
  Puppet.err(http_e.message)
  new_response.respond_with(http_e.status, "application/json", http_e.to_json)
ensure
  if profiler
    remove_profiler(profiler)
  end
  cleanup(request)
end