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] diff --git a/test/adapters/integration.rb b/test/adapters/integration.rb index 0e53fc699..80785188c 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 = Faraday::TestCase.ruby_22_plus? ? 'options' : '' + + assert_equal body, resp.body end def test_HEAD_retrieves_no_response_body