Skip to content

Commit

Permalink
Merge pull request #799 from jnunemaker/drop-old-rubies
Browse files Browse the repository at this point in the history
Drop old ruby support
  • Loading branch information
jnunemaker authored Mar 20, 2024
2 parents ca47360 + 322785d commit e516b11
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 107 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ jobs:
strategy:
matrix:
ruby:
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- '3.0' # Quoted, to avoid YAML float 3.0 interplated to "3"
- "3.0" # Quoted, to avoid YAML float 3.0 interplated to "3"
- 3.1
- 3.2
- 3.3
Expand Down
2 changes: 1 addition & 1 deletion httparty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.summary = 'Makes http fun! Also, makes consuming restful web services dead easy.'
s.description = 'Makes http fun! Also, makes consuming restful web services dead easy.'

s.required_ruby_version = '>= 2.3.0'
s.required_ruby_version = '>= 2.7.0'

s.add_dependency 'csv'
s.add_dependency 'multi_xml', ">= 0.5.2"
Expand Down
29 changes: 5 additions & 24 deletions lib/httparty/connection_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ def connection
if add_timeout?(options[:timeout])
http.open_timeout = options[:timeout]
http.read_timeout = options[:timeout]

from_ruby_version('2.6.0', option: :write_timeout, warn: false) do
http.write_timeout = options[:timeout]
end
http.write_timeout = options[:timeout]
end

if add_timeout?(options[:read_timeout])
Expand All @@ -134,15 +131,11 @@ def connection
end

if add_timeout?(options[:write_timeout])
from_ruby_version('2.6.0', option: :write_timeout) do
http.write_timeout = options[:write_timeout]
end
http.write_timeout = options[:write_timeout]
end

if add_max_retries?(options[:max_retries])
from_ruby_version('2.5.0', option: :max_retries) do
http.max_retries = options[:max_retries]
end
http.max_retries = options[:max_retries]
end

if options[:debug_output]
Expand All @@ -157,30 +150,18 @@ def connection
#
# @see https://bugs.ruby-lang.org/issues/6617
if options[:local_host]
from_ruby_version('2.0.0', option: :local_host) do
http.local_host = options[:local_host]
end
http.local_host = options[:local_host]
end

if options[:local_port]
from_ruby_version('2.0.0', option: :local_port) do
http.local_port = options[:local_port]
end
http.local_port = options[:local_port]
end

http
end

private

def from_ruby_version(ruby_version, option: nil, warn: true)
if RUBY_VERSION >= ruby_version
yield
elsif warn
Kernel.warn("Warning: option #{ option } requires Ruby version #{ ruby_version } or later")
end
end

def add_timeout?(timeout)
timeout && (timeout.is_a?(Integer) || timeout.is_a?(Float))
end
Expand Down
4 changes: 2 additions & 2 deletions lib/httparty/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def inspect
end

# Support old multiple_choice? method from pre 2.0.0 era.
if ::RUBY_VERSION >= '2.0.0' && ::RUBY_PLATFORM != 'java'
if ::RUBY_PLATFORM != 'java'
alias_method :multiple_choice?, :multiple_choices?
end

# Support old status codes method from pre 2.6.0 era.
if ::RUBY_VERSION >= '2.6.0' && ::RUBY_PLATFORM != 'java'
if ::RUBY_PLATFORM != 'java'
alias_method :gateway_time_out?, :gateway_timeout?
alias_method :request_entity_too_large?, :payload_too_large?
alias_method :request_time_out?, :request_timeout?
Expand Down
130 changes: 58 additions & 72 deletions spec/httparty/connection_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
it "sets ssl version" do
expect(subject.ssl_version).to eq(:TLSv1)
end
end if RUBY_VERSION > '1.9'
end
end

context "when dealing with IPv6" do
Expand All @@ -119,7 +119,7 @@
it "should set the ciphers on the connection" do
expect(subject.ciphers).to eq('RC4-SHA')
end
end if RUBY_VERSION > '1.9'
end

context "when timeout is not set" do
it "doesn't set the timeout" do
Expand Down Expand Up @@ -152,11 +152,9 @@
it { is_expected.to eq(5) }
end

if RUBY_VERSION >= '2.6.0'
describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(5) }
end
describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(5) }
end
end

Expand Down Expand Up @@ -223,11 +221,9 @@
it { is_expected.to eq(5) }
end

if RUBY_VERSION >= '2.6.0'
describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(5) }
end
describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(5) }
end

