From 90bdb6080ae9747b220a04f49e76e64fe9388079 Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Mon, 26 Dec 2016 14:57:24 +0000 Subject: [PATCH 1/4] Use subclasses of Net::HTTPRequest instead of Net::HTTPGenericRequest Instead of directly instantiating Net::HTTPGenericRequest, use the appropriate Net::HTTPRequest subclass. Fixes a problem with net-http-persistent adapter that is checking the subclasses of Net::HTTPRequest for idempotence support. --- lib/faraday/adapter/net_http.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/faraday/adapter/net_http.rb b/lib/faraday/adapter/net_http.rb index d2f8cec95..e26b51d4c 100644 --- a/lib/faraday/adapter/net_http.rb +++ b/lib/faraday/adapter/net_http.rb @@ -64,12 +64,10 @@ def call(env) private def create_request(env) - request = Net::HTTPGenericRequest.new \ - env[:method].to_s.upcase, # request method - !!env[:body], # is there request body - :head != env[:method], # is there response body - env[:url].request_uri, # request uri path - env[:request_headers] # request headers + klass = Net::HTTP.const_get(env[:method].to_s.capitalize) + request = klass.new \ + env[:url].request_uri, # request uri path + env[:request_headers] # request headers if env[:body].respond_to?(:read) request.body_stream = env[:body] From 0bee79a1f0ffc1a4cfb368d959f6ab257f5b6fc9 Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Tue, 2 Oct 2018 20:37:03 +0200 Subject: [PATCH 2/4] Fix specs based on Ruby version --- test/adapters/integration.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/adapters/integration.rb b/test/adapters/integration.rb index 0e53fc699..d592528a7 100644 --- a/test/adapters/integration.rb +++ b/test/adapters/integration.rb @@ -159,7 +159,10 @@ def test_PATCH_send_url_encoded_params def test_OPTIONS resp = run_request(:options, 'echo', nil, {}) - assert_equal 'options', resp.body + + body = 'options' if ruby_22_plus? + + assert_equal body, resp.body end def test_HEAD_retrieves_no_response_body From f92edd295936ea0d20460e26c2c2c4ce67caa982 Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Tue, 2 Oct 2018 20:45:08 +0200 Subject: [PATCH 3/4] Use Faraday::TestCase --- test/adapters/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/adapters/integration.rb b/test/adapters/integration.rb index d592528a7..0ffcbb0b2 100644 --- a/test/adapters/integration.rb +++ b/test/adapters/integration.rb @@ -160,7 +160,7 @@ def test_PATCH_send_url_encoded_params def test_OPTIONS resp = run_request(:options, 'echo', nil, {}) - body = 'options' if ruby_22_plus? + body = 'options' if Faraday::TestCase.ruby_22_plus? assert_equal body, resp.body end From 76943640fca699e250d4c12e349c6ed2ffcd81cc Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Tue, 2 Oct 2018 21:04:43 +0200 Subject: [PATCH 4/4] One more try --- test/adapters/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/adapters/integration.rb b/test/adapters/integration.rb index 0ffcbb0b2..80785188c 100644 --- a/test/adapters/integration.rb +++ b/test/adapters/integration.rb @@ -160,7 +160,7 @@ def test_PATCH_send_url_encoded_params def test_OPTIONS resp = run_request(:options, 'echo', nil, {}) - body = 'options' if Faraday::TestCase.ruby_22_plus? + body = Faraday::TestCase.ruby_22_plus? ? 'options' : '' assert_equal body, resp.body end