httpi 2.4.0 → 2.4.5

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 (42) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +3 -5
  3. data/CHANGELOG.md +42 -0
  4. data/Gemfile +5 -1
  5. data/README.md +7 -7
  6. data/Rakefile +5 -3
  7. data/httpi.gemspec +2 -1
  8. data/lib/httpi.rb +5 -4
  9. data/lib/httpi/adapter.rb +1 -1
  10. data/lib/httpi/adapter/curb.rb +18 -5
  11. data/lib/httpi/adapter/em_http.rb +5 -4
  12. data/lib/httpi/adapter/excon.rb +16 -5
  13. data/lib/httpi/adapter/http.rb +88 -0
  14. data/lib/httpi/adapter/httpclient.rb +15 -4
  15. data/lib/httpi/adapter/net_http.rb +43 -16
  16. data/lib/httpi/adapter/net_http_persistent.rb +10 -1
  17. data/lib/httpi/adapter/rack.rb +13 -6
  18. data/lib/httpi/auth/ssl.rb +49 -2
  19. data/lib/httpi/logger.rb +6 -1
  20. data/lib/httpi/request.rb +12 -5
  21. data/lib/httpi/response.rb +2 -0
  22. data/lib/httpi/version.rb +1 -1
  23. data/spec/httpi/adapter/curb_spec.rb +56 -18
  24. data/spec/httpi/adapter/em_http_spec.rb +21 -13
  25. data/spec/httpi/adapter/excon_spec.rb +28 -90
  26. data/spec/httpi/adapter/http_spec.rb +28 -0
  27. data/spec/httpi/adapter/httpclient_spec.rb +39 -4
  28. data/spec/httpi/adapter/net_http_persistent_spec.rb +31 -81
  29. data/spec/httpi/adapter/net_http_spec.rb +39 -99
  30. data/spec/httpi/adapter/rack_spec.rb +6 -8
  31. data/spec/httpi/auth/ssl_spec.rb +32 -1
  32. data/spec/httpi/httpi_spec.rb +17 -1
  33. data/spec/httpi/request_spec.rb +5 -0
  34. data/spec/integration/curb_spec.rb +11 -0
  35. data/spec/integration/em_http_spec.rb +17 -0
  36. data/spec/integration/excon_spec.rb +165 -0
  37. data/spec/integration/http_spec.rb +147 -0
  38. data/spec/integration/httpclient_spec.rb +11 -0
  39. data/spec/integration/net_http_persistent_spec.rb +22 -1
  40. data/spec/integration/net_http_spec.rb +127 -1
  41. data/spec/integration/support/application.rb +4 -2
  42. metadata +35 -4
@@ -30,6 +30,17 @@ describe HTTPI::Adapter::HTTPClient do
30
30
  expect(response.headers["Set-Cookie"]).to eq(cookies)
31
31
  end
32
32
 
33
+ it "it supports read timeout" do
34
+ require "httpclient"
35
+
36
+ request = HTTPI::Request.new(@server.url + "timeout")
37
+ request.read_timeout = 0.5 # seconds
38
+
39
+ expect do
40
+ HTTPI.get(request, adapter)
41
+ end.to raise_exception(HTTPClient::ReceiveTimeoutError)
42
+ end
43
+
33
44
  it "executes GET requests" do
34
45
  response = HTTPI.get(@server.url, adapter)
35
46
  expect(response.body).to eq("get")
@@ -30,6 +30,17 @@ describe HTTPI::Adapter::NetHTTP do
30
30
  expect(response.headers["Set-Cookie"]).to eq(cookies)
31
31
  end
32
32
 
33
+ it "it supports read timeout" do
34
+ require "net/http/persistent"
35
+
36
+ request = HTTPI::Request.new(@server.url + "timeout")
37
+ request.read_timeout = 0.5 # seconds
38
+
39
+ expect do
40
+ HTTPI.get(request, adapter)
41
+ end.to raise_exception(Net::HTTP::Persistent::Error, /Net::ReadTimeout/)
42
+ end
43
+
33
44
  it "executes GET requests" do
