Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.4
0.4.6
15 changes: 11 additions & 4 deletions lib/rack/reverse_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]

Expand Down Expand Up @@ -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|
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion rack-reverse-proxy.gemspec
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down