Sha256: ea490161f332c32627a180c49f229088001c0cfd31a037410dfce18a8fab3abf

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
puppet-0.24.0 lib/puppet/network/http/webrick.rb
puppet-0.24.2 lib/puppet/network/http/webrick.rb
puppet-0.24.1 lib/puppet/network/http/webrick.rb
puppet-0.24.4 lib/puppet/network/http/webrick.rb
puppet-0.24.3 lib/puppet/network/http/webrick.rb