34
45
  response = HTTPI.get(@server.url, adapter)
35
46
  expect(response.body).to eq("get")
@@ -37,7 +48,9 @@ describe HTTPI::Adapter::NetHTTP do
37
48
  end
38
49
 
39
50
  it "executes POST requests" do
40
- response = HTTPI.post(@server.url, "<some>xml</some>", adapter)
51
+ request = HTTPI::Request.new(url: @server.url, body: "<some>xml</some>")
52
+
53
+ response = HTTPI.post(request, adapter)
41
54
  expect(response.body).to eq("post")
42
55
  expect(response.headers["Content-Type"]).to eq("text/plain")
43
56
  end
@@ -68,6 +81,14 @@ describe HTTPI::Adapter::NetHTTP do
68
81
  expect(response.body).to eq("basic-auth")
69
82
  end
70
83
 
84
+ it "does not support ntlm authentication" do
85
+ request = HTTPI::Request.new(@server.url + "ntlm-auth")
86
+ request.auth.ntlm("tester", "vReqSoafRe5O")
87
+
88
+ expect { HTTPI.get(request, adapter) }.
89
+ to raise_error(HTTPI::NotSupportedError, /does not support NTLM authentication/)
90
+ end
91
+
71
92
  # it does not support digest authentication
72
93
 
73
94
  it "supports chunked response" do
@@ -14,6 +14,21 @@ describe HTTPI::Adapter::NetHTTP do
14
14
  @server.stop
15
15
  end
16
16
 
17
+ context "when socks is specified" do
18
+ let(:socks_client) { mock("socks_client") }
19
+ let(:request) { HTTPI::Request.new(@server.url) }
20
+
21
+ it "uses Net::HTTP.SOCKSProxy as client" do
22
+ socks_client.expects(:new).with(URI(@server.url).host, URI(@server.url).port).returns(:socks_client_instance)
23
+ Net::HTTP.expects(:SOCKSProxy).with("localhost", 8080).returns socks_client
24
+
25
+ request.proxy = "socks://localhost:8080"
26
+ adapter = HTTPI::Adapter::NetHTTP.new(request)
27
+
28
+ expect(adapter.client).to eq(:socks_client_instance)
29
+ end
30
+ end
31
+
17
32
  it "sends and receives HTTP headers" do
18
33
  request = HTTPI::Request.new(@server.url + "x-header")
19
34
  request.headers["X-Header"] = "HTTPI"
@@ -30,6 +45,17 @@ describe HTTPI::Adapter::NetHTTP do
30
45
  expect(response.headers["Set-Cookie"]).to eq(cookies)
31
46
  end
32
47
 
48
+ it "it supports read timeout" do
49
+ require "net/http"
50
+
51
+ request = HTTPI::Request.new(@server.url + "timeout")
52
+ request.read_timeout = 0.5 # seconds
53
+
54
+ expect do
55
+ HTTPI.get(request, adapter)
56
+ end.to raise_exception(Net::ReadTimeout)
57
+ end
58
+
33
59
  it "executes GET requests" do
34
60
  response = HTTPI.get(@server.url, adapter)
35
61
  expect(response.body).to eq("get")
@@ -60,6 +86,34 @@ describe HTTPI::Adapter::NetHTTP do
60
86
  expect(response.headers["Content-Type"]).to eq("text/plain")
61
87
  end
62
88
 
