diff --git a/VERSION b/VERSION index 6f2743d..ef52a64 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.4 +0.4.6 diff --git a/lib/rack/reverse_proxy.rb b/lib/rack/reverse_proxy.rb index b7acfcf..64cf35f 100644 --- a/lib/rack/reverse_proxy.rb +++ b/lib/rack/reverse_proxy.rb @@ -6,13 +6,13 @@ class ReverseProxy def initialize(app = nil, &b) @app = app || lambda {|env| [404, [], []] } @matchers = [] - @global_options = {:preserve_host => true, :matching => :all, :verify_ssl => true} + @global_options = {:preserve_host => true, :x_forwarded_host => true, :matching => :all, :verify_ssl => true} instance_eval &b if block_given? end def call(env) rackreq = Rack::Request.new(env) - matcher = get_matcher rackreq.fullpath + matcher = get_matcher rackreq.url return @app.call(env) if matcher.nil? uri = matcher.get_uri(rackreq.fullpath,env) @@ -23,8 +23,9 @@ def call(env) headers[$1] = value end } - headers['HOST'] = uri.host if all_opts[:preserve_host] - + headers['HOST'] = host_with_port uri, env['SERVER_PORT'] if all_opts[:preserve_host] + headers['X-Forwarded-Host'] = host_with_port uri, env['SERVER_PORT'] if all_opts[:x_forwarded_host] + session = Net::HTTP.new(uri.host, uri.port) session.read_timeout=all_opts[:timeout] if all_opts[:timeout] @@ -71,6 +72,9 @@ def call(env) end private + def host_with_port uri, port + [uri.host, port].compact.map(&:to_s).join ':' + end def get_matcher path matches = @matchers.select do |matcher| @@ -93,6 +97,9 @@ def create_response_headers http_response # TODO: figure out how to handle chunked responses response_headers.delete('transfer-encoding') # TODO: Verify Content Length, and required Rack headers + # Workaround: Ignore Content-Length headers to support Rack::Deflate + # gzipped responses + response_headers.delete('Content-Length') response_headers end diff --git a/rack-reverse-proxy.gemspec b/rack-reverse-proxy.gemspec index 2fbd435..20fce72 100644 --- a/rack-reverse-proxy.gemspec +++ b/rack-reverse-proxy.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = %q{rack-reverse-proxy} - s.version = "0.4.4" + s.version = "0.4.6" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Jon Swope"]