Class: Puppet::Network::HTTP::MongrelREST
- Inherits:
-
Mongrel::HttpHandler
- Object
- Mongrel::HttpHandler
- Puppet::Network::HTTP::MongrelREST
- Includes:
- Handler
- Defined in:
- lib/vendor/puppet/network/http/mongrel/rest.rb
Constant Summary collapse
- ACCEPT_HEADER =
yay, zed’s a crazy-man
"HTTP_ACCEPT".freeze
Constants included from API::V1
Instance Attribute Summary
Attributes included from Handler
Instance Method Summary collapse
- #accept_header(request) ⇒ Object
-
#body(request) ⇒ Object
return the request body.
- #client_info(request) ⇒ Object
- #content_type_header(request) ⇒ Object
-
#http_method(request) ⇒ Object
which HTTP verb was used in this request.
-
#initialize(args = {}) ⇒ MongrelREST
constructor
A new instance of MongrelREST.
-
#params(request) ⇒ Object
Return the query params for this request.
-
#path(request) ⇒ Object
what path was requested?.
- #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
Constructor Details
#initialize(args = {}) ⇒ MongrelREST
Returns a new instance of MongrelREST.
9 10 11 12 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 9 def initialize(args={}) super() initialize_for_puppet(args) end |
Instance Method Details
#accept_header(request) ⇒ Object
14 15 16 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 14 def accept_header(request) request.params[ACCEPT_HEADER] end |
#body(request) ⇒ Object
return the request body
45 46 47 48 49 50 51 52 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 45 def body(request) body = request.body.read # We rewind the body, since read on a StringIO is destructive, and # subsequent reads will return an empty string. request.body.rewind body end |
#client_info(request) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 81 def client_info(request) result = {} params = request.params result[:ip] = params["HTTP_X_FORWARDED_FOR"] ? params["HTTP_X_FORWARDED_FOR"].split(',').last.strip : params["REMOTE_ADDR"] # JJM #906 The following dn.match regular expression is forgiving # enough to match the two Distinguished Name string contents # coming from Apache, Pound or other reverse SSL proxies. if dn = params[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/) result[:node] = dn_matchdata[1].to_str result[:authenticated] = (params[Puppet[:ssl_client_verify_header]] == 'SUCCESS') else result[:node] = resolve_node(result) result[:authenticated] = false end result end |
#content_type_header(request) ⇒ Object
18 19 20 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 18 def content_type_header(request) request.params["HTTP_CONTENT_TYPE"] end |
#http_method(request) ⇒ Object
which HTTP verb was used in this request
23 24 25 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 23 def http_method(request) request.params[Mongrel::Const::REQUEST_METHOD] end |
#params(request) ⇒ Object
Return the query params for this request. We had to expose this method for testing purposes.
29 30 31 32 33 34 35 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 29 def params(request) params = Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"]) params.merge!(Mongrel::HttpRequest.query_parse(body(request))) if http_method(request).upcase == 'POST' params = decode_params(params) params.merge(client_info(request)) end |
#path(request) ⇒ Object
what path was requested?
38 39 40 41 42 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 38 def path(request) # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] #x = '/' + request.params[Mongrel::Const::REQUEST_PATH] request.params[Mongrel::Const::REQUEST_PATH] end |
#set_content_type(response, format) ⇒ Object
54 55 56 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 54 def set_content_type(response, format) response.header['Content-Type'] = format_to_mime(format) end |
#set_response(response, result, status = 200) ⇒ Object
produce the body of the response
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vendor/puppet/network/http/mongrel/rest.rb', line 59 def set_response(response, result, status = 200) # Set the 'reason' (or 'message', as it's called in Webrick), when # we have a failure, unless we're on a version of mongrel that doesn't # support this. if status < 300 unless result.is_a?(File) response.start(status) { |head, body| body.write(result) } else response.start(status) { |head, body| } response.send_status(result.stat.size) response.send_header response.send_file(result.path) end else begin response.start(status,false,result) { |head, body| body.write(result) } rescue ArgumentError response.start(status) { |head, body| body.write(result) } end end end |