Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to be compatibile with Rack v3.1+ #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ end

group :development, :test do
gem "simplecov"
gem "debug", platforms: %i[mri mingw x64_mingw]
5minpause marked this conversation as resolved.
Show resolved Hide resolved
end
2 changes: 1 addition & 1 deletion lib/rack_reverse_proxy/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Middleware
}

def initialize(app = nil, &b)
@app = app || lambda { |_| [404, [], []] }
@app = app || lambda { |_| [404, {}, []] }
@rules = []
@global_options = DEFAULT_OPTIONS
instance_eval(&b) if block_given?
Expand Down
10 changes: 5 additions & 5 deletions lib/rack_reverse_proxy/roundtrip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def target_response
end

def response_headers
@_response_headers ||= build_response_headers
@_response_headers ||= build_response_headers.transform_keys(&:downcase)
end

def build_response_headers
Expand All @@ -163,7 +163,7 @@ def build_response_headers
end

def rack_response_headers
Rack::Utils::HeaderHash.new(
Rack::Headers.new.merge(
Rack::Proxy.normalize_headers(
format_headers(target_response.headers)
)
Expand All @@ -173,15 +173,15 @@ def rack_response_headers
def replace_location_header
return unless need_replace_location?
rewrite_uri(response_location, source_request)
response_headers["Location"] = response_location.to_s
response_headers["location"] = response_location.to_s
end

def response_location
@_response_location ||= URI(response_headers["Location"])
@_response_location ||= URI(response_headers["location"] || uri)
end

def need_replace_location?
response_headers["Location"] && options[:replace_response_host] && response_location.host
response_headers["location"] && options[:replace_response_host] && response_location.host
end

def setup_request
Expand Down
6 changes: 3 additions & 3 deletions rack-reverse-proxy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ eos
spec.require_paths = ["lib"]

spec.add_dependency "rack", ">= 1.0.0"
spec.add_dependency "rack-proxy", "~> 0.6", ">= 0.6.1"
spec.add_dependency "rack-proxy", "~> 0.7", ">= 0.7.0"

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.3"
spec.add_development_dependency "bundler", "~> 2.5"
spec.add_development_dependency "rake", "~> 13.2"
end
# rubocop:enable
13 changes: 6 additions & 7 deletions spec/rack/reverse_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def dummy_app
)
end

describe "global options", focus: true do
describe "global options" do
it "starts with default global options" do
m = Rack::ReverseProxy.new(dummy_app) do
reverse_proxy "/test", "http://example.com/"
Expand Down Expand Up @@ -73,10 +73,10 @@ def app
expect(last_response.body).to eq("Proxied App")
end

it "produces a response header of type HeaderHash" do
it "produces a response header of type Headers" do
stub_request(:get, "http://example.com/test")
get "/test"
expect(last_response.headers).to be_an_instance_of(Rack::Utils::HeaderHash)
expect(last_response.headers).to be_an_instance_of(Rack::Headers)
end

it "parses the headers as a Hash with values of type String" do
Expand Down Expand Up @@ -154,7 +154,7 @@ def app
expect(headers["Status"]).to be_nil
end

it "formats the headers correctly to avoid duplicates" do
it "compares keys case-insensitive" do
stub_request(:get, "http://example.com/2test").to_return(
:headers => { :date => "Wed, 22 Jul 2015 11:27:21 GMT" }
)
Expand All @@ -163,7 +163,7 @@ def app

headers = last_response.headers.to_hash
expect(headers["Date"]).to eq("Wed, 22 Jul 2015 11:27:21 GMT")
expect(headers["date"]).to be_nil
expect(headers["date"]).to eq("Wed, 22 Jul 2015 11:27:21 GMT")
end

it "formats the headers with dashes correctly" do
Expand All @@ -175,8 +175,7 @@ def app
get "/2test"

headers = last_response.headers.to_hash
expect(headers["X-Additional-Info"]).to eq("something")
expect(headers["x-additional-info"]).to be_nil
expect(headers["x-additional-info"]).to eq("something")
end

it "the response header includes content-length" do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "simplecov"
SimpleCov.start

require "debug"
require "rack/reverse_proxy"
require "rack/test"
require "webmock/rspec"
Expand Down