Class: Puppet::Network::HTTP::Request
- Defined in:
- lib/puppet/network/http/request.rb
Overview
This class is effectively public API, because a Request object is passed as a parameter to the current Handler subclass. Puppetserver implements its own Handler github.com/puppetlabs/puppetserver/blob/8.3.0/src/ruby/puppetserver-lib/puppet/server/network/http/handler.rb#L9 and the Request object is passed to its Handler#body method github.com/puppetlabs/puppetserver/blob/8.3.0/src/ruby/puppetserver-lib/puppet/server/network/http/handler.rb#L36
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#client_cert ⇒ Object
Returns the value of attribute client_cert.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#routing_path ⇒ Object
Returns the value of attribute routing_path.
Class Method Summary collapse
Instance Method Summary collapse
- #formatter ⇒ Object
- #response_formatters_for(supported_formats, default_accepted_formats = nil) ⇒ Object
- #route_into(prefix) ⇒ Object
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
9 10 11 |
# File 'lib/puppet/network/http/request.rb', line 9 def body @body end |
#client_cert ⇒ Object
Returns the value of attribute client_cert
9 10 11 |
# File 'lib/puppet/network/http/request.rb', line 9 def client_cert @client_cert end |
#headers ⇒ Object
Returns the value of attribute headers
9 10 11 |
# File 'lib/puppet/network/http/request.rb', line 9 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method
9 10 11 |
# File 'lib/puppet/network/http/request.rb', line 9 def method @method end |
#params ⇒ Object
Returns the value of attribute params
9 10 11 |
# File 'lib/puppet/network/http/request.rb', line 9 def params @params end |
#path ⇒ Object
Returns the value of attribute path
9 10 11 |
# File 'lib/puppet/network/http/request.rb', line 9 def path @path end |
#routing_path ⇒ Object
Returns the value of attribute routing_path
9 10 11 |
# File 'lib/puppet/network/http/request.rb', line 9 def routing_path @routing_path end |
Class Method Details
.from_hash(hash) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/puppet/network/http/request.rb', line 10 def self.from_hash(hash) symbol_members = members.collect(&:intern) unknown = hash.keys - symbol_members if unknown.empty? new(hash[:headers] || {}, hash[:params] || {}, hash[:method] || "GET", hash[:path], hash[:routing_path] || hash[:path], hash[:client_cert], hash[:body]) else raise ArgumentError, _("Unknown arguments: %{args}") % { args: unknown.collect(&:inspect).join(', ') } end end |
Instance Method Details
#formatter ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/puppet/network/http/request.rb', line 30 def formatter header = headers['content-type'] if header header.gsub!(/\s*;.*$/, '') # strip any charset format = Puppet::Network::FormatHandler.mime(header) return format if valid_network_format?(format) # TRANSLATORS "mime-type" is a keyword and should not be translated raise Puppet::Network::HTTP::Error::HTTPUnsupportedMediaTypeError.new( _("Client sent a mime-type (%{header}) that doesn't correspond to a format we support") % { header: headers['content-type'] }, Puppet::Network::HTTP::Issues::UNSUPPORTED_MEDIA_TYPE ) end raise Puppet::Network::HTTP::Error::HTTPBadRequestError.new( _("No Content-Type header was received, it isn't possible to unserialize the request"), Puppet::Network::HTTP::Issues::MISSING_HEADER_FIELD ) end |
#response_formatters_for(supported_formats, default_accepted_formats = nil) ⇒ Object
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 |
# File 'lib/puppet/network/http/request.rb', line 51 def response_formatters_for(supported_formats, default_accepted_formats = nil) accepted_formats = headers['accept'] || default_accepted_formats if accepted_formats.nil? raise Puppet::Network::HTTP::Error::HTTPBadRequestError.new(_("Missing required Accept header"), Puppet::Network::HTTP::Issues::MISSING_HEADER_FIELD) end formats = Puppet::Network::FormatHandler.most_suitable_formats_for( accepted_formats.split(/\s*,\s*/), supported_formats ) formats.find_all do |format| # we are only passed supported_formats that are suitable # and whose klass implements the required_methods valid_network_format?(format) end return formats unless formats.empty? raise Puppet::Network::HTTP::Error::HTTPNotAcceptableError.new( _("No supported formats are acceptable (Accept: %{accepted_formats})") % { accepted_formats: accepted_formats }, Puppet::Network::HTTP::Issues::UNSUPPORTED_FORMAT ) end |
#route_into(prefix) ⇒ Object
26 27 28 |
# File 'lib/puppet/network/http/request.rb', line 26 def route_into(prefix) self.class.new(headers, params, method, path, routing_path.sub(prefix, ''), client_cert, body) end |