http 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.travis.yml +1 -0
- data/CHANGES.md +6 -0
- data/README.md +2 -1
- data/lib/http/timeout/global.rb +25 -9
- data/lib/http/timeout/null.rb +32 -15
- data/lib/http/timeout/per_operation.rb +14 -4
- data/lib/http/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2e1c7f1cbe78f39dff1f5194cd2fa58b9ffe5b4
|
4
|
+
data.tar.gz: 60ba195836aed0fb9a78c29ac67406d725e576d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2dc702c28b433e98d710e7330ca9379c3fb182dbee771b03a14c73710cbe3134a5f49177802bdd3696f3586531495ba194738954c7037801c4a31b924638204
|
7
|
+
data.tar.gz: 2354deaba38c163740dee33693564b18398fe0a3b3ebcfc18a93b717b11f78bba6d40d4055e7a670d040b135814ed2c98fca84cf9934e5a96527b21a9bd65389
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/README.md
CHANGED
data/lib/http/timeout/global.rb
CHANGED
@@ -104,16 +104,32 @@ module HTTP
|
|
104
104
|
:eof
|
105
105
|
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
if RUBY_VERSION < "2.0.0"
|
108
|
+
# Wait for a socket to become readable
|
109
|
+
def wait_readable_or_timeout
|
110
|
+
IO.select([@socket], nil, nil, time_left)
|
111
|
+
log_time
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
114
|
+
# Wait for a socket to become writable
|
115
|
+
def wait_writable_or_timeout
|
116
|
+
IO.select(nil, [@socket], nil, time_left)
|
117
|
+
log_time
|
118
|
+
end
|
119
|
+
else
|
120
|
+
require "io/wait"
|
121
|
+
|
122
|
+
# Wait for a socket to become readable
|
123
|
+
def wait_readable_or_timeout
|
124
|
+
@socket.to_io.wait_readable(time_left)
|
125
|
+
log_time
|
126
|
+
end
|
127
|
+
|
128
|
+
# Wait for a socket to become writable
|
129
|
+
def wait_writable_or_timeout
|
130
|
+
@socket.to_io.wait_writable(time_left)
|
131
|
+
log_time
|
132
|
+
end
|
117
133
|
end
|
118
134
|
|
119
135
|
# Due to the run/retry nature of nonblocking I/O, it's easier to keep track of time
|
data/lib/http/timeout/null.rb
CHANGED
@@ -50,26 +50,43 @@ module HTTP
|
|
50
50
|
end
|
51
51
|
alias_method :<<, :write
|
52
52
|
|
53
|
+
# These cops can be re-eanbled after we go Ruby 2.0+ only
|
54
|
+
# rubocop:disable Lint/UselessAccessModifier, Metrics/BlockNesting
|
55
|
+
|
53
56
|
private
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
retry
|
61
|
-
|
58
|
+
if RUBY_VERSION < "2.0.0"
|
59
|
+
# Retry reading
|
60
|
+
def rescue_readable
|
61
|
+
yield
|
62
|
+
rescue IO::WaitReadable
|
63
|
+
retry if IO.select([socket], nil, nil, read_timeout)
|
64
|
+
raise TimeoutError, "Read timed out after #{read_timeout} seconds"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Retry writing
|
68
|
+
def rescue_writable
|
69
|
+
yield
|
70
|
+
rescue IO::WaitWritable
|
71
|
+
retry if IO.select(nil, [socket], nil, write_timeout)
|
72
|
+
raise TimeoutError, "Write timed out after #{write_timeout} seconds"
|
73
|
+
end
|
74
|
+
else
|
75
|
+
require "io/wait"
|
76
|
+
|
77
|
+
# Retry reading
|
78
|
+
def rescue_readable
|
79
|
+
yield
|
80
|
+
rescue IO::WaitReadable
|
81
|
+
retry if socket.to_io.wait_readable(read_timeout)
|
62
82
|
raise TimeoutError, "Read timed out after #{read_timeout} seconds"
|
63
83
|
end
|
64
|
-
end
|
65
84
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
retry
|
72
|
-
else
|
85
|
+
# Retry writing
|
86
|
+
def rescue_writable
|
87
|
+
yield
|
88
|
+
rescue IO::WaitWritable
|
89
|
+
retry if socket.to_io.wait_writable(write_timeout)
|
73
90
|
raise TimeoutError, "Write timed out after #{write_timeout} seconds"
|
74
91
|
end
|
75
92
|
end
|
@@ -59,14 +59,19 @@ module HTTP
|
|
59
59
|
# Read data from the socket
|
60
60
|
def readpartial(size)
|
61
61
|
loop do
|
62
|
-
|
62
|
+
# JRuby may still raise exceptions on SSL sockets even though
|
63
|
+
# we explicitly specify `:exception => false`
|
64
|
+
result = rescue_readable do
|
65
|
+
socket.read_nonblock(size, :exception => false)
|
66
|
+
end
|
67
|
+
|
63
68
|
if result.nil?
|
64
69
|
return :eof
|
65
70
|
elsif result != :wait_readable
|
66
71
|
return result
|
67
72
|
end
|
68
73
|
|
69
|
-
unless
|
74
|
+
unless socket.to_io.wait_readable(read_timeout)
|
70
75
|
fail TimeoutError, "Read timed out after #{read_timeout} seconds"
|
71
76
|
end
|
72
77
|
end
|
@@ -75,10 +80,15 @@ module HTTP
|
|
75
80
|
# Write data to the socket
|
76
81
|
def write(data)
|
77
82
|
loop do
|
78
|
-
|
83
|
+
# JRuby may still raise exceptions on SSL sockets even though
|
84
|
+
# we explicitly specify `:exception => false`
|
85
|
+
result = rescue_writable do
|
86
|
+
socket.write_nonblock(data, :exception => false)
|
87
|
+
end
|
88
|
+
|
79
89
|
return result unless result == :wait_writable
|
80
90
|
|
81
|
-
unless
|
91
|
+
unless socket.to_io.wait_writable(write_timeout)
|
82
92
|
fail TimeoutError, "Read timed out after #{write_timeout} seconds"
|
83
93
|
end
|
84
94
|
end
|
data/lib/http/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-12-
|
14
|
+
date: 2015-12-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: http_parser.rb
|