http 2.2.2 → 3.0.0.pre

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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +46 -13
  3. data/.travis.yml +17 -12
  4. data/CHANGES.md +25 -1
  5. data/Gemfile +11 -4
  6. data/Guardfile +2 -0
  7. data/README.md +4 -5
  8. data/Rakefile +14 -13
  9. data/http.gemspec +3 -1
  10. data/lib/http.rb +1 -0
  11. data/lib/http/chainable.rb +15 -14
  12. data/lib/http/client.rb +27 -24
  13. data/lib/http/connection.rb +6 -4
  14. data/lib/http/content_type.rb +1 -0
  15. data/lib/http/errors.rb +3 -2
  16. data/lib/http/feature.rb +2 -1
  17. data/lib/http/features/auto_deflate.rb +77 -20
  18. data/lib/http/features/auto_inflate.rb +2 -1
  19. data/lib/http/headers.rb +3 -2
  20. data/lib/http/headers/known.rb +23 -22
  21. data/lib/http/headers/mixin.rb +1 -0
  22. data/lib/http/mime_type.rb +1 -0
  23. data/lib/http/mime_type/adapter.rb +2 -1
  24. data/lib/http/mime_type/json.rb +2 -1
  25. data/lib/http/options.rb +15 -12
  26. data/lib/http/redirector.rb +4 -3
  27. data/lib/http/request.rb +25 -10
  28. data/lib/http/request/body.rb +67 -0
  29. data/lib/http/request/writer.rb +32 -37
  30. data/lib/http/response.rb +17 -2
  31. data/lib/http/response/body.rb +16 -12
  32. data/lib/http/response/parser.rb +1 -0
  33. data/lib/http/response/status.rb +1 -0
  34. data/lib/http/response/status/reasons.rb +1 -0
  35. data/lib/http/timeout/global.rb +1 -0
  36. data/lib/http/timeout/null.rb +2 -1
  37. data/lib/http/timeout/per_operation.rb +19 -6
  38. data/lib/http/uri.rb +8 -2
  39. data/lib/http/version.rb +1 -1
  40. data/spec/lib/http/client_spec.rb +104 -4
  41. data/spec/lib/http/content_type_spec.rb +1 -0
  42. data/spec/lib/http/features/auto_deflate_spec.rb +32 -64
  43. data/spec/lib/http/features/auto_inflate_spec.rb +1 -0
  44. data/spec/lib/http/headers/mixin_spec.rb +1 -0
  45. data/spec/lib/http/headers_spec.rb +36 -35
  46. data/spec/lib/http/options/body_spec.rb +1 -0
  47. data/spec/lib/http/options/features_spec.rb +1 -0
  48. data/spec/lib/http/options/form_spec.rb +1 -0
  49. data/spec/lib/http/options/headers_spec.rb +2 -1
  50. data/spec/lib/http/options/json_spec.rb +1 -0
  51. data/spec/lib/http/options/new_spec.rb +2 -1
  52. data/spec/lib/http/options/proxy_spec.rb +1 -0
  53. data/spec/lib/http/options_spec.rb +1 -0
  54. data/spec/lib/http/redirector_spec.rb +1 -0
  55. data/spec/lib/http/request/body_spec.rb +138 -0
  56. data/spec/lib/http/request/writer_spec.rb +44 -74
  57. data/spec/lib/http/request_spec.rb +14 -0
  58. data/spec/lib/http/response/body_spec.rb +20 -4
  59. data/spec/lib/http/response/status_spec.rb +27 -26
  60. data/spec/lib/http/response_spec.rb +10 -0
  61. data/spec/lib/http/uri_spec.rb +11 -0
  62. data/spec/lib/http_spec.rb +18 -6
  63. data/spec/regression_specs.rb +1 -0
  64. data/spec/spec_helper.rb +1 -0
  65. data/spec/support/black_hole.rb +9 -2
  66. data/spec/support/capture_warning.rb +1 -0
  67. data/spec/support/dummy_server.rb +2 -1
  68. data/spec/support/dummy_server/servlet.rb +1 -1
  69. data/spec/support/fakeio.rb +21 -0
  70. data/spec/support/http_handling_shared.rb +1 -0
  71. data/spec/support/proxy_server.rb +1 -0
  72. data/spec/support/servers/config.rb +1 -0
  73. data/spec/support/servers/runner.rb +1 -0
  74. data/spec/support/ssl_helper.rb +3 -2
  75. metadata +20 -9
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  RSpec.describe HTTP::Response do
3
4
  let(:body) { "Hello world!" }
4
5
  let(:uri) { "http://example.com/" }
@@ -173,4 +174,13 @@ RSpec.describe HTTP::Response do
173
174
  expect(response.connection).to eq connection
174
175
  end
175
176
  end
177
+
178
+ describe "#chunked?" do
179
+ subject { response }
180
+ context "when encoding is set to chunked" do
181
+ let(:headers) { {"Transfer-Encoding" => "chunked"} }
182
+ it { is_expected.to be_chunked }
183
+ end
184
+ it { is_expected.not_to be_chunked }
185
+ end
176
186
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  RSpec.describe HTTP::URI do
3
4
  let(:example_http_uri_string) { "http://example.com" }
