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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4daefc1ab609a814049d1dbb15c8b4dd1dcbc4af
4
- data.tar.gz: 8e997cb150a1b40c3f93713a8c0a8e0c3c347e37
3
+ metadata.gz: 9ce75d295d182290642aa569b754914f89ed797f
4
+ data.tar.gz: 353078321cc4c0e9134a5b10d655186474288770
5
5
  SHA512:
6
- metadata.gz: 14aa2d7853ca5d3b0c4a60f3d85ea79ce29f942cae40d60c83cfa9de10845806b521cece91aabff8954f2bfd33ccd78577f39676133d5dee45f7055b0083e599
7
- data.tar.gz: 9473c747c14dc40eb7ee6a9822bf45b674a8892c8cc92db6cfa9d88fa9bc3d6f03429e72609d6e902fdaed836c38e80fc6ba0d5d58c53a2a688a98fb365deaf1
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)
@@ -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]
@@ -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)]
@@ -10,17 +10,22 @@ module HTTP
10
10
  include Enumerable
11
11
  def_delegator :to_s, :empty?
12
12
 
13
- def initialize(client, encoding = Encoding::BINARY)
14
- @client = client
15
- @streaming = nil
16
- @contents = nil
17
- @encoding = encoding
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
- @client.readpartial(*args)
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 = @client.readpartial)
55
+ while (chunk = @connection.readpartial)
51
56
  @contents << chunk.force_encoding(encoding)
52
57
  end
53
58
  rescue
@@ -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(read_timeout)
62
- raise TimeoutError, "Read timed out after #{read_timeout} seconds"
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(write_timeout)
70
- raise TimeoutError, "Write timed out after #{write_timeout} seconds"
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
@@ -28,8 +28,8 @@ module HTTP
28
28
  end
29
29
 
30
30
  def connect_ssl
31
- rescue_readable do
32
- rescue_writable do
31
+ rescue_readable(@connect_timeout) do
32
+ rescue_writable(@connect_timeout) do
33
33
  @socket.connect_nonblock
34
34
  end
35
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTP
4
- VERSION = "2.0.3".freeze
4
+ VERSION = "2.1.0".freeze
5
5
  end
@@ -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(:client) { double(:sequence_id => 0) }
4
- let(:chunks) { [String.new("Hello, "), String.new("World!")] }
3
+ let(:connection) { double(:sequence_id => 0) }
4
+ let(:chunks) { [String.new("Hello, "), String.new("World!")] }
5
5
 
6
- before { allow(client).to receive(:readpartial) { chunks.shift } }
6
+ before { allow(connection).to receive(:readpartial) { chunks.shift } }
7
7
 
8
- subject(:body) { described_class.new(client, Encoding::UTF_8) }
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 client" do
25
- expect(client).to receive(:readpartial).with(42)
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 client readpartial without specific size" do
36
- expect(client).to receive(:readpartial).with no_args
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.3
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-08-03 00:00:00.000000000 Z
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: