# File lib/puppet/network/http/rack/rest.rb, line 29 def initialize(args={}) super() initialize_for_puppet(args) end
Retrieve the accept header from the http request.
# File lib/puppet/network/http/rack/rest.rb, line 50 def accept_header(request) request.env[HEADER_ACCEPT] end
return the request body
# File lib/puppet/network/http/rack/rest.rb, line 76 def body(request) request.body.read end
Passenger freaks out if we finish handling the request without reading any part of the body, so make sure we have.
# File lib/puppet/network/http/rack/rest.rb, line 92 def cleanup(request) request.body.read(1) nil end
# File lib/puppet/network/http/rack/rest.rb, line 80 def client_cert(request) # This environment variable is set by mod_ssl, note that it # requires the `+ExportCertData` option in the `SSLOptions` directive cert = request.env['SSL_CLIENT_CERT'] # NOTE: The SSL_CLIENT_CERT environment variable will be the empty string # when Puppet agent nodes have not yet obtained a signed certificate. return nil if cert.nil? or cert.empty? OpenSSL::X509::Certificate.new(cert) end
Retrieve the accept header from the http request.
# File lib/puppet/network/http/rack/rest.rb, line 55 def content_type_header(request) request.content_type end
# File lib/puppet/network/http/rack/rest.rb, line 97 def extract_client_info(request) result = {} result[:ip] = request.ip # if we find SSL info in the headers, use them to get a hostname. # try this with :ssl_client_header, which defaults should work for # Apache with StdEnvVars. if dn = request.env[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/) result[:node] = dn_matchdata[1].to_str result[:authenticated] = (request.env[Puppet[:ssl_client_verify_header]] == 'SUCCESS') else result[:node] = resolve_node(result) result[:authenticated] = false end result end
Return which HTTP verb was used in this request.
# File lib/puppet/network/http/rack/rest.rb, line 60 def http_method(request) request.request_method end
Return the query params for this request.
# File lib/puppet/network/http/rack/rest.rb, line 65 def params(request) result = decode_params(request.params) result.merge(extract_client_info(request)) end
what path was requested? (this is, without any query parameters)
# File lib/puppet/network/http/rack/rest.rb, line 71 def path(request) request.path end
# File lib/puppet/network/http/rack/rest.rb, line 34 def set_content_type(response, format) response[ContentType] = format_to_mime(format) end
produce the body of the response
# File lib/puppet/network/http/rack/rest.rb, line 39 def set_response(response, result, status = 200) response.status = status unless result.is_a?(File) response.write result else response["Content-Length"] = result.stat.size.to_s response.body = RackFile.new(result) end end