4
5
  let(:example_https_uri_string) { "https://example.com" }
@@ -18,4 +19,14 @@ RSpec.describe HTTP::URI do
18
19
  it "sets default ports for HTTPS URIs" do
19
20
  expect(https_uri.port).to eq 443
20
21
  end
22
+
23
+ describe "#dup" do
24
+ it "doesn't share internal value between duplicates" do
25
+ duplicated_uri = http_uri.dup
26
+ duplicated_uri.host = "example.org"
27
+
28
+ expect(duplicated_uri.to_s).to eq("http://example.org")
29
+ expect(http_uri.to_s).to eq("http://example.com")
30
+ end
31
+ end
21
32
  end
@@ -49,7 +49,7 @@ RSpec.describe HTTP do
49
49
  end
50
50
 
51
51
  context "with a large request body" do
52
- %w(global null per_operation).each do |timeout|
52
+ %w[global null per_operation].each do |timeout|
53
53
  context "with a #{timeout} timeout" do
54
54
  [16_000, 16_500, 17_000, 34_000, 68_000].each do |size|
55
55
  [0, rand(0..100), rand(100..1000)].each do |fuzzer|
@@ -382,11 +382,6 @@ RSpec.describe HTTP do
382
382
  client = HTTP.headers("Cookie" => "foo=bar").cookies(:baz => :moo)
383
383
  expect(client.get(endpoint).to_s).to eq "foo: bar\nbaz: moo"
384
384
  end
385
-
386
- it "unifies socket errors into HTTP::ConnectionError" do
387
- expect { HTTP.get "http://thishostshouldnotexists.com" }.to raise_error HTTP::ConnectionError
388
- expect { HTTP.get "http://127.0.0.1:000" }.to raise_error HTTP::ConnectionError
389
- end
390
385
  end
391
386
 
392
387
  describe ".nodelay" do
@@ -434,6 +429,15 @@ RSpec.describe HTTP do
434
429
 
435
430
  expect(Zlib::GzipReader.new(StringIO.new(encoded)).read).to eq body
436
431
  end
432
+
433
+ it "sends deflated body" do
434
+ client = HTTP.use :auto_deflate => {:method => "deflate"}
435
+ body = "Hello!"
436
+ response = client.post("#{dummy.endpoint}/echo-body", :body => body)
437
+ encoded = response.to_s
438
+
439
+ expect(Zlib::Inflate.inflate(encoded)).to eq body
440
+ end
437
441
  end
438
442
 
439
443
  context "with :auto_inflate" do
@@ -461,4 +465,12 @@ RSpec.describe HTTP do
461
465
  end
462
466
  end
463
467
  end
468
+
469
+ it "unifies socket errors into HTTP::ConnectionError" do
470
+ expect { HTTP.get "http://thishostshouldnotexists.com" }.
471
+ to raise_error HTTP::ConnectionError
472
+
473
+ expect { HTTP.get "http://127.0.0.1:000" }.
474
+ to raise_error HTTP::ConnectionError
475
+ end
464
476
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "spec_helper"
3
4
 
4
5
  RSpec.describe "Regression testing" do
@@ -18,6 +18,7 @@ end
18
18
  require "http"
19
19
  require "rspec/its"
20
20
  require "support/capture_warning"
21
+ require "support/fakeio"
21
22
 
22
23
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
23
24
  RSpec.configure do |config|
@@ -1,6 +1,13 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module BlackHole
3
- def self.method_missing(*)
4
- self
4
+ class << self
5
+ def method_missing(*) # rubocop: disable Style/MethodMissing
6
+ self
7
+ end
8
+
9
+ def respond_to_missing?(*)
10
+ true
11
+ end
5
12
  end
6
13
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  def capture_warning
3
4
  old_stderr = $stderr
4
5
  $stderr = StringIO.new
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "webrick"
3
4
  require "webrick/ssl"
4
5
 
@@ -23,7 +24,7 @@ class DummyServer < WEBrick::HTTPServer
23
24
  :SSLStartImmediately => true
24
25
  ).freeze
25
26
 
26
- def initialize(options = {})
27
+ def initialize(options = {}) # rubocop:disable Style/OptionHash
27
28
  super(options[:ssl] ? SSL_CONFIG : CONFIG)
28
29
  mount("/", Servlet)
29
30
  end
@@ -17,7 +17,7 @@ class DummyServer < WEBrick::HTTPServer
17
17
  @handlers ||= {}
18
18
  end
19
19
 
20
- %w(get post head).each do |method|
20
+ %w[get post head].each do |method|
21
21
  class_eval <<-RUBY, __FILE__, __LINE__
22
22
  def self.#{method}(path, &block)
23
23
  handlers["#{method}:\#{path}"] = block
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stringio"
4
+
5
+ class FakeIO
6
+ def initialize(content)
7
+ @io = StringIO.new(content)
8
+ end
9
+
10
+ def string
11
+ @io.string
12
+ end
13
+
14
+ def read(*args)
15
+ @io.read(*args)
16
+ end
17
+
18
+ def size
19
+ @io.size
20
+ end
21
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  RSpec.shared_context "HTTP handling" do
3
4
  describe "timeouts" do
