httpi 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +3 -3
- data/lib/httpi/adapter/curb.rb +3 -2
- data/lib/httpi/adapter/em_http.rb +5 -4
- data/lib/httpi/adapter/excon.rb +2 -1
- data/lib/httpi/adapter/http.rb +6 -0
- data/lib/httpi/adapter/httpclient.rb +1 -0
- data/lib/httpi/adapter/net_http.rb +7 -0
- data/lib/httpi/adapter/net_http_persistent.rb +1 -0
- data/lib/httpi/auth/ssl.rb +1 -1
- data/lib/httpi/request.rb +2 -2
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/adapter/curb_spec.rb +14 -7
- data/spec/httpi/adapter/em_http_spec.rb +21 -13
- data/spec/httpi/adapter/excon_spec.rb +23 -119
- data/spec/httpi/adapter/http_spec.rb +23 -96
- data/spec/httpi/adapter/httpclient_spec.rb +14 -0
- data/spec/httpi/adapter/net_http_persistent_spec.rb +31 -81
- data/spec/httpi/adapter/net_http_spec.rb +37 -181
- data/spec/integration/curb_spec.rb +11 -0
- data/spec/integration/em_http_spec.rb +17 -0
- data/spec/integration/excon_spec.rb +47 -0
- data/spec/integration/http_spec.rb +28 -0
- data/spec/integration/httpclient_spec.rb +11 -0
- data/spec/integration/net_http_persistent_spec.rb +21 -2
- data/spec/integration/net_http_spec.rb +117 -1
- data/spec/integration/support/application.rb +3 -2
- metadata +3 -3
@@ -30,6 +30,18 @@ describe HTTPI::Adapter::HTTP 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 "http"
|
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(HTTP::TimeoutError)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
33
45
|
it "executes GET requests" do
|
34
46
|
response = HTTPI.get(@server.url, adapter)
|
35
47
|
expect(response.body).to eq("get")
|
@@ -68,6 +80,22 @@ describe HTTPI::Adapter::HTTP do
|
|
68
80
|
expect(response.body).to eq("basic-auth")
|
69
81
|
end
|
70
82
|
|
83
|
+
it "does not support digest authentication" do
|
84
|
+
request = HTTPI::Request.new(@server.url + "digest-auth")
|
85
|
+
request.auth.digest("admin", "secret")
|
86
|
+
|
87
|
+
expect { HTTPI.get(request, adapter) }.
|
88
|
+
to raise_error(HTTPI::NotSupportedError, /does not support HTTP digest authentication/)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "does not support ntlm authentication" do
|
92
|
+
request = HTTPI::Request.new(@server.url + "ntlm-auth")
|
93
|
+
request.auth.ntlm("tester", "vReqSoafRe5O")
|
94
|
+
|
95
|
+
expect { HTTPI.get(request, adapter) }.
|
96
|
+
to raise_error(HTTPI::NotSupportedError, /does not support NTLM digest authentication/)
|
97
|
+
end
|
98
|
+
|
71
99
|
it "supports chunked response" do
|
72
100
|
skip("Needs investigation")
|
73
101
|
request = HTTPI::Request.new(@server.url)
|
@@ -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,8 +48,8 @@ describe HTTPI::Adapter::NetHTTP do
|
|
37
48
|
end
|
38
49
|
|
39
50
|
it "executes POST requests" do
|
40
|
-
request = HTTPI::Request.new(url: @server.url,
|
41
|
-
|
51
|
+
request = HTTPI::Request.new(url: @server.url, body: "<some>xml</some>")
|
52
|
+
|
42
53
|
response = HTTPI.post(request, adapter)
|
43
54
|
expect(response.body).to eq("post")
|
44
55
|
expect(response.headers["Content-Type"]).to eq("text/plain")
|
@@ -70,6 +81,14 @@ describe HTTPI::Adapter::NetHTTP do
|
|
70
81
|
expect(response.body).to eq("basic-auth")
|
71
82
|
end
|
72
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
|
+
|
73
92
|
# it does not support digest authentication
|
74
93
|
|
75
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
|
-
|
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)
|
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.
|
4
|
+
version: 2.4.4
|
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: 2018-
|
12
|
+
date: 2018-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
220
|
version: '0'
|
221
221
|
requirements: []
|
222
222
|
rubyforge_project: httpi
|
223
|
-
rubygems_version: 2.7.
|
223
|
+
rubygems_version: 2.7.6
|
224
224
|
signing_key:
|
225
225
|
specification_version: 4
|
226
226
|
summary: Common interface for Ruby's HTTP libraries
|