httpi 4.0.3 → 4.0.4
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/httpi/version.rb +1 -1
- metadata +2 -50
- data/.devcontainer/devcontainer.json +0 -22
- data/.github/workflows/development.yml +0 -49
- data/.gitignore +0 -11
- data/.rspec +0 -1
- data/Gemfile +0 -22
- data/Rakefile +0 -18
- data/httpi.gemspec +0 -40
- data/spec/fixtures/attachment.gif +0 -0
- data/spec/fixtures/client_cert.pem +0 -20
- data/spec/fixtures/client_key.pem +0 -27
- data/spec/fixtures/xml.gz +0 -0
- data/spec/fixtures/xml.xml +0 -10
- data/spec/fixtures/xml_dime.dime +0 -0
- data/spec/fixtures/xml_dime.xml +0 -1
- data/spec/httpi/adapter/base_spec.rb +0 -23
- data/spec/httpi/adapter/curb_spec.rb +0 -351
- data/spec/httpi/adapter/em_http_spec.rb +0 -180
- data/spec/httpi/adapter/excon_spec.rb +0 -34
- data/spec/httpi/adapter/http_spec.rb +0 -28
- data/spec/httpi/adapter/httpclient_spec.rb +0 -238
- data/spec/httpi/adapter/net_http_persistent_spec.rb +0 -46
- data/spec/httpi/adapter/net_http_spec.rb +0 -54
- data/spec/httpi/adapter/rack_spec.rb +0 -109
- data/spec/httpi/adapter_spec.rb +0 -68
- data/spec/httpi/auth/config_spec.rb +0 -163
- data/spec/httpi/auth/ssl_spec.rb +0 -216
- data/spec/httpi/cookie_spec.rb +0 -36
- data/spec/httpi/cookie_store_spec.rb +0 -26
- data/spec/httpi/error_spec.rb +0 -43
- data/spec/httpi/httpi_spec.rb +0 -382
- data/spec/httpi/request_spec.rb +0 -290
- data/spec/httpi/response_spec.rb +0 -146
- data/spec/integration/curb_spec.rb +0 -140
- data/spec/integration/em_http_spec.rb +0 -108
- data/spec/integration/excon_spec.rb +0 -174
- data/spec/integration/fixtures/ca_all.pem +0 -19
- data/spec/integration/fixtures/server.cert +0 -19
- data/spec/integration/fixtures/server.key +0 -27
- data/spec/integration/http_spec.rb +0 -156
- data/spec/integration/httpclient_spec.rb +0 -137
- data/spec/integration/net_http_persistent_spec.rb +0 -171
- data/spec/integration/net_http_spec.rb +0 -282
- data/spec/integration/support/application.rb +0 -88
- data/spec/integration/support/server.rb +0 -83
- data/spec/spec_helper.rb +0 -23
- data/spec/support/error_helper.rb +0 -26
- data/spec/support/fixture.rb +0 -27
- data/spec/support/matchers.rb +0 -19
@@ -1,351 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "httpi/adapter/curb"
|
3
|
-
require "httpi/request"
|
4
|
-
|
5
|
-
require "integration/support/server"
|
6
|
-
|
7
|
-
# curb does not run on jruby
|
8
|
-
unless RUBY_PLATFORM =~ /java/
|
9
|
-
HTTPI::Adapter.load_adapter(:curb)
|
10
|
-
|
11
|
-
describe "NTLM authentication" do
|
12
|
-
before :all do
|
13
|
-
@server = IntegrationServer.run
|
14
|
-
end
|
15
|
-
|
16
|
-
after :all do
|
17
|
-
@server.stop
|
18
|
-
end
|
19
|
-
|
20
|
-
it "supports ntlm authentication" do
|
21
|
-
request = HTTPI::Request.new(@server.url + "ntlm-auth")
|
22
|
-
adapter = HTTPI::Adapter::Curb.new(request)
|
23
|
-
|
24
|
-
request.auth.ntlm("tester", "vReqSoafRe5O")
|
25
|
-
expect(adapter.request(:get).body).to eq("ntlm-auth")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe HTTPI::Adapter::Curb do
|
30
|
-
|
31
|
-
let(:adapter) { HTTPI::Adapter::Curb.new(request) }
|
32
|
-
let(:curb) { Curl::Easy.any_instance }
|
33
|
-
let(:request) { HTTPI::Request.new("http://example.com") }
|
34
|
-
|
35
|
-
describe "#request(:get)" do
|
36
|
-
before do
|
37
|
-
curb.expects(:http_get)
|
38
|
-
curb.expects(:response_code).returns(200)
|
39
|
-
curb.expects(:header_str).returns("Accept-encoding: utf-8")
|
40
|
-
curb.expects(:body_str).returns(Fixture.xml)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "returns a valid HTTPI::Response" do
|
44
|
-
expect(adapter.request(:get)).to match_response(:body => Fixture.xml)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#request(:post)" do
|
49
|
-
before do
|
50
|
-
curb.expects(:http_post)
|
51
|
-
curb.expects(:response_code).returns(200)
|
52
|
-
curb.expects(:header_str).returns("Accept-encoding: utf-8")
|
53
|
-
curb.expects(:body_str).returns(Fixture.xml)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns a valid HTTPI::Response" do
|
57
|
-
expect(adapter.request(:post)).to match_response(:body => Fixture.xml)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#request(:post)" do
|
62
|
-
it "sends the body in the request" do
|
63
|
-
curb.expects(:http_post).with("xml=hi&name=123")
|
64
|
-
|
65
|
-
request.body = "xml=hi&name=123"
|
66
|
-
adapter.request(:post)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#request(:head)" do
|
71
|
-
before do
|
72
|
-
curb.expects(:http_head)
|
73
|
-
curb.expects(:response_code).returns(200)
|
74
|
-
curb.expects(:header_str).returns("Accept-encoding: utf-8")
|
75
|
-
curb.expects(:body_str).returns(Fixture.xml)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "returns a valid HTTPI::Response" do
|
79
|
-
expect(adapter.request(:head)).to match_response(:body => Fixture.xml)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "#request(:put)" do
|
84
|
-
before do
|
85
|
-
curb.expects(:http_put)
|
86
|
-
curb.expects(:response_code).returns(200)
|
87
|
-
curb.expects(:header_str).returns("Accept-encoding: utf-8")
|
88
|
-
curb.expects(:body_str).returns(Fixture.xml)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "returns a valid HTTPI::Response" do
|
92
|
-
expect(adapter.request(:put)).to match_response(:body => Fixture.xml)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "#request(:put)" do
|
97
|
-
it "sends the body in the request" do
|
98
|
-
curb.expects(:http_put).with('xml=hi&name=123')
|
99
|
-
|
100
|
-
request.body = 'xml=hi&name=123'
|
101
|
-
adapter.request(:put)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "#request(:delete)" do
|
106
|
-
before do
|
107
|
-
curb.expects(:http_delete)
|
108
|
-
curb.expects(:response_code).returns(200)
|
109
|
-
curb.expects(:header_str).returns("Accept-encoding: utf-8")
|
110
|
-
curb.expects(:body_str).returns("")
|
111
|
-
end
|
112
|
-
|
113
|
-
it "returns a valid HTTPI::Response" do
|
114
|
-
expect(adapter.request(:delete)).to match_response(:body => "")
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "#request(:custom)" do
|
119
|
-
it "raises a NotSupportedError" do
|
120
|
-
expect { adapter.request(:custom) }.
|
121
|
-
to raise_error(HTTPI::NotSupportedError, "Curb does not support custom HTTP methods")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "settings:" do
|
126
|
-
before { curb.stubs(:http_get) }
|
127
|
-
|
128
|
-
describe "url" do
|
129
|
-
it "always sets the request url" do
|
130
|
-
curb.expects(:url=).with(request.url.to_s)
|
131
|
-
adapter.request(:get)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "proxy_url" do
|
136
|
-
it "is not set unless it's specified" do
|
137
|
-
curb.expects(:proxy_url=).never
|
138
|
-
adapter.request(:get)
|
139
|
-
end
|
140
|
-
|
141
|
-
it "is set if specified" do
|
142
|
-
request.proxy = "http://proxy.example.com"
|
143
|
-
curb.expects(:proxy_url=).with(request.proxy.to_s)
|
144
|
-
|
145
|
-
adapter.request(:get)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "timeout_ms" do
|
150
|
-
it "is not set unless it's specified" do
|
151
|
-
curb.expects(:timeout_ms=).never
|
152
|
-
adapter.request(:get)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "is set if specified read_timeout" do
|
156
|
-
request.read_timeout = 30
|
157
|
-
curb.expects(:timeout_ms=).with(30_000)
|
158
|
-
|
159
|
-
adapter.request(:get)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "is set if specified write_timeout" do
|
163
|
-
request.write_timeout = 30
|
164
|
-
curb.expects(:timeout_ms=).with(30_000)
|
165
|
-
|
166
|
-
adapter.request(:get)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "connect_timeout_ms" do
|
171
|
-
it "is not set unless it's specified" do
|
172
|
-
curb.expects(:connect_timeout_ms=).never
|
173
|
-
adapter.request(:get)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "is set if specified" do
|
177
|
-
request.open_timeout = 30
|
178
|
-
curb.expects(:connect_timeout_ms=).with(30_000)
|
179
|
-
|
180
|
-
adapter.request(:get)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "headers" do
|
185
|
-
it "is always set" do
|
186
|
-
curb.expects(:headers=).with({})
|
187
|
-
adapter.request(:get)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "verbose" do
|
192
|
-
it "is always set to false" do
|
193
|
-
curb.expects(:verbose=).with(false)
|
194
|
-
adapter.request(:get)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
describe "http_auth_types" do
|
199
|
-
it "is set to :basic for HTTP basic auth" do
|
200
|
-
request.auth.basic "username", "password"
|
201
|
-
curb.expects(:http_auth_types=).with(:basic)
|
202
|
-
|
203
|
-
adapter.request(:get)
|
204
|
-
end
|
205
|
-
|
206
|
-
it "is set to :digest for HTTP digest auth" do
|
207
|
-
request.auth.digest "username", "password"
|
208
|
-
curb.expects(:http_auth_types=).with(:digest)
|
209
|
-
|
210
|
-
adapter.request(:get)
|
211
|
-
end
|
212
|
-
|
213
|
-
it "is set to :gssnegotiate for HTTP Negotiate auth" do
|
214
|
-
request.auth.gssnegotiate
|
215
|
-
curb.expects(:http_auth_types=).with(:gssnegotiate)
|
216
|
-
|
217
|
-
adapter.request(:get)
|
218
|
-
end
|
219
|
-
|
220
|
-
it "is set to :ntlm for HTTP NTLM auth" do
|
221
|
-
request.auth.ntlm("tester", "vReqSoafRe5O")
|
222
|
-
curb.expects(:http_auth_types=).with(:ntlm)
|
223
|
-
|
224
|
-
adapter.request(:get)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe "username and password" do
|
229
|
-
it "is set for HTTP basic auth" do
|
230
|
-
request.auth.basic "username", "password"
|
231
|
-
|
232
|
-
curb.expects(:username=).with("username")
|
233
|
-
curb.expects(:password=).with("password")
|
234
|
-
adapter.request(:get)
|
235
|
-
end
|
236
|
-
|
237
|
-
it "is set for HTTP digest auth" do
|
238
|
-
request.auth.digest "username", "password"
|
239
|
-
|
240
|
-
curb.expects(:username=).with("username")
|
241
|
-
curb.expects(:password=).with("password")
|
242
|
-
adapter.request(:get)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
context "(for SSL without auth)" do
|
247
|
-
let(:request) do
|
248
|
-
request = HTTPI::Request.new("http://example.com")
|
249
|
-
request.ssl = true
|
250
|
-
request
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'sets ssl_cipher_list' do
|
254
|
-
request.auth.ssl.ciphers = ["AES128"]
|
255
|
-
curb.expects(:set).with(any_parameters).at_least(1)
|
256
|
-
curb.expects(:set).with(:ssl_cipher_list, anything)
|
257
|
-
adapter.request(:get)
|
258
|
-
end
|
259
|
-
|
260
|
-
context 'sets ssl_version' do
|
261
|
-
it 'defaults to nil when no ssl_version is specified' do
|
262
|
-
curb.expects(:ssl_version=).with(nil)
|
263
|
-
adapter.request(:get)
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'to 1 when ssl_version is specified as TLSv1' do
|
267
|
-
request.auth.ssl.ssl_version = :TLSv1
|
268
|
-
curb.expects(:ssl_version=).with(1)
|
269
|
-
|
270
|
-
adapter.request(:get)
|
271
|
-
end
|
272
|
-
|
273
|
-
it 'to 2 when ssl_version is specified as SSLv2/SSLv23' do
|
274
|
-
version = HTTPI::Auth::SSL::SSL_VERSIONS.select { |method| method.to_s.match(/SSLv2|SSLv23/) }.first
|
275
|
-
request.auth.ssl.ssl_version = version
|
276
|
-
curb.expects(:ssl_version=).with(2)
|
277
|
-
|
278
|
-
adapter.request(:get)
|
279
|
-
end
|
280
|
-
|
281
|
-
it 'to 3 when ssl_version is specified as SSLv3' do
|
282
|
-
request.auth.ssl.ssl_version = :SSLv3
|
283
|
-
curb.expects(:ssl_version=).with(3)
|
284
|
-
|
285
|
-
adapter.request(:get)
|
286
|
-
end
|
287
|
-
end
|
288
|
-
it 'raises error when min_version not nil' do
|
289
|
-
request.auth.ssl.min_version = :TLS1_2
|
290
|
-
expect{ adapter.request(:get) }.
|
291
|
-
to raise_error(HTTPI::NotSupportedError, 'Curb adapter does not support #min_version or #max_version. Please, use #ssl_version instead.')
|
292
|
-
end
|
293
|
-
it 'raises error when max_version not nil' do
|
294
|
-
request.auth.ssl.max_version = :TLS1_2
|
295
|
-
expect{ adapter.request(:get) }.
|
296
|
-
to raise_error(HTTPI::NotSupportedError, 'Curb adapter does not support #min_version or #max_version. Please, use #ssl_version instead.')
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
context "(for SSL client auth)" do
|
301
|
-
let(:request) do
|
302
|
-
request = HTTPI::Request.new("http://example.com")
|
303
|
-
request.auth.ssl.cert_key_file = "spec/fixtures/client_key.pem"
|
304
|
-
request.auth.ssl.cert_file = "spec/fixtures/client_cert.pem"
|
305
|
-
request.auth.ssl.cert_key_password = 'example'
|
306
|
-
request
|
307
|
-
end
|
308
|
-
|
309
|
-
it "send certificate regardless of state of SSL verify mode" do
|
310
|
-
request.auth.ssl.verify_mode = :none
|
311
|
-
curb.expects(:ssl_verify_host=).with(0) # avoid "SSL peer certificate" error
|
312
|
-
curb.expects(:cert_key=).with(request.auth.ssl.cert_key_file)
|
313
|
-
curb.expects(:cert=).with(request.auth.ssl.cert_file)
|
314
|
-
curb.expects(:certpassword=).with(request.auth.ssl.cert_key_password)
|
315
|
-
|
316
|
-
adapter.request(:get)
|
317
|
-
end
|
318
|
-
|
319
|
-
it "cert_key, cert and ssl_verify_peer should be set" do
|
320
|
-
curb.expects(:cert_key=).with(request.auth.ssl.cert_key_file)
|
321
|
-
curb.expects(:cert=).with(request.auth.ssl.cert_file)
|
322
|
-
curb.expects(:certpassword=).with(request.auth.ssl.cert_key_password)
|
323
|
-
curb.expects(:ssl_verify_peer=).with(true)
|
324
|
-
curb.expects(:certtype=).with(request.auth.ssl.cert_type.to_s.upcase)
|
325
|
-
|
326
|
-
adapter.request(:get)
|
327
|
-
end
|
328
|
-
|
329
|
-
it "sets the cert_type to DER if specified" do
|
330
|
-
request.auth.ssl.cert_type = :der
|
331
|
-
curb.expects(:certtype=).with(:der.to_s.upcase)
|
332
|
-
|
333
|
-
adapter.request(:get)
|
334
|
-
end
|
335
|
-
|
336
|
-
it "raise if an invalid cert type was set" do
|
337
|
-
expect { request.auth.ssl.cert_type = :invalid }.
|
338
|
-
to raise_error(ArgumentError, "Invalid SSL cert type :invalid\nPlease specify one of [:pem, :der]")
|
339
|
-
end
|
340
|
-
|
341
|
-
it "sets the cacert if specified" do
|
342
|
-
request.auth.ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
|
343
|
-
curb.expects(:cacert=).with(request.auth.ssl.ca_cert_file)
|
344
|
-
|
345
|
-
adapter.request(:get)
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
end
|
351
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "httpi/adapter/em_http"
|
3
|
-
require "httpi/request"
|
4
|
-
|
5
|
-
unless RUBY_PLATFORM =~ /java/
|
6
|
-
HTTPI::Adapter.load_adapter(:em_http)
|
7
|
-
|
8
|
-
describe HTTPI::Adapter::EmHttpRequest do
|
9
|
-
|
10
|
-
around(:each) do |example|
|
11
|
-
EM.synchrony do
|
12
|
-
example.run
|
13
|
-
EM.stop
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:adapter) { HTTPI::Adapter::EmHttpRequest.new(request) }
|
18
|
-
let(:em_http) { EventMachine::HttpConnection.any_instance }
|
19
|
-
let(:request) { HTTPI::Request.new("http://example.com") }
|
20
|
-
|
21
|
-
describe "#request(:get)" do
|
22
|
-
it "returns a valid HTTPI::Response" do
|
23
|
-
em_http.expects(:get).
|
24
|
-
with(:query => nil, :head => {}, :body => nil).
|
25
|
-
returns(http_message)
|
26
|
-
|
27
|
-
expect(adapter.request(:get)).to match_response(:body => Fixture.xml)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#request(:post)" do
|
32
|
-
it "returns a valid HTTPI::Response" do
|
33
|
-
em_http.expects(:post).
|
34
|
-
with(:query => nil, :head => {}, :body => Fixture.xml).
|
35
|
-
returns(http_message)
|
36
|
-
|
37
|
-
request.body = Fixture.xml
|
38
|
-
expect(adapter.request(:post)).to match_response(:body => Fixture.xml)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#request(:head)" do
|
43
|
-
it "returns a valid HTTPI::Response" do
|
44
|
-
em_http.expects(:head).
|
45
|
-
with(:query => nil, :head => {}, :body => nil).
|
46
|
-
returns(http_message)
|
47
|
-
|
48
|
-
expect(adapter.request(:head)).to match_response(:body => Fixture.xml)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "#request(:put)" do
|
53
|
-
it "returns a valid HTTPI::Response" do
|
54
|
-
em_http.expects(:put).
|
55
|
-
with(:query => nil, :head => {}, :body => Fixture.xml).
|
56
|
-
returns(http_message)
|
57
|
-
|
58
|
-
request.body = Fixture.xml
|
59
|
-
expect(adapter.request(:put)).to match_response(:body => Fixture.xml)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#request(:delete)" do
|
64
|
-
it "returns a valid HTTPI::Response" do
|
65
|
-
em_http.expects(:delete).
|
66
|
-
with(:query => nil, :head => {}, :body => nil).
|
67
|
-
returns(http_message(""))
|
68
|
-
|
69
|
-
expect(adapter.request(:delete)).to match_response(:body => "")
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#request(:custom)" do
|
74
|
-
it "returns a valid HTTPI::Response" do
|
75
|
-
em_http.expects(:custom).
|
76
|
-
with(:query => nil, :head => {}, :body => nil).
|
77
|
-
returns(http_message(""))
|
78
|
-
|
79
|
-
expect(adapter.request(:custom)).to match_response(:body => "")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "settings:" do
|
84
|
-
describe "proxy" do
|
85
|
-
before do
|
86
|
-
request.proxy = "http://proxy-host.com:443"
|
87
|
-
request.proxy.user = "username"
|
88
|
-
request.proxy.password = "password"
|
89
|
-
end
|
90
|
-
|
91
|
-
it "sets host, port and authorization" do
|
92
|
-
url = "http://example.com:80"
|
93
|
-
connection_options = {
|
94
|
-
:proxy => {
|
95
|
-
:host => "proxy-host.com",
|
96
|
-
:port => 443,
|
97
|
-
:authorization => ["username", "password"]
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
EventMachine::HttpRequest.expects(:new).with(url, connection_options)
|
102
|
-
|
103
|
-
adapter
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "connect_timeout" do
|
108
|
-
it "is passed as a connection option" do
|
109
|
-
request.open_timeout = 30
|
110
|
-
|
111
|
-
url = "http://example.com:80"
|
112
|
-
connection_options = { connect_timeout: 30 }
|
113
|
-
|
114
|
-
EventMachine::HttpRequest.expects(:new).with(url, connection_options)
|
115
|
-
|
116
|
-
adapter
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "receive_timeout" do
|
121
|
-
it "is passed as a connection option (when read_timeout specified)" do
|
122
|
-
request.read_timeout = 60
|
123
|
-
|
124
|
-
url = "http://example.com:80"
|
125
|
-
connection_options = { inactivity_timeout: 60 }
|
126
|
-
|
127
|
-
EventMachine::HttpRequest.expects(:new).with(url, connection_options)
|
128
|
-
|
129
|
-
adapter
|
130
|
-
end
|
131
|
-
|
132
|
-
it "is passed as a connection option (when write_timeout specified)" do
|
133
|
-
request.write_timeout = 60
|
134
|
-
|
135
|
-
url = "http://example.com:80"
|
136
|
-
connection_options = { inactivity_timeout: 60 }
|
137
|
-
|
138
|
-
EventMachine::HttpRequest.expects(:new).with(url, connection_options)
|
139
|
-
|
140
|
-
adapter
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe "set_auth" do
|
145
|
-
it "is set for HTTP basic auth" do
|
146
|
-
request.auth.basic "username", "password"
|
147
|
-
em_http.expects(:get).once.with(has_entries(:head => { :authorization => %w( username password) })).returns(http_message)
|
148
|
-
adapter.request(:get)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "raises an error for HTTP digest auth" do
|
152
|
-
request.auth.digest "username", "password"
|
153
|
-
expect { adapter.request(:get) }.to raise_error HTTPI::NotSupportedError
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context "(for SSL client auth)" do
|
158
|
-
before do
|
159
|
-
request.auth.ssl.cert_key_file = "spec/fixtures/client_key.pem"
|
160
|
-
request.auth.ssl.cert_file = "spec/fixtures/client_cert.pem"
|
161
|
-
end
|
162
|
-
|
163
|
-
it "is not supported" do
|
164
|
-
expect { adapter.request(:get) }.
|
165
|
-
to raise_error(HTTPI::NotSupportedError, "EM-HTTP-Request does not support SSL client auth")
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def http_message(body = Fixture.xml)
|
171
|
-
message = EventMachine::HttpClient.new("http://example.com", {})
|
172
|
-
message.instance_variable_set :@response, body
|
173
|
-
message.instance_variable_set :@response_header, EventMachine::HttpResponseHeader.new
|
174
|
-
message.response_header['Accept-encoding'] = 'utf-8'
|
175
|
-
message.response_header.http_status = '200'
|
176
|
-
message
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
180
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "httpi/adapter/excon"
|
3
|
-
require "httpi/request"
|
4
|
-
|
5
|
-
begin
|
6
|
-
HTTPI::Adapter.load_adapter(:excon)
|
7
|
-
|
8
|
-
describe HTTPI::Adapter::Excon do
|
9
|
-
let(:adapter) { HTTPI::Adapter::Excon.new(request) }
|
10
|
-
let(:request) { HTTPI::Request.new("http://example.com") }
|
11
|
-
|
12
|
-
describe "settings" do
|
13
|
-
describe "connect_timeout, read_timeout, write_timeout" do
|
14
|
-
it "are passed as connection options" do
|
15
|
-
request.open_timeout = 30
|
16
|
-
request.read_timeout = 40
|
17
|
-
request.write_timeout = 50
|
18
|
-
|
19
|
-
expect(adapter.client.data).to include(
|
20
|
-
connect_timeout: 30,
|
21
|
-
read_timeout: 40,
|
22
|
-
write_timeout: 50
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
describe "host, hostname" do
|
27
|
-
it "both are set" do
|
28
|
-
Excon.expects(:display_warning).never
|
29
|
-
expect(adapter.client.data).to include(host: 'example.com', hostname: 'example.com')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "httpi/adapter/http"
|
3
|
-
require "httpi/request"
|
4
|
-
|
5
|
-
begin
|
6
|
-
HTTPI::Adapter.load_adapter(:http)
|
7
|
-
|
8
|
-
describe HTTPI::Adapter::HTTP do
|
9
|
-
let(:adapter) { HTTPI::Adapter::HTTP.new(request) }
|
10
|
-
let(:request) { HTTPI::Request.new("http://example.com") }
|
11
|
-
|
12
|
-
describe "settings" do
|
13
|
-
describe "connect_timeout, read_timeout, write_timeout" do
|
14
|
-
it "are being set on the client" do
|
15
|
-
request.open_timeout = 30
|
16
|
-
request.read_timeout = 40
|
17
|
-
request.write_timeout = 50
|
18
|
-
|
19
|
-
expect(adapter.client.default_options.timeout_options).to eq(
|
20
|
-
connect_timeout: 30,
|
21
|
-
read_timeout: 40,
|
22
|
-
write_timeout: 50
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|