http 5.0.0.pre → 5.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -1
  3. data/.travis.yml +6 -4
  4. data/CHANGES.md +83 -0
  5. data/Gemfile +2 -1
  6. data/README.md +7 -6
  7. data/http.gemspec +11 -4
  8. data/lib/http/chainable.rb +8 -3
  9. data/lib/http/client.rb +32 -34
  10. data/lib/http/connection.rb +5 -5
  11. data/lib/http/content_type.rb +2 -2
  12. data/lib/http/feature.rb +3 -0
  13. data/lib/http/features/auto_deflate.rb +13 -7
  14. data/lib/http/features/auto_inflate.rb +6 -5
  15. data/lib/http/features/normalize_uri.rb +17 -0
  16. data/lib/http/headers.rb +48 -11
  17. data/lib/http/headers/known.rb +3 -0
  18. data/lib/http/mime_type/adapter.rb +1 -1
  19. data/lib/http/mime_type/json.rb +1 -0
  20. data/lib/http/options.rb +4 -7
  21. data/lib/http/redirector.rb +3 -1
  22. data/lib/http/request.rb +32 -29
  23. data/lib/http/request/body.rb +26 -1
  24. data/lib/http/request/writer.rb +3 -2
  25. data/lib/http/response.rb +17 -15
  26. data/lib/http/response/body.rb +1 -0
  27. data/lib/http/response/parser.rb +20 -6
  28. data/lib/http/response/status.rb +2 -1
  29. data/lib/http/timeout/global.rb +1 -3
  30. data/lib/http/timeout/per_operation.rb +1 -0
  31. data/lib/http/uri.rb +13 -0
  32. data/lib/http/version.rb +1 -1
  33. data/spec/lib/http/client_spec.rb +96 -14
  34. data/spec/lib/http/connection_spec.rb +8 -5
  35. data/spec/lib/http/features/auto_inflate_spec.rb +4 -2
  36. data/spec/lib/http/features/instrumentation_spec.rb +7 -6
  37. data/spec/lib/http/features/logging_spec.rb +6 -5
  38. data/spec/lib/http/headers_spec.rb +52 -17
  39. data/spec/lib/http/options/headers_spec.rb +1 -1
  40. data/spec/lib/http/options/merge_spec.rb +16 -16
  41. data/spec/lib/http/redirector_spec.rb +15 -1
  42. data/spec/lib/http/request/body_spec.rb +22 -0
  43. data/spec/lib/http/request/writer_spec.rb +13 -1
  44. data/spec/lib/http/request_spec.rb +5 -5
  45. data/spec/lib/http/response/parser_spec.rb +45 -0
  46. data/spec/lib/http/response/status_spec.rb +3 -3
  47. data/spec/lib/http/response_spec.rb +11 -22
  48. data/spec/lib/http_spec.rb +30 -1
  49. data/spec/support/black_hole.rb +1 -1
  50. data/spec/support/dummy_server.rb +6 -6
  51. data/spec/support/dummy_server/servlet.rb +8 -4
  52. data/spec/support/http_handling_shared.rb +4 -4
  53. data/spec/support/ssl_helper.rb +4 -4
  54. metadata +23 -16
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require "json"
5
5
 
@@ -307,6 +307,15 @@ RSpec.describe HTTP do
307
307
  end
308
308
  end
309
309
 
310
+ context "specifying per operation timeouts as frozen hash" do
311
+ let(:frozen_options) { {:read => 123}.freeze }
312
+ subject(:client) { HTTP.timeout(frozen_options) }
313
+
314
+ it "does not raise an error" do
315
+ expect { client }.not_to raise_error
316
+ end
317
+ end
318
+
310
319
  context "specifying a global timeout" do
311
320
  subject(:client) { HTTP.timeout 123 }
312
321
 
@@ -430,6 +439,26 @@ RSpec.describe HTTP do
430
439
  expect(response.to_s).to eq("#{body}-deflated")
431
440
  end
432
441
  end
442
+
443
+ context "with :normalize_uri" do
444
+ it "normalizes URI" do
445
+ response = HTTP.get "#{dummy.endpoint}/hello world"
446
+ expect(response.to_s).to eq("hello world")
447
+ end
448
+
449
+ it "uses the custom URI Normalizer method" do
450
+ client = HTTP.use(:normalize_uri => {:normalizer => :itself.to_proc})
451
+ response = client.get("#{dummy.endpoint}/hello world")
452
+ expect(response.status).to eq(400)
453
+ end
454
+
455
+ it "uses the default URI normalizer" do
456
+ client = HTTP.use :normalize_uri
457
+ expect(HTTP::URI::NORMALIZER).to receive(:call).and_call_original
458
+ response = client.get("#{dummy.endpoint}/hello world")
459
+ expect(response.to_s).to eq("hello world")
460
+ end
461
+ end
433
462
  end
434
463
 
435
464
  it "unifies socket errors into HTTP::ConnectionError" do
@@ -2,7 +2,7 @@
2
2
 
3
3
  module BlackHole
4
4
  class << self
5
- def method_missing(*) # rubocop: disable Style/MethodMissing
5
+ def method_missing(*) # rubocop:disable Style/MethodMissingSuper
6
6
  self
7
7
  end
8
8
 
@@ -13,15 +13,15 @@ class DummyServer < WEBrick::HTTPServer
13
13
  include ServerConfig
14
14
 
15
15
  CONFIG = {
16
- :BindAddress => "127.0.0.1",
17
- :Port => 0,
18
- :AccessLog => BlackHole,
19
- :Logger => BlackHole
16
+ :BindAddress => "127.0.0.1",
17
+ :Port => 0,
18
+ :AccessLog => BlackHole,
19
+ :Logger => BlackHole
20
20
  }.freeze
21
21
 
22
22
  SSL_CONFIG = CONFIG.merge(
23
- :SSLEnable => true,
24
- :SSLStartImmediately => true
23
+ :SSLEnable => true,
24
+ :SSLStartImmediately => true
25
25
  ).freeze
26
26
 
27
27
  def initialize(options = {}) # rubocop:disable Style/OptionHash
@@ -1,9 +1,8 @@
1
- # frozen_string_literal: true
2
1
  # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  class DummyServer < WEBrick::HTTPServer
5
- # rubocop:disable Metrics/ClassLength
6
- class Servlet < WEBrick::HTTPServlet::AbstractServlet
5
+ class Servlet < WEBrick::HTTPServlet::AbstractServlet # rubocop:disable Metrics/ClassLength
7
6
  def self.sockets
8
7
  @sockets ||= []
9
8
  end
@@ -18,7 +17,7 @@ class DummyServer < WEBrick::HTTPServer
18
17
  end
19
18
 
20
19
  %w[get post head].each do |method|
21
- class_eval <<-RUBY, __FILE__, __LINE__
20
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
22
21
  def self.#{method}(path, &block)
23
22
  handlers["#{method}:\#{path}"] = block
24
23
  end
@@ -148,6 +147,11 @@ class DummyServer < WEBrick::HTTPServer
148
147
  res.body = req.body
149
148
  end
150
149
 
150
+ get "/hello world" do |_req, res|
151
+ res.status = 200
152
+ res.body = "hello world"
153
+ end
154
+
151
155
  post "/encoded-body" do |req, res|
152
156
  res.status = 200
153
157
 
@@ -14,11 +14,11 @@ RSpec.shared_context "HTTP handling" do
14
14
 
15
15
  let(:options) do
16
16
  {
17
- :timeout_class => HTTP::Timeout::PerOperation,
17
+ :timeout_class => HTTP::Timeout::PerOperation,
18
18
  :timeout_options => {
19
19
  :connect_timeout => conn_timeout,
20
- :read_timeout => read_timeout,
21
- :write_timeout => write_timeout
20
+ :read_timeout => read_timeout,
21
+ :write_timeout => write_timeout
22
22
  }
23
23
  }
24
24
  end
@@ -62,7 +62,7 @@ RSpec.shared_context "HTTP handling" do
62
62
  context "with a global timeout" do
63
63
  let(:options) do