89
+ context "custom methods" do
90
+ let(:request) {
91
+ HTTPI::Request.new(@server.url).tap do |r|
92
+ r.body = request_body if request_body
93
+ end
94
+ }
95
+ let(:request_body) { nil }
96
+ let(:response) { HTTPI.request(http_method, request, adapter) }
97
+
98
+ shared_examples_for "any supported custom method" do
99
+ specify { response.body.should eq http_method.to_s }
100
+ specify { response.headers["Content-Type"].should eq("text/plain") }
101
+ end
102
+
103
+ context "PATCH method" do
104
+ let(:http_method) { :patch }
105
+ let(:request_body) { "<some>xml</some>" }
106
+
107
+ it_behaves_like "any supported custom method"
108
+ end
109
+
110
+ context "UNSUPPORTED method" do
111
+ let(:http_method) { :unsupported }
112
+
113
+ specify { expect { response }.to raise_error HTTPI::NotSupportedError }
114
+ end
115
+ end
116
+
63
117
  it "supports basic authentication" do
64
118
  request = HTTPI::Request.new(@server.url + "basic-auth")
65
119
  request.auth.basic("admin", "secret")
@@ -68,7 +122,69 @@ describe HTTPI::Adapter::NetHTTP do
68
122
  expect(response.body).to eq("basic-auth")
69
123
  end
70
124
 
71
- # it does not support digest authentication
125
+ it "does not support digest authentication" do
126
+ request = HTTPI::Request.new(@server.url + "digest-auth")
127
+ request.auth.digest("admin", "secret")
128
+
129
+ expect { HTTPI.get(request, adapter) }.
130
+ to raise_error(HTTPI::NotSupportedError, /does not support HTTP digest authentication/)
131
+ end
132
+
133
+ it "supports ntlm authentication" do
134
+ request = HTTPI::Request.new(@server.url + "ntlm-auth")
135
+ request.auth.ntlm("tester", "vReqSoafRe5O")
136
+
137
+ response = HTTPI.get(request, adapter)
138
+ expect(response.body).to eq("ntlm-auth")
139
+ end
140
+
141
+ it "does not support ntlm authentication when Net::NTLM is not available" do
142
+ Net.expects(:const_defined?).with(:NTLM).returns false
143
+
144
+ request = HTTPI::Request.new(@server.url + "ntlm-auth")
145
+ request.auth.ntlm("testing", "failures")
146
+
147
+ expect { HTTPI.get(request, adapter) }.
148
+ to raise_error(HTTPI::NotSupportedError, /Net::NTLM is not available/)
149
+ end
150
+
151
+ it "does not require ntlm when ntlm authenication is not requested" do
152
+ HTTPI::Adapter::NetHTTP.any_instance.stubs(:check_net_ntlm_version!).raises(RuntimeError)
153
+ request = HTTPI::Request.new(@server.url)
154
+ expect(request.auth.ntlm?).to be false
155
+
156
+ # make sure a request doesn't call ntlm check if we don't ask for it.
157
+ expect { HTTPI.get(request, adapter) }.not_to raise_error
158
+ HTTPI::Adapter::NetHTTP.any_instance.unstub(:check_net_ntlm_version!)
159
+ end
160
+
161
+ it "does check ntlm when ntlm authentication is requested" do
162
+ request = HTTPI::Request.new(@server.url + "ntlm-auth")
163
+ request.auth.ntlm("tester", "vReqSoafRe5O")
164
+
165
+ expect { HTTPI.get(request, adapter) }.not_to raise_error
166
+
167
+ # the check should also verify that the version of ntlm is supported and still fail if it isn't
168
+ HTTPI::Adapter::NetHTTP.any_instance.stubs(:ntlm_version).returns("0.1.1")
169
+
170
+ request = HTTPI::Request.new(@server.url + "ntlm-auth")
171
+ request.auth.ntlm("tester", "vReqSoafRe5O")
172
+
173
+ expect { HTTPI.get(request, adapter) }.to raise_error(ArgumentError, /Invalid version/)
174
+
175
+ HTTPI::Adapter::NetHTTP.any_instance.unstub(:ntlm_version)
176
+ end
177
+
178
+ it "does not crash when authenticate header is missing (on second request)" do
179
+ request = HTTPI::Request.new(@server.url + "ntlm-auth")
180
+ request.auth.ntlm("tester", "vReqSoafRe5O")
181
+
182
+ expect { HTTPI.get(request, adapter) }.
183
+ to_not raise_error
184
+
185
+ expect { HTTPI.get(request, adapter) }.
186
+ to_not raise_error
187
+ end
72
188
 
