require "rack" require "rack/utils" module Rackbal class HostPool include Singleton attr_accessor :host_pool class Host attr_accessor :host, :port, :priority, :request_count, :in_use def initialize(host,port,priority = 0,request_count = 0) @host = host @port = port @priority = priority @request_count = request_count @in_use = false end def is_host(in_host,in_port) return (@host == in_host && @port == in_port) end end def add_host(host,port,priority = 0) end def remove_host(host_address,host_port) @host_pool.reject!{|host| host.is_host(host_address,host_port)} if @host_pool end def next_host end end # http://rack.rubyforge.org/doc/classes/Rack/Forwarder.html # Forward class ripped form html above. I can not locate /lib/rack/fowarder.rb # anywhere! class Forward attr_accessor :host,:port def initialize(host, port=80) @host, @port = host, port end def call(rackreq,headers) res = Net::HTTP.start(@host, @port) { |http| m = rackreq.request_method case m when "GET", "HEAD", "DELETE", "OPTIONS", "TRACE" req = Net::HTTP.const_get(m.capitalize).new(rackreq.fullpath, headers) when "PUT", "POST" req = Net::HTTP.const_get(m.capitalize).new(rackreq.fullpath, headers) req.body_stream = rackreq.body else raise "method not supported: #{method}" end http.request(req) } [res.code, Rack::Utils::HeaderHash.new(res.to_hash), [res.body]] end end module Dispatch def Dispatch.run(request) end end end