diff options
author | Luke Kanies <luke@madstop.com> | 2008-07-26 22:46:26 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-07-29 00:51:21 -0500 |
commit | e3350caeec3a662b0b92ec2dee372563a493fa11 (patch) | |
tree | 26630fdca2c343d91b7e6b8fe8fa8e67b4b68a47 /lib | |
parent | b3914c367f470dd37a846d01207228d6ded40c6d (diff) | |
download | puppet-e3350caeec3a662b0b92ec2dee372563a493fa11.tar.gz puppet-e3350caeec3a662b0b92ec2dee372563a493fa11.tar.xz puppet-e3350caeec3a662b0b92ec2dee372563a493fa11.zip |
Drastically simplifying the REST implementation tests.
Nearly all of the tests are now written just once, in
the Handler module. The Mongrel and Webrick tests just
validate that they provide the interface and how they do
so.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/network/http/mongrel/rest.rb | 22 | ||||
-rw-r--r-- | lib/puppet/network/http/webrick/rest.rb | 13 |
2 files changed, 25 insertions, 10 deletions
diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb index 520ad67f0..d6c2e4679 100644 --- a/lib/puppet/network/http/mongrel/rest.rb +++ b/lib/puppet/network/http/mongrel/rest.rb @@ -4,24 +4,28 @@ class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler include Puppet::Network::HTTP::Handler + ACCEPT_HEADER = "HTTP_ACCEPT".freeze # yay, zed's a crazy-man + def initialize(args={}) super() initialize_for_puppet(args) end - # Return the query params for this request. We had to expose this method for - # testing purposes. - def params(request) - Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"]).merge(client_info(request)) + def accept_header(request) + request.params[ACCEPT_HEADER] end - private - # which HTTP verb was used in this request def http_method(request) request.params[Mongrel::Const::REQUEST_METHOD] end + # Return the query params for this request. We had to expose this method for + # testing purposes. + def params(request) + Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"]).merge(client_info(request)) + end + # what path was requested? def path(request) # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] @@ -39,8 +43,12 @@ class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler request.body end + def set_content_type(response, format) + response.header['Content-Type'] = format + end + # produce the body of the response - def encode_result(request, response, result, status = 200) + def set_response(response, result, status = 200) response.start(status) do |head, body| body.write(result) end diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb index a235fb4f3..c7cc06916 100644 --- a/lib/puppet/network/http/webrick/rest.rb +++ b/lib/puppet/network/http/webrick/rest.rb @@ -10,7 +10,7 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet initialize_for_puppet(:server => server, :handler => handler) end - # We had to expose this method for testing purposes. + # Retrieve the request parameters, including authentication information. def params(request) result = request.query result.merge(client_information(request)) @@ -21,7 +21,9 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet process(request, response) end - private + def accept_header(request) + request[:accept] + end def http_method(request) request.request_method @@ -41,7 +43,12 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet request.body end - def encode_result(request, response, result, status = 200) + # Set the specified format as the content type of the response. + def set_content_type(response, format) + response[:content_type] = format + end + + def set_response(response, result, status = 200) response.status = status response.body = result end |