73
189
  it "supports chunked response" do
74
190
  request = HTTPI::Request.new(@server.url)
@@ -101,6 +217,16 @@ describe HTTPI::Adapter::NetHTTP do
101
217
  response = HTTPI.get(request, adapter)
102
218
  expect(response.body).to eq("get")
103
219
  end
220
+
221
+ it "works with min_version/max_version" do
222
+ request = HTTPI::Request.new(@server.url)
223
+ request.auth.ssl.ca_cert_file = IntegrationServer.ssl_ca_file
224
+ request.auth.ssl.min_version = :TLS1_2
225
+ request.auth.ssl.max_version = :TLS1_2
226
+
227
+ response = HTTPI.get(request, adapter)
228
+ expect(response.body).to eq("get")
229
+ end
104
230
  end
105
231
  end
106
232
 
@@ -1,3 +1,4 @@
1
+ require 'rack'
1
2
  require "rack/builder"
2
3
 
3
4
  class IntegrationServer
@@ -14,9 +15,10 @@ class IntegrationServer
14
15
  }
15
16
  end
16
17
 
17
- map "/repeat" do
18
+ map "/timeout" do
18
19
  run lambda { |env|
19
- IntegrationServer.respond_with :body => env["rack.input"].read
20
+ sleep 2
21
+ IntegrationServer.respond_with "done"
20
22
  }
21
23
  end
22
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-01 00:00:00.000000000 Z
12
+ date: 2020-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: socksify
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: rubyntlm
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +109,20 @@ dependencies:
95
109
  - - "~>"
96
110
  - !ruby/object:Gem::Version
97
111
  version: 2.3.2
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
98
126
  description: Common interface for Ruby's HTTP libraries
99
127
  email: me@rubiii.com
100
128
  executables: []
@@ -116,6 +144,7 @@ files:
116
144
  - lib/httpi/adapter/curb.rb
117
145
  - lib/httpi/adapter/em_http.rb
118
146
  - lib/httpi/adapter/excon.rb
147
+ - lib/httpi/adapter/http.rb
119
148
  - lib/httpi/adapter/httpclient.rb
120
149
  - lib/httpi/adapter/net_http.rb
121
150
  - lib/httpi/adapter/net_http_persistent.rb
@@ -141,6 +170,7 @@ files:
141
170
  - spec/httpi/adapter/curb_spec.rb
142
171
  - spec/httpi/adapter/em_http_spec.rb
143
172
  - spec/httpi/adapter/excon_spec.rb
173
+ - spec/httpi/adapter/http_spec.rb
144
174
  - spec/httpi/adapter/httpclient_spec.rb
145
175
  - spec/httpi/adapter/net_http_persistent_spec.rb
146
176
  - spec/httpi/adapter/net_http_spec.rb
@@ -156,9 +186,11 @@ files:
156
186
  - spec/httpi/response_spec.rb
157
187
  - spec/integration/curb_spec.rb
158
188
  - spec/integration/em_http_spec.rb
189
+ - spec/integration/excon_spec.rb
159
190
  - spec/integration/fixtures/ca_all.pem
160
191
  - spec/integration/fixtures/server.cert
161
192
  - spec/integration/fixtures/server.key
193
+ - spec/integration/http_spec.rb
162
194
  - spec/integration/httpclient_spec.rb
163
195
  - spec/integration/net_http_persistent_spec.rb
164
196
  - spec/integration/net_http_spec.rb
@@ -187,8 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
219
  - !ruby/object:Gem::Version
188
220
  version: '0'
189
221
  requirements: []
190
- rubyforge_project: httpi
191
- rubygems_version: 2.2.2
222
+ rubygems_version: 3.0.3
192
223
  signing_key:
193
224
  specification_version: 4
194
225
  summary: Common interface for Ruby's HTTP libraries