Class: Puppet::Network::HTTP::RackREST
- Inherits:
-
RackHttpHandler
- Object
- RackHttpHandler
- Puppet::Network::HTTP::RackREST
- Includes:
- Handler
- Defined in:
- lib/vendor/puppet/network/http/rack/rest.rb
Defined Under Namespace
Classes: RackFile
Constant Summary collapse
- HEADER_ACCEPT =
'HTTP_ACCEPT'.freeze
- ContentType =
'Content-Type'.freeze
- CHUNK_SIZE =
8192
Constants included from API::V1
Instance Attribute Summary
Attributes included from Handler
Instance Method Summary collapse
-
#accept_header(request) ⇒ Object
Retrieve the accept header from the http request.
-
#body(request) ⇒ Object
return the request body request.body has some limitiations, so we need to concat it back into a regular string, which is something puppet can use.
-
#content_type_header(request) ⇒ Object
Retrieve the accept header from the http request.
- #extract_client_info(request) ⇒ Object
-
#http_method(request) ⇒ Object
Return which HTTP verb was used in this request.
-
#initialize(args = {}) ⇒ RackREST
constructor
A new instance of RackREST.
-
#params(request) ⇒ Object
Return the query params for this request.
-
#path(request) ⇒ Object
what path was requested? (this is, without any query parameters).
- #set_content_type(response, format) ⇒ Object
-
#set_response(response, result, status = 200) ⇒ Object
produce the body of the response.
Methods included from Handler
#do_destroy, #do_exception, #do_find, #do_head, #do_save, #do_search, #format_to_mime, #format_to_use, #initialize_for_puppet, #model, #process, #request_format, #resolve_node
Methods included from RestAuthorization
#authconfig, #check_authorization
Methods included from API::V1
#indirection2uri, #indirection_method, #plurality, #pluralize, #request_to_uri_and_body, #uri2indirection
Methods inherited from RackHttpHandler
Constructor Details
#initialize(args = {}) ⇒ RackREST
Returns a new instance of RackREST.
29 30 31 32 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 29 def initialize(args={}) super() initialize_for_puppet(args) end |
Instance Method Details
#accept_header(request) ⇒ Object
Retrieve the accept header from the http request.
50 51 52 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 50 def accept_header(request) request.env[HEADER_ACCEPT] end |
#body(request) ⇒ Object
return the request body request.body has some limitiations, so we need to concat it back into a regular string, which is something puppet can use.
78 79 80 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 78 def body(request) request.body.read end |
#content_type_header(request) ⇒ Object
Retrieve the accept header from the http request.
55 56 57 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 55 def content_type_header(request) request.content_type end |
#extract_client_info(request) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 82 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 |
#http_method(request) ⇒ Object
Return which HTTP verb was used in this request.
60 61 62 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 60 def http_method(request) request.request_method end |
#params(request) ⇒ Object
Return the query params for this request.
65 66 67 68 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 65 def params(request) result = decode_params(request.params) result.merge(extract_client_info(request)) end |
#path(request) ⇒ Object
what path was requested? (this is, without any query parameters)
71 72 73 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 71 def path(request) request.path end |
#set_content_type(response, format) ⇒ Object
34 35 36 |
# File 'lib/vendor/puppet/network/http/rack/rest.rb', line 34 def set_content_type(response, format) response[ContentType] = format_to_mime(format) end |
#set_response(response, result, status = 200) ⇒ Object
produce the body of the response
39 40 41 42 43 44 45 46 47 |
# File 'lib/vendor/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 |