diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/indirector/rest.rb | 12 | ||||
| -rw-r--r-- | lib/puppet/network/http/api/v1.rb | 8 |
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb index e50dc68ae..0d3997221 100644 --- a/lib/puppet/indirector/rest.rb +++ b/lib/puppet/indirector/rest.rb @@ -72,7 +72,17 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus end def find(request) - return nil unless result = deserialize(network(request).get(indirection2uri(request), headers)) + uri, body = request_to_uri_and_body(request) + uri_with_query_string = "#{uri}?#{body}" + http_connection = network(request) + # WEBrick in Ruby 1.9.1 only supports up to 1024 character lines in an HTTP request + # http://redmine.ruby-lang.org/issues/show/3991 + response = if "GET #{uri_with_query_string} HTTP/1.1\r\n".length > 1024 + http_connection.post(uri, body, headers) + else + http_connection.get(uri_with_query_string, headers) + end + result = deserialize response result.name = request.key if result.respond_to?(:name=) result end diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index 5fe143979..61307f01e 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -8,6 +8,9 @@ module Puppet::Network::HTTP::API::V1 :plural => :search, :singular => :find }, + "POST" => { + :singular => :find, + }, "PUT" => { :singular => :save }, @@ -41,6 +44,11 @@ module Puppet::Network::HTTP::API::V1 "/#{request.environment.to_s}/#{indirection}/#{request.escaped_key}#{request.query_string}" end + def request_to_uri_and_body(request) + indirection = request.method == :search ? pluralize(request.indirection_name.to_s) : request.indirection_name.to_s + ["/#{request.environment.to_s}/#{indirection}/#{request.escaped_key}", request.query_string.sub(/^\?/,'')] + end + def indirection_method(http_method, indirection) raise ArgumentError, "No support for http method #{http_method}" unless METHOD_MAP[http_method] |
