summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network/http/webrick.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-12 22:11:40 -0600
committerLuke Kanies <luke@madstop.com>2007-11-12 22:11:40 -0600
commitfa1924eb04a2d6600349eddf13e1f3e62b45d6ce (patch)
tree978aa0e92812f5854978048162c6e2ab752dad72 /lib/puppet/network/http/webrick.rb
parenta535cbbe148802c0afe62cd2d5b29d0768b3a0f0 (diff)
parent72510bfaa65e97f4eaaf246ef8f1c155716967b6 (diff)
downloadpuppet-fa1924eb04a2d6600349eddf13e1f3e62b45d6ce.tar.gz
puppet-fa1924eb04a2d6600349eddf13e1f3e62b45d6ce.tar.xz
puppet-fa1924eb04a2d6600349eddf13e1f3e62b45d6ce.zip
Merge branch 'master' of ssh://reductivelabs.com/opt/rl/git/puppet-luke
Diffstat (limited to 'lib/puppet/network/http/webrick.rb')
-rw-r--r--lib/puppet/network/http/webrick.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
new file mode 100644
index 000000000..c4b2ed3c6
--- /dev/null
+++ b/lib/puppet/network/http/webrick.rb
@@ -0,0 +1,51 @@
+require 'webrick'
+require 'webrick/https'
+require 'puppet/network/http/webrick/rest'
+require 'puppet/network/http/webrick/xmlrpc'
+
+class Puppet::Network::HTTP::WEBrick
+ def initialize(args = {})
+ @listening = false
+ end
+
+ def listen(args = {})
+ 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]
+ @server = WEBrick::HTTPServer.new(:BindAddress => args[:address], :Port => args[:port])
+ setup_handlers
+ @server.start
+ @listening = true
+ end
+
+ def unlisten
+ raise "WEBrick server is not listening" unless listening?
+ @server.shutdown
+ @listening = false
+ end
+
+ def listening?
+ @listening
+ end
+
+ private
+
+ def setup_handlers
+ @protocols.each do |protocol|
+ @handlers.each do |handler|
+ class_for_protocol(protocol).new(:server => @server, :handler => handler)
+ end
+ end
+ end
+
+ def class_for_protocol(protocol)
+ return Puppet::Network::HTTP::WEBrickREST if protocol.to_sym == :rest
+ return Puppet::Network::HTTP::WEBrickXMLRPC if protocol.to_sym == :xmlrpc
+ raise ArgumentError, "Unknown protocol [#{protocol}]."
+ end
+end