4
5
  let(:conn_timeout) { 1 }
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "webrick/httpproxy"
3
4
 
4
5
  require "support/black_hole"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ServerConfig
3
4
  def addr
4
5
  config[:BindAddress]
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ServerRunner
3
4
  def run_server(name)
4
5
  let! name do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "pathname"
3
4
 
4
5
  require "certificate_authority"
@@ -7,7 +8,7 @@ module SSLHelper
7
8
  CERTS_PATH = Pathname.new File.expand_path("../../../tmp/certs", __FILE__)
8
9
 
9
10
  class RootCertificate < ::CertificateAuthority::Certificate
10
- EXTENSIONS = {"keyUsage" => {"usage" => %w(critical keyCertSign)}}.freeze
11
+ EXTENSIONS = {"keyUsage" => {"usage" => %w[critical keyCertSign]}}.freeze
11
12
 
12
13
  def initialize
13
14
  super()
@@ -88,7 +89,7 @@ module SSLHelper
88
89
  }
89
90
  end
90
91
 
91
- %w(server client).each do |side|
92
+ %w[server client].each do |side|
92
93
  class_eval <<-RUBY, __FILE__, __LINE__
93
94
  def #{side}_cert
94
95
  @#{side}_cert ||= ChildCertificate.new ca
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.2.2
4
+ version: 3.0.0.pre
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: 2017-04-27 00:00:00.000000000 Z
14
+ date: 2017-09-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: http_parser.rb
@@ -31,16 +31,22 @@ dependencies:
31
31
  name: http-form_data
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - "~>"
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.0.0.pre.pre2
37
+ - - "<"
35
38
  - !ruby/object:Gem::Version
36
- version: 1.0.1
39
+ version: '3'
37
40
  type: :runtime
38
41
  prerelease: false
39
42
  version_requirements: !ruby/object:Gem::Requirement
40
43
  requirements:
41
- - - "~>"
44
+ - - ">="
42
45
  - !ruby/object:Gem::Version
43
- version: 1.0.1
46
+ version: 2.0.0.pre.pre2
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '3'
44
50
  - !ruby/object:Gem::Dependency
45
51
  name: http-cookie
46
52
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +130,7 @@ files:
124
130
  - lib/http/options.rb
125
131
  - lib/http/redirector.rb
126
132
  - lib/http/request.rb
133
+ - lib/http/request/body.rb
127
134
  - lib/http/request/writer.rb
128
135
  - lib/http/response.rb
129
136
  - lib/http/response/body.rb
@@ -153,6 +160,7 @@ files:
153
160
  - spec/lib/http/options/proxy_spec.rb
154
161
  - spec/lib/http/options_spec.rb
155
162
  - spec/lib/http/redirector_spec.rb
163
+ - spec/lib/http/request/body_spec.rb
156
164
  - spec/lib/http/request/writer_spec.rb
157
165
  - spec/lib/http/request_spec.rb
158
166
  - spec/lib/http/response/body_spec.rb
@@ -166,6 +174,7 @@ files:
166
174
  - spec/support/capture_warning.rb
167
175
  - spec/support/dummy_server.rb
168
176
  - spec/support/dummy_server/servlet.rb
177
+ - spec/support/fakeio.rb
169
178
  - spec/support/http_handling_shared.rb
170
179
  - spec/support/proxy_server.rb
171
180
  - spec/support/servers/config.rb
@@ -186,12 +195,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
195
  version: '2.0'
187
196
  required_rubygems_version: !ruby/object:Gem::Requirement
188
197
  requirements:
189
- - - ">="
198
+ - - ">"
190
199
  - !ruby/object:Gem::Version
191
- version: '0'
200
+ version: 1.3.1
192
201
  requirements: []
193
202
  rubyforge_project:
194
- rubygems_version: 2.6.8
203
+ rubygems_version: 2.6.12
195
204
  signing_key:
196
205
  specification_version: 4
197
206
  summary: HTTP should be easy
@@ -212,6 +221,7 @@ test_files:
212
221
  - spec/lib/http/options/proxy_spec.rb
213
222
  - spec/lib/http/options_spec.rb
214
223
  - spec/lib/http/redirector_spec.rb
224
+ - spec/lib/http/request/body_spec.rb
215
225
  - spec/lib/http/request/writer_spec.rb
216
226
  - spec/lib/http/request_spec.rb
217
227
  - spec/lib/http/response/body_spec.rb
@@ -225,6 +235,7 @@ test_files:
225
235
  - spec/support/capture_warning.rb
226
236
  - spec/support/dummy_server.rb
227
237
  - spec/support/dummy_server/servlet.rb
238
+ - spec/support/fakeio.rb
228
239
  - spec/support/http_handling_shared.rb
229
240
  - spec/support/proxy_server.rb
230
241
  - spec/support/servers/config.rb