Skip to content

Commit 3ed0c31

Browse files
committed
Bump min supported Ruby version to 2.5
1 parent ae796fa commit 3ed0c31

File tree

9 files changed

+55
-93
lines changed

9 files changed

+55
-93
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
ruby: [ ruby-2.4, ruby-2.5, ruby-2.6, ruby-2.7, ruby-3.0, jruby-9.2 ]
19+
ruby: [ ruby-2.5, ruby-2.6, ruby-2.7, ruby-3.0, jruby-9.2 ]
2020
os: [ ubuntu-latest ]
2121

2222
steps:
@@ -56,7 +56,7 @@ jobs:
5656

5757
- uses: ruby/setup-ruby@v1
5858
with:
59-
ruby-version: 2.4
59+
ruby-version: 2.5
6060
bundler-cache: true
6161

6262
- name: bundle exec rubocop

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ AllCops:
77
DefaultFormatter: fuubar
88
DisplayCopNames: true
99
NewCops: enable
10-
TargetRubyVersion: 2.4
10+
TargetRubyVersion: 2.5

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ and call `#readpartial` on it repeatedly until it returns `nil`:
165165
This library aims to support and is [tested against][travis] the following Ruby
166166
versions:
167167

168-
* Ruby 2.4
169-
* Ruby 2.5
170168
* Ruby 2.6
171169
* Ruby 2.7
172170
* Ruby 3.0

http.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
2525
gem.require_paths = ["lib"]
2626
gem.version = HTTP::VERSION
2727

28-
gem.required_ruby_version = ">= 2.4"
28+
gem.required_ruby_version = ">= 2.5"
2929

3030
gem.add_runtime_dependency "addressable", "~> 2.3"
3131
gem.add_runtime_dependency "http-cookie", "~> 1.0"

lib/http/headers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def include?(name)
111111
#
112112
# @return [Hash]
113113
def to_h
114-
Hash[keys.map { |k| [k, self[k]] }]
114+
keys.map { |k| [k, self[k]] }.to_h
115115
end
116116
alias to_hash to_h
117117

lib/http/response/status.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def symbolize(str)
6969
# SYMBOL_CODES[:im_a_teapot] # => 418
7070
#
7171
# @return [Hash<Symbol => Fixnum>]
72-
SYMBOL_CODES = Hash[SYMBOLS.map { |k, v| [v, k] }].freeze
72+
SYMBOL_CODES = SYMBOLS.map { |k, v| [v, k] }.to_h.freeze
7373

7474
# @return [Fixnum] status code
7575
attr_reader :code

lib/http/timeout/global.rb

+16-28
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,31 @@ def write(data)
5959

6060
private
6161

62-
if RUBY_VERSION < "2.1.0"
63-
def read_nonblock(size, buffer = nil)
64-
@socket.read_nonblock(size, buffer)
65-
end
66-
67-
def write_nonblock(data)
68-
@socket.write_nonblock(data)
69-
end
70-
else
71-
def read_nonblock(size, buffer = nil)
72-
@socket.read_nonblock(size, buffer, :exception => false)
73-
end
62+
def read_nonblock(size, buffer = nil)
63+
@socket.read_nonblock(size, buffer, :exception => false)
64+
end
7465

75-
def write_nonblock(data)
76-
@socket.write_nonblock(data, :exception => false)
77-
end
66+
def write_nonblock(data)
67+
@socket.write_nonblock(data, :exception => false)
7868
end
7969

8070
# Perform the given I/O operation with the given argument
8171
def perform_io
8272
reset_timer
8373

8474
loop do
85-
begin
86-
result = yield
87-
88-
case result
89-
when :wait_readable then wait_readable_or_timeout
90-
when :wait_writable then wait_writable_or_timeout
91-
when NilClass then return :eof
92-
else return result
93-
end
94-
rescue IO::WaitReadable
95-
wait_readable_or_timeout
96-
rescue IO::WaitWritable
97-
wait_writable_or_timeout
75+
result = yield
76+
77+
case result
78+
when :wait_readable then wait_readable_or_timeout
79+
when :wait_writable then wait_writable_or_timeout
80+
when NilClass then return :eof
81+
else return result
9882
end
83+
rescue IO::WaitReadable
84+
wait_readable_or_timeout
85+
rescue IO::WaitWritable
86+
wait_writable_or_timeout
9987
end
10088
rescue EOFError
10189
:eof

lib/http/timeout/per_operation.rb

+31-55
Original file line numberDiff line numberDiff line change
@@ -34,66 +34,42 @@ def connect_ssl
3434
end
3535
end
3636

37-
# NIO with exceptions
38-
if RUBY_VERSION < "2.1.0"
39-
# Read data from the socket
40-
def readpartial(size, buffer = nil)
41-
rescue_readable do
42-
@socket.read_nonblock(size, buffer)
43-
end
44-
rescue EOFError
45-
:eof
46-
end
47-
48-
# Write data to the socket
49-
def write(data)
50-
rescue_writable do
51-
@socket.write_nonblock(data)
52-
end
53-
rescue EOFError
54-
:eof
55-
end
56-
57-
# NIO without exceptions
58-
else
59-
# Read data from the socket
60-
def readpartial(size, buffer = nil)
61-
timeout = false
62-
loop do
63-
result = @socket.read_nonblock(size, buffer, :exception => false)
64-
65-
return :eof if result.nil?
66-
return result if result != :wait_readable
67-
68-
raise TimeoutError, "Read timed out after #{@read_timeout} seconds" if timeout
69-
70-
# marking the socket for timeout. Why is this not being raised immediately?
71-
# it seems there is some race-condition on the network level between calling
72-
# #read_nonblock and #wait_readable, in which #read_nonblock signalizes waiting
73-
# for reads, and when waiting for x seconds, it returns nil suddenly without completing
74-
# the x seconds. In a normal case this would be a timeout on wait/read, but it can
75-
# also mean that the socket has been closed by the server. Therefore we "mark" the
76-
# socket for timeout and try to read more bytes. If it returns :eof, it's all good, no
77-
# timeout. Else, the first timeout was a proper timeout.
78-
# This hack has to be done because io/wait#wait_readable doesn't provide a value for when
79-
# the socket is closed by the server, and HTTP::Parser doesn't provide the limit for the chunks.
80-
timeout = true unless @socket.to_io.wait_readable(@read_timeout)
81-
end
37+
# Read data from the socket
38+
def readpartial(size, buffer = nil)
39+
timeout = false
40+
loop do
41+
result = @socket.read_nonblock(size, buffer, :exception => false)
42+
43+
return :eof if result.nil?
44+
return result if result != :wait_readable
45+
46+
raise TimeoutError, "Read timed out after #{@read_timeout} seconds" if timeout
47+
48+
# marking the socket for timeout. Why is this not being raised immediately?
49+
# it seems there is some race-condition on the network level between calling
50+
# #read_nonblock and #wait_readable, in which #read_nonblock signalizes waiting
51+
# for reads, and when waiting for x seconds, it returns nil suddenly without completing
52+
# the x seconds. In a normal case this would be a timeout on wait/read, but it can
53+
# also mean that the socket has been closed by the server. Therefore we "mark" the
54+
# socket for timeout and try to read more bytes. If it returns :eof, it's all good, no
55+
# timeout. Else, the first timeout was a proper timeout.
56+
# This hack has to be done because io/wait#wait_readable doesn't provide a value for when
57+
# the socket is closed by the server, and HTTP::Parser doesn't provide the limit for the chunks.
58+
timeout = true unless @socket.to_io.wait_readable(@read_timeout)
8259
end
60+
end
8361

84-
# Write data to the socket
85-
def write(data)
86-
timeout = false
87-
loop do
88-
result = @socket.write_nonblock(data, :exception => false)
89-
return result unless result == :wait_writable
62+
# Write data to the socket
63+
def write(data)
64+
timeout = false
65+
loop do
66+
result = @socket.write_nonblock(data, :exception => false)
67+
return result unless result == :wait_writable
9068

91-
raise TimeoutError, "Write timed out after #{@write_timeout} seconds" if timeout
69+
raise TimeoutError, "Write timed out after #{@write_timeout} seconds" if timeout
9270

93-
timeout = true unless @socket.to_io.wait_writable(@write_timeout)
94-
end
71+
timeout = true unless @socket.to_io.wait_writable(@write_timeout)
9572
end
96-
9773
end
9874
end
9975
end

spec/lib/http/client_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def stubs
2020
end
2121

2222
def stub(stubs)
23-
@stubs = stubs.each_with_object({}) do |(k, v), o|
24-
o[HTTP::URI::NORMALIZER.call(k).to_s] = v
23+
@stubs = stubs.transform_keys do |k|
24+
HTTP::URI::NORMALIZER.call(k).to_s
2525
end
2626

2727
self

0 commit comments

Comments
 (0)