summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network/http/mongrel
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-03-12 22:26:12 -0500
committerLuke Kanies <luke@madstop.com>2008-04-11 13:10:33 -0500
commite86fde2facafd56ee12d7e748b1c8cad916253bf (patch)
tree2d7595566a3f36b5596430c492da3def1b507951 /lib/puppet/network/http/mongrel
parentc2f8c69af368a8ba496da4ef0023ac5f0885e3c0 (diff)
This is the first version where mongrel and webrick are reliably startable and stoppable via Puppet::Network::Server.
Added a network/server integration spec, testing startup, shutdown, reachability, and collision of webrick and mongrel servers in the new network code. Converted Puppet::Network::HTTP::Handler class to a module, as mongrel Handler should be subclassed; converting subclasses to include the module instead. Mongrel will actually stop if you .stop it, graceful_shutdown didn't seem quite so reliable. Webrick requires running in its own Thread to avoid hanging the entire process; this requires introduction of a Mutex to make things safe. We're only supporting the REST protocol. Made this explicit. Fixed http server setup args, w/ specs, ah the glory of integration testing.
Diffstat (limited to 'lib/puppet/network/http/mongrel')
-rw-r--r--lib/puppet/network/http/mongrel/rest.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb
index 6c24e360c..7cb6f67bf 100644
--- a/lib/puppet/network/http/mongrel/rest.rb
+++ b/lib/puppet/network/http/mongrel/rest.rb
@@ -1,36 +1,45 @@
require 'puppet/network/http/handler'
-class Puppet::Network::HTTP::MongrelREST < Puppet::Network::HTTP::Handler
+class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler
+
+ include Puppet::Network::HTTP::Handler
private
-
+
+ # have this mongrel @server listen for /foo and /foos REST endpoints
def register_handler
@server.register('/' + @handler.to_s, self)
@server.register('/' + @handler.to_s + 's', self)
end
+ # which HTTP verb was used in this request
def http_method(request)
request.params[Mongrel::Const::REQUEST_METHOD]
end
+ # what path was requested?
def path(request)
# LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
x = '/' + request.params[Mongrel::Const::REQUEST_PATH].split('/')[1]
end
+ # return the key included in the request path
def request_key(request)
# LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
x = request.params[Mongrel::Const::REQUEST_PATH].split('/')[2]
end
+ # return the request body
def body(request)
request.body
end
+ # return the query params for this request
def params(request)
Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"])
end
+ # produce the body of the response
def encode_result(request, response, result, status = 200)
response.start(status) do |head, body|
body.write(result)