64
64
  {
65
- :timeout_class => HTTP::Timeout::Global,
65
+ :timeout_class => HTTP::Timeout::Global,
66
66
  :timeout_options => {
67
67
  :global_timeout => global_timeout
68
68
  }
@@ -5,7 +5,7 @@ require "pathname"
5
5
  require "certificate_authority"
6
6
 
7
7
  module SSLHelper
8
- CERTS_PATH = Pathname.new File.expand_path("../../../tmp/certs", __FILE__)
8
+ CERTS_PATH = Pathname.new File.expand_path("../../tmp/certs", __dir__)
9
9
 
10
10
  class RootCertificate < ::CertificateAuthority::Certificate
11
11
  EXTENSIONS = {"keyUsage" => {"usage" => %w[critical keyCertSign]}}.freeze
@@ -83,14 +83,14 @@ module SSLHelper
83
83
 
84
84
  def client_params
85
85
  {
86
- :key => client_cert.key,
87
- :cert => client_cert.cert,
86
+ :key => client_cert.key,
87
+ :cert => client_cert.cert,
88
88
  :ca_file => ca.file
89
89
  }
90
90
  end
91
91
 
92
92
  %w[server client].each do |side|
93
- class_eval <<-RUBY, __FILE__, __LINE__
93
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
94
94
  def #{side}_cert
95
95
  @#{side}_cert ||= ChildCertificate.new ca
96
96
  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: 5.0.0.pre
4
+ version: 5.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -11,64 +11,64 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-02-04 00:00:00.000000000 Z
14
+ date: 2020-01-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: http-parser
17
+ name: addressable
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - "~>"
21
21
  - !ruby/object:Gem::Version
22
- version: 1.2.0
22
+ version: '2.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 1.2.0
29
+ version: '2.3'
30
30
  - !ruby/object:Gem::Dependency
31
- name: http-form_data
31
+ name: http-cookie
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: '2.0'
36
+ version: '1.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '2.0'
43
+ version: '1.0'
44
44
  - !ruby/object:Gem::Dependency
45
- name: http-cookie
45
+ name: http-form_data
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: '1.0'
50
+ version: '2.2'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: '1.0'
57
+ version: '2.2'
58
58
  - !ruby/object:Gem::Dependency
59
- name: addressable
59
+ name: http-parser
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: '2.3'
64
+ version: 1.2.0
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - "~>"
70
70
  - !ruby/object:Gem::Version
71
- version: '2.3'
71
+ version: 1.2.0
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: bundler
74
74
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +116,7 @@ files:
116
116
  - lib/http/features/auto_inflate.rb
117
117
  - lib/http/features/instrumentation.rb
118
118
  - lib/http/features/logging.rb
119
+ - lib/http/features/normalize_uri.rb
119
120
  - lib/http/headers.rb
120
121
  - lib/http/headers/known.rb
121
122
  - lib/http/headers/mixin.rb
@@ -162,6 +163,7 @@ files:
162
163
  - spec/lib/http/request/writer_spec.rb
163
164
  - spec/lib/http/request_spec.rb
164
165
  - spec/lib/http/response/body_spec.rb
166
+ - spec/lib/http/response/parser_spec.rb
165
167
  - spec/lib/http/response/status_spec.rb
166
168
  - spec/lib/http/response_spec.rb
167
169
  - spec/lib/http/uri_spec.rb
@@ -181,7 +183,11 @@ files:
181
183
  homepage: https://github.com/httprb/http
182
184
  licenses:
183
185
  - MIT
184
- metadata: {}
186
+ metadata:
187
+ source_code_uri: https://github.com/httprb/http
188
+ wiki_uri: https://github.com/httprb/http/wiki
189
+ bug_tracker_uri: https://github.com/httprb/http/issues
190
+ changelog_uri: https://github.com/httprb/http/blob/v5.0.0.pre2/CHANGES.md
185
191
  post_install_message:
186
192
  rdoc_options: []
187
193
  require_paths:
@@ -197,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
203
  - !ruby/object:Gem::Version
198
204
  version: 1.3.1
199
205
  requirements: []
200
- rubygems_version: 3.0.1
206
+ rubygems_version: 3.1.2
201
207
  signing_key:
202
208
  specification_version: 4
203
209
  summary: HTTP should be easy
@@ -225,6 +231,7 @@ test_files:
225
231
  - spec/lib/http/request/writer_spec.rb
226
232
  - spec/lib/http/request_spec.rb
227
233
  - spec/lib/http/response/body_spec.rb
234
+ - spec/lib/http/response/parser_spec.rb
228
235
  - spec/lib/http/response/status_spec.rb
229
236
  - spec/lib/http/response_spec.rb
230
237
  - spec/lib/http/uri_spec.rb