summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/network/http/mongrel.rb23
-rw-r--r--lib/puppet/network/http/webrick.rb22
-rw-r--r--spec/unit/network/http/mongrel.rb36
-rw-r--r--spec/unit/network/http/webrick.rb23
4 files changed, 93 insertions, 11 deletions
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb
index bbba69fe3..ab1e616b1 100644
--- a/lib/puppet/network/http/mongrel.rb
+++ b/lib/puppet/network/http/mongrel.rb
@@ -6,10 +6,17 @@ class Puppet::Network::HTTP::Mongrel
end
def listen(args = {})
- raise ArgumentError, ":handlers must be specified." if !args[:handlers] or args[:handlers].keys.empty?
+ raise ArgumentError, ":handlers must be specified." if !args[:handlers] or args[:handlers].empty?
+ raise ArgumentError, ":protocols must be specified." if !args[:protocols] or args[:protocols].empty?
raise ArgumentError, ":address must be specified." unless args[:address]
raise ArgumentError, ":port must be specified." unless args[:port]
raise "Mongrel server is already listening" if listening?
+
+ @protocols = args[:protocols]
+ @handlers = args[:handlers]
+
+ setup_handlers
+
@server = Mongrel::HttpServer.new(args[:address], args[:port])
@server.run
@listening = true
@@ -24,4 +31,18 @@ class Puppet::Network::HTTP::Mongrel
def listening?
@listening
end
+
+ private
+
+ def setup_handlers
+ @protocols.each do |protocol|
+ @handlers.each do |handler|
+ class_for_protocol_handler(protocol, handler).new
+ end
+ end
+ end
+
+ def class_for_protocol_handler(protocol, handler)
+ Class.new
+ end
end
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index b74bf441e..00d13437c 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -7,11 +7,17 @@ class Puppet::Network::HTTP::WEBrick
end
def listen(args = {})
- raise ArgumentError, ":handlers must be specified." if !args[:handlers] or args[:handlers].keys.empty?
+ raise ArgumentError, ":handlers must be specified." if !args[:handlers] or args[:handlers].empty?
+ raise ArgumentError, ":protocols must be specified." if !args[:protocols] or args[:protocols].empty?
raise ArgumentError, ":address must be specified." unless args[:address]
raise ArgumentError, ":port must be specified." unless args[:port]
raise "WEBrick server is already listening" if listening?
+ @protocols = args[:protocols]
+ @handlers = args[:handlers]
+
+ setup_handlers
+
@server = WEBrick::HTTPServer.new(:BindAddress => args[:address], :Port => args[:port])
# TODO / FIXME is this really necessary? -- or can we do it in both mongrel and webrick?
@@ -30,4 +36,18 @@ class Puppet::Network::HTTP::WEBrick
def listening?
@listening
end
+
+ private
+
+ def setup_handlers
+ @handlers.each do |handler|
+ @protocols.each do |protocol|
+ class_for_protocol_handler(protocol, handler).new
+ end
+ end
+ end
+
+ def class_for_protocol_handler(protocol, handler)
+ Class.new
+ end
end
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index f964e6844..6c8b65582 100644
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -18,7 +18,7 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
@mock_mongrel = mock('mongrel')
@mock_mongrel.stubs(:run)
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail if already listening" do
@@ -30,6 +30,10 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
end
+ it "should require at least one protocol" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :protocols == k}) }.should raise_error(ArgumentError)
+ end
+
it "should require a listening address to be specified" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
end
@@ -56,8 +60,31 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
@server.should be_listening
end
- it "should instantiate a specific handler (mongrel+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)"
- it "should mount handlers on a mongrel path"
+ it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do
+ @listen_params[:handlers].each do |handler|
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
+ mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
+ mock_handler_class.expects(:new).returns(mock_handler)
+ @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
+ end
+ end
+ @server.listen(@listen_params)
+ end
+
+ it "should mount each handler on a mongrel path" do
+ pending "a moment of clarity"
+ @listen_params[:handlers].each do |handler|
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
+ mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
+ mock_handler_class.stubs(:new).returns(mock_handler)
+ @server.stubs(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
+ # TODO / FIXME : HERE -- need to begin resolving the model behind the indirection
+ end
+ end
+ @server.listen(@listen_params)
+ end
end
describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do
@@ -65,9 +92,8 @@ describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do
@mock_mongrel = mock('mongrel httpserver')
@mock_mongrel.stubs(:run)
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
-
@server = Puppet::Network::HTTP::Mongrel.new
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail unless listening" do
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 804be4c33..b94a6a78d 100644
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -19,7 +19,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@mock_webrick = mock('webrick')
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail if already listening" do
@@ -31,6 +31,10 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
end
+ it "should require at least one protocol" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :protocols == k}) }.should raise_error(ArgumentError)
+ end
+
it "should require a listening address to be specified" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
end
@@ -55,8 +59,19 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@server.listen(@listen_params)
@server.should be_listening
end
-
- it "should instantiate a specific handler (webrick+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)"
+
+ it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do
+ @listen_params[:handlers].each do |handler|
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
+ mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
+ mock_handler_class.expects(:new).returns(mock_handler)
+ @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
+ end
+ end
+ @server.listen(@listen_params)
+ end
+
it "should mount handlers on a webrick path"
end
@@ -68,7 +83,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
@server.stubs(:shutdown)
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail unless listening" do