From 0ef163161a5e71febd38b9786adb9fd5cab90066 Mon Sep 17 00:00:00 2001 From: Anuj Das Date: Thu, 2 Jul 2015 14:06:36 -0700 Subject: [PATCH 1/2] Fix method declaration to be ruby-1.8-compatible --- lib/rack/reverse_proxy_matcher.rb | 2 +- spec/rack/reverse_proxy_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rack/reverse_proxy_matcher.rb b/lib/rack/reverse_proxy_matcher.rb index 6afacba..7044580 100644 --- a/lib/rack/reverse_proxy_matcher.rb +++ b/lib/rack/reverse_proxy_matcher.rb @@ -1,6 +1,6 @@ module Rack class ReverseProxyMatcher - def initialize(matcher,url=nil,options) + def initialize(matcher, url=nil, options={}) @default_url=url @url=url @options=options diff --git a/spec/rack/reverse_proxy_spec.rb b/spec/rack/reverse_proxy_spec.rb index adfcbdd..f3c6610 100644 --- a/spec/rack/reverse_proxy_spec.rb +++ b/spec/rack/reverse_proxy_spec.rb @@ -324,9 +324,9 @@ def app it "should proxy requests when a pattern is matched" do stub_request(:get, 'http://users-example.com/users?user=omer').to_return({:body => "User App"}) - get '/test', user: "mark" + get '/test', :user => "mark" last_response.body.should == "Dummy App" - get '/users', user: 'omer' + get '/users', :user => 'omer' last_response.body.should == "User App" end end From f0458c958d57f549fd87d0bb8eaebd2f13bc7720 Mon Sep 17 00:00:00 2001 From: Oleksii Fedorov Date: Fri, 3 Jul 2015 23:27:34 +0200 Subject: [PATCH 2/2] quickfix for jruby + rack-reverse-proxy + rspec-mocks + :read_timeout= weirdness --- lib/rack/reverse_proxy.rb | 3 ++- lib/rack/reverse_proxy/http_streaming_response.rb | 7 +++++++ spec/rack/reverse_proxy_spec.rb | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 lib/rack/reverse_proxy/http_streaming_response.rb diff --git a/lib/rack/reverse_proxy.rb b/lib/rack/reverse_proxy.rb index 55d5419..b6e0f8d 100644 --- a/lib/rack/reverse_proxy.rb +++ b/lib/rack/reverse_proxy.rb @@ -3,6 +3,7 @@ require "rack-proxy" require "rack/reverse_proxy_matcher" require "rack/exception" +require "rack/reverse_proxy/http_streaming_response" module Rack class ReverseProxy @@ -72,7 +73,7 @@ def proxy(env, source_request, matcher) target_response = HttpStreamingResponse.new(target_request, uri.host, uri.port) # pass the timeout configuration through - target_response.read_timeout = options[:timeout] if options[:timeout].to_i > 0 + target_response.set_read_timeout(options[:timeout]) if options[:timeout].to_i > 0 target_response.use_ssl = "https" == uri.scheme diff --git a/lib/rack/reverse_proxy/http_streaming_response.rb b/lib/rack/reverse_proxy/http_streaming_response.rb new file mode 100644 index 0000000..2e43b97 --- /dev/null +++ b/lib/rack/reverse_proxy/http_streaming_response.rb @@ -0,0 +1,7 @@ +module Rack + class HttpStreamingResponse + def set_read_timeout(value) + self.read_timeout = value + end + end +end diff --git a/spec/rack/reverse_proxy_spec.rb b/spec/rack/reverse_proxy_spec.rb index f3c6610..5186743 100644 --- a/spec/rack/reverse_proxy_spec.rb +++ b/spec/rack/reverse_proxy_spec.rb @@ -89,7 +89,7 @@ def app it "should make request with basic auth" do stub_request(:get, "http://example.com/test/slow") - Rack::HttpStreamingResponse.any_instance.should_receive(:read_timeout=).with(99) + Rack::HttpStreamingResponse.any_instance.should_receive(:set_read_timeout).with(99) get '/test/slow' end end @@ -103,7 +103,7 @@ def app it "should make request with basic auth" do stub_request(:get, "http://example.com/test/slow") - Rack::HttpStreamingResponse.any_instance.should_not_receive(:read_timeout=) + Rack::HttpStreamingResponse.any_instance.should_not_receive(:set_read_timeout) get '/test/slow' end end