Class: Puppet::Network::HTTP::WEBrickREST
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Puppet::Network::HTTP::WEBrickREST
- Includes:
- Handler
- Defined in:
- lib/vendor/puppet/network/http/webrick/rest.rb
Constant Summary
Constants included from API::V1
Instance Attribute Summary
Attributes included from Handler
Instance Method Summary collapse
- #accept_header(request) ⇒ Object
- #body(request) ⇒ Object
-
#client_information(request) ⇒ Object
Retrieve node/cert/ip information from the request object.
- #content_type_header(request) ⇒ Object
- #http_method(request) ⇒ Object
-
#initialize(server, handler) ⇒ WEBrickREST
constructor
A new instance of WEBrickREST.
-
#params(request) ⇒ Object
Retrieve the request parameters, including authentication information.
- #path(request) ⇒ Object
-
#service(request, response) ⇒ Object
WEBrick uses a service method to respond to requests.
-
#set_content_type(response, format) ⇒ Object
Set the specified format as the content type of the response.
- #set_response(response, result, status = 200) ⇒ Object
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
Constructor Details
#initialize(server, handler) ⇒ WEBrickREST
Returns a new instance of WEBrickREST.
9 10 11 12 13 |
# File 'lib/vendor/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 |
Instance Method Details
#accept_header(request) ⇒ Object
27 28 29 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 27 def accept_header(request) request["accept"] end |
#body(request) ⇒ Object
43 44 45 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 43 def body(request) request.body end |
#client_information(request) ⇒ Object
Retrieve node/cert/ip information from the request object.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 62 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) ⇒ Object
31 32 33 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 31 def content_type_header(request) request["content-type"] end |
#http_method(request) ⇒ Object
35 36 37 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 35 def http_method(request) request.request_method end |
#params(request) ⇒ Object
Retrieve the request parameters, including authentication information.
16 17 18 19 20 |
# File 'lib/vendor/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) ⇒ Object
39 40 41 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 39 def path(request) request.path end |
#service(request, response) ⇒ Object
WEBrick uses a service method to respond to requests. Simply delegate to the handler response method.
23 24 25 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 23 def service(request, response) process(request, response) end |
#set_content_type(response, format) ⇒ Object
Set the specified format as the content type of the response.
48 49 50 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 48 def set_content_type(response, format) response["content-type"] = format_to_mime(format) end |
#set_response(response, result, status = 200) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/vendor/puppet/network/http/webrick/rest.rb', line 52 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 |