describe '#read_timeout' do
Expand All @@ -247,9 +243,7 @@
)
expect(http).to receive(:open_timeout=)
expect(http).to receive(:read_timeout=).twice
if RUBY_VERSION >= '2.6.0'
expect(http).to receive(:write_timeout=)
end
expect(http).to receive(:write_timeout=)
allow(Net::HTTP).to receive_messages(new: http)
adapter.connection
end
Expand Down Expand Up @@ -298,11 +292,9 @@
it { is_expected.to eq(7) }
end

if RUBY_VERSION >= '2.6.0'
describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(5) }
end
describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(5) }
end

describe '#read_timeout' do
Expand All @@ -322,54 +314,50 @@
)
expect(http).to receive(:open_timeout=).twice
expect(http).to receive(:read_timeout=)
if RUBY_VERSION >= '2.6.0'
expect(http).to receive(:write_timeout=)
end
expect(http).to receive(:write_timeout=)
allow(Net::HTTP).to receive_messages(new: http)
adapter.connection
end
end

if RUBY_VERSION >= '2.6.0'
context "when timeout is not set and write_timeout is set to 8 seconds" do
let(:options) { {write_timeout: 8} }
context "when timeout is not set and write_timeout is set to 8 seconds" do
let(:options) { {write_timeout: 8} }

describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(8) }
end
describe '#write_timeout' do
subject { super().write_timeout }
it { is_expected.to eq(8) }
end

it "should not set the open timeout" do
http = double(
"http",
:null_object => true,
:use_ssl= => false,
:use_ssl? => false,
:read_timeout= => 0,
:open_timeout= => 0,
:write_timeout= => 0,
it "should not set the open timeout" do
http = double(
"http",
:null_object => true,
:use_ssl= => false,
:use_ssl? => false,
:read_timeout= => 0,
:open_timeout= => 0,
:write_timeout= => 0,

)
expect(http).not_to receive(:open_timeout=)
allow(Net::HTTP).to receive_messages(new: http)
adapter.connection
end
)
expect(http).not_to receive(:open_timeout=)
allow(Net::HTTP).to receive_messages(new: http)
adapter.connection
end

it "should not set the read timeout" do
http = double(
"http",
:null_object => true,
:use_ssl= => false,
:use_ssl? => false,
:read_timeout= => 0,
:open_timeout= => 0,
:write_timeout= => 0,
it "should not set the read timeout" do
http = double(
"http",
:null_object => true,
:use_ssl= => false,
:use_ssl? => false,
:read_timeout= => 0,
:open_timeout= => 0,
:write_timeout= => 0,

)
expect(http).not_to receive(:read_timeout=)
allow(Net::HTTP).to receive_messages(new: http)
adapter.connection
end
)
expect(http).not_to receive(:read_timeout=)
allow(Net::HTTP).to receive_messages(new: http)
adapter.connection
end

context "when timeout is set and write_timeout is set to 8 seconds" do
Expand Down Expand Up @@ -415,21 +403,19 @@
end

context "when setting max_retries" do
if RUBY_VERSION >= '2.5.0'
context "to 5 times" do
let(:options) { {max_retries: 5} }
describe '#max_retries' do
subject { super().max_retries }
it { is_expected.to eq(5) }
end
context "to 5 times" do
let(:options) { {max_retries: 5} }
describe '#max_retries' do
subject { super().max_retries }
it { is_expected.to eq(5) }
end
end

context "to 0 times" do
let(:options) { {max_retries: 0} }
describe '#max_retries' do
subject { super().max_retries }
it { is_expected.to eq(0) }
end
context "to 0 times" do
let(:options) { {max_retries: 0} }
describe '#max_retries' do
subject { super().max_retries }
it { is_expected.to eq(0) }
end
end

Expand Down Expand Up @@ -545,7 +531,7 @@
subject { super().local_port }
it { is_expected.to eq(12345) }
end
end if RUBY_VERSION >= '2.0'
end

context "when providing PEM certificates" do
let(:pem) { :pem_contents }
Expand Down
5 changes: 2 additions & 3 deletions spec/httparty/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,12 @@ def response_mock(klass)
version_not_supported?: Net::HTTPVersionNotSupported
}

# Ruby 2.0, new name for this response.
if RUBY_VERSION >= "2.0.0" && ::RUBY_PLATFORM != "java"
if ::RUBY_PLATFORM != "java"
SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices
end

# Ruby 2.6, those status codes have been updated.
if RUBY_VERSION >= "2.6.0" && ::RUBY_PLATFORM != "java"
if ::RUBY_PLATFORM != "java"
SPECIFIC_CODES[:gateway_timeout?] = Net::HTTPGatewayTimeout
SPECIFIC_CODES[:payload_too_large?] = Net::HTTPPayloadTooLarge
SPECIFIC_CODES[:request_timeout?] = Net::HTTPRequestTimeout
Expand Down

0 comments on commit e516b11

Please sign in to comment.