http 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +15 -0
- data/lib/http/headers.rb +8 -0
- data/lib/http/response.rb +4 -0
- data/lib/http/response/body.rb +12 -7
- data/lib/http/timeout/null.rb +6 -6
- data/lib/http/timeout/per_operation.rb +2 -2
- data/lib/http/version.rb +1 -1
- data/spec/lib/http/headers_spec.rb +20 -0
- data/spec/lib/http/response/body_spec.rb +8 -8
- data/spec/lib/http/response_spec.rb +16 -0
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce75d295d182290642aa569b754914f89ed797f
|
4
|
+
data.tar.gz: 353078321cc4c0e9134a5b10d655186474288770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4717d7e9b0a3d841fa31e533e69e35728943218c68455550ccacb845712c1a24e657385c7c4d228c6d3af5a5c68105a674647bef64fba1af33439041153db6a
|
7
|
+
data.tar.gz: 6dd93161b0a552b4f7484ee2e935e54f57de0f0f6f3f1415250f35073ea90be854baa00322cc59a078a2f3f0a84732289de5ad44e63f782874df44a347770bb8
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 2.1.0 (2016-11-08)
|
2
|
+
|
3
|
+
* [#370](https://github.com/httprb/http/issues/370)
|
4
|
+
Add Headers#include?
|
5
|
+
([@ixti])
|
6
|
+
|
7
|
+
* [#364](https://github.com/httprb/http/issues/364)
|
8
|
+
Add HTTP::Response#connection
|
9
|
+
([@janko-m])
|
10
|
+
|
11
|
+
* [#362](https://github.com/httprb/http/issues/362)
|
12
|
+
connect_ssl uses connect_timeout (Closes #359)
|
13
|
+
([@TiagoCardoso1983])
|
14
|
+
|
15
|
+
|
1
16
|
## 2.0.3 (2016-08-03)
|
2
17
|
|
3
18
|
* [#365](https://github.com/httprb/http/issues/365)
|
data/lib/http/headers.rb
CHANGED
@@ -75,6 +75,14 @@ module HTTP
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
# Tells whenever header with given `name` is set or not.
|
79
|
+
#
|
80
|
+
# @return [Boolean]
|
81
|
+
def include?(name)
|
82
|
+
name = normalize_header name.to_s
|
83
|
+
@pile.any? { |k, _| k == name }
|
84
|
+
end
|
85
|
+
|
78
86
|
# Returns Rack-compatible headers Hash
|
79
87
|
#
|
80
88
|
# @return [Hash]
|
data/lib/http/response.rb
CHANGED
@@ -71,6 +71,10 @@ module HTTP
|
|
71
71
|
# (see HTTP::Response::Body#readpartial)
|
72
72
|
def_delegator :body, :readpartial
|
73
73
|
|
74
|
+
# @!method connection
|
75
|
+
# (see HTTP::Response::Body#connection)
|
76
|
+
def_delegator :body, :connection
|
77
|
+
|
74
78
|
# Returns an Array ala Rack: `[status, headers, body]`
|
75
79
|
#
|
76
80
|
# @return [Array(Fixnum, Hash, String)]
|
data/lib/http/response/body.rb
CHANGED
@@ -10,17 +10,22 @@ module HTTP
|
|
10
10
|
include Enumerable
|
11
11
|
def_delegator :to_s, :empty?
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
# The connection object used to make the corresponding request.
|
14
|
+
#
|
15
|
+
# @return [HTTP::Connection]
|
16
|
+
attr_reader :connection
|
17
|
+
|
18
|
+
def initialize(connection, encoding = Encoding::BINARY)
|
19
|
+
@connection = connection
|
20
|
+
@streaming = nil
|
21
|
+
@contents = nil
|
22
|
+
@encoding = encoding
|
18
23
|
end
|
19
24
|
|
20
25
|
# (see HTTP::Client#readpartial)
|
21
26
|
def readpartial(*args)
|
22
27
|
stream!
|
23
|
-
@
|
28
|
+
@connection.readpartial(*args)
|
24
29
|
end
|
25
30
|
|
26
31
|
# Iterate over the body, allowing it to be enumerable
|
@@ -47,7 +52,7 @@ module HTTP
|
|
47
52
|
@streaming = false
|
48
53
|
@contents = String.new("").force_encoding(encoding)
|
49
54
|
|
50
|
-
while (chunk = @
|
55
|
+
while (chunk = @connection.readpartial)
|
51
56
|
@contents << chunk.force_encoding(encoding)
|
52
57
|
end
|
53
58
|
rescue
|
data/lib/http/timeout/null.rb
CHANGED
@@ -55,19 +55,19 @@ module HTTP
|
|
55
55
|
private
|
56
56
|
|
57
57
|
# Retry reading
|
58
|
-
def rescue_readable
|
58
|
+
def rescue_readable(timeout = read_timeout)
|
59
59
|
yield
|
60
60
|
rescue IO::WaitReadable
|
61
|
-
retry if @socket.to_io.wait_readable(
|
62
|
-
raise TimeoutError, "Read timed out after #{
|
61
|
+
retry if @socket.to_io.wait_readable(timeout)
|
62
|
+
raise TimeoutError, "Read timed out after #{timeout} seconds"
|
63
63
|
end
|
64
64
|
|
65
65
|
# Retry writing
|
66
|
-
def rescue_writable
|
66
|
+
def rescue_writable(timeout = write_timeout)
|
67
67
|
yield
|
68
68
|
rescue IO::WaitWritable
|
69
|
-
retry if @socket.to_io.wait_writable(
|
70
|
-
raise TimeoutError, "Write timed out after #{
|
69
|
+
retry if @socket.to_io.wait_writable(timeout)
|
70
|
+
raise TimeoutError, "Write timed out after #{timeout} seconds"
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
data/lib/http/version.rb
CHANGED
@@ -185,6 +185,26 @@ RSpec.describe HTTP::Headers do
|
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
+
describe "#include?" do
|
189
|
+
before do
|
190
|
+
headers.add :content_type, "application/json"
|
191
|
+
headers.add :set_cookie, "hoo=ray"
|
192
|
+
headers.add :set_cookie, "woo=hoo"
|
193
|
+
end
|
194
|
+
|
195
|
+
it "tells whenever given headers is set or not" do
|
196
|
+
expect(headers.include?("Content-Type")).to be true
|
197
|
+
expect(headers.include?("Set-Cookie")).to be true
|
198
|
+
expect(headers.include?("Accept")).to be false
|
199
|
+
end
|
200
|
+
|
201
|
+
it "normalizes given header name" do
|
202
|
+
expect(headers.include?(:content_type)).to be true
|
203
|
+
expect(headers.include?(:set_cookie)).to be true
|
204
|
+
expect(headers.include?(:accept)).to be false
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
188
208
|
describe "#to_h" do
|
189
209
|
before do
|
190
210
|
headers.add :content_type, "application/json"
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
RSpec.describe HTTP::Response::Body do
|
3
|
-
let(:
|
4
|
-
let(:chunks)
|
3
|
+
let(:connection) { double(:sequence_id => 0) }
|
4
|
+
let(:chunks) { [String.new("Hello, "), String.new("World!")] }
|
5
5
|
|
6
|
-
before
|
6
|
+
before { allow(connection).to receive(:readpartial) { chunks.shift } }
|
7
7
|
|
8
|
-
subject(:body)
|
8
|
+
subject(:body) { described_class.new(connection, Encoding::UTF_8) }
|
9
9
|
|
10
10
|
it "streams bodies from responses" do
|
11
11
|
expect(subject.to_s).to eq("Hello, World!")
|
@@ -21,8 +21,8 @@ RSpec.describe HTTP::Response::Body do
|
|
21
21
|
|
22
22
|
describe "#readpartial" do
|
23
23
|
context "with size given" do
|
24
|
-
it "passes value to underlying
|
25
|
-
expect(
|
24
|
+
it "passes value to underlying connection" do
|
25
|
+
expect(connection).to receive(:readpartial).with(42)
|
26
26
|
body.readpartial 42
|
27
27
|
end
|
28
28
|
end
|
@@ -32,8 +32,8 @@ RSpec.describe HTTP::Response::Body do
|
|
32
32
|
expect { body.readpartial }.to_not raise_error
|
33
33
|
end
|
34
34
|
|
35
|
-
it "calls underlying
|
36
|
-
expect(
|
35
|
+
it "calls underlying connection readpartial without specific size" do
|
36
|
+
expect(connection).to receive(:readpartial).with no_args
|
37
37
|
body.readpartial
|
38
38
|
end
|
39
39
|
end
|
@@ -157,4 +157,20 @@ RSpec.describe HTTP::Response do
|
|
157
157
|
expect(jar.count { |c| "c" == c.name }).to eq 0
|
158
158
|
end
|
159
159
|
end
|
160
|
+
|
161
|
+
describe "#connection" do
|
162
|
+
let(:connection) { double }
|
163
|
+
|
164
|
+
subject(:response) do
|
165
|
+
HTTP::Response.new(
|
166
|
+
:version => "1.1",
|
167
|
+
:status => 200,
|
168
|
+
:connection => connection
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "returns the connection object used to instantiate the response" do
|
173
|
+
expect(response.connection).to eq connection
|
174
|
+
end
|
175
|
+
end
|
160
176
|
end
|
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: 2.0
|
4
|
+
version: 2.1.0
|
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: 2016-
|
14
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: http_parser.rb
|
@@ -219,4 +219,3 @@ test_files:
|
|
219
219
|
- spec/support/servers/config.rb
|
220
220
|
- spec/support/servers/runner.rb
|
221
221
|
- spec/support/ssl_helper.rb
|
222
|
-
has_rdoc:
|