httpi 4.0.3 → 4.0.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 +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
data/spec/httpi/request_spec.rb
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "httpi/request"
|
3
|
-
|
4
|
-
describe HTTPI::Request do
|
5
|
-
let(:request) { HTTPI::Request.new }
|
6
|
-
|
7
|
-
describe ".new" do
|
8
|
-
it "accepts a url" do
|
9
|
-
request = HTTPI::Request.new "http://example.com"
|
10
|
-
expect(request.url).to eq(URI("http://example.com"))
|
11
|
-
end
|
12
|
-
|
13
|
-
it "accepts a Hash of accessors to set" do
|
14
|
-
request = HTTPI::Request.new :url => "http://example.com", :open_timeout => 30, :query => { key: "value" }
|
15
|
-
expect(request.url).to eq(URI("http://example.com?key=value"))
|
16
|
-
expect(request.open_timeout).to eq(30)
|
17
|
-
expect(request.query).to eq("key=value")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#url" do
|
22
|
-
it "lets you specify the URL to access as a String" do
|
23
|
-
request.url = "http://example.com"
|
24
|
-
expect(request.url).to eq(URI("http://example.com"))
|
25
|
-
end
|
26
|
-
|
27
|
-
it "also accepts a URI object" do
|
28
|
-
request.url = URI("http://example.com")
|
29
|
-
expect(request.url).to eq(URI("http://example.com"))
|
30
|
-
end
|
31
|
-
|
32
|
-
it "raises an ArgumentError in case of an invalid url" do
|
33
|
-
expect { request.url = "invalid" }.to raise_error(ArgumentError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "uses username and password as basic authentication if present in the URL" do
|
37
|
-
request.url = "http://username:password@example.com"
|
38
|
-
expect(request.auth.basic).to eq(['username', 'password'])
|
39
|
-
end
|
40
|
-
|
41
|
-
it "uses a blank password if only username is specified in the URL" do
|
42
|
-
request.url = "http://username@example.com"
|
43
|
-
expect(request.auth.basic).to eq(['username', ''])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#query" do
|
48
|
-
it "raises an ArgumentError if url not respond to query" do
|
49
|
-
expect { request.query = "q=query" }.to raise_error(ArgumentError)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "getter return nil for invalid url" do
|
53
|
-
expect(request.query).to be_nil
|
54
|
-
end
|
55
|
-
|
56
|
-
context "with query parameter as String" do
|
57
|
-
it "lets you specify query parameter as String" do
|
58
|
-
request.url = "http://example.com"
|
59
|
-
request.query = "q=query"
|
60
|
-
expect(request.url.to_s).to eq("http://example.com?q=query")
|
61
|
-
end
|
62
|
-
|
63
|
-
it "getter return String for query parameter as String" do
|
64
|
-
request.url = "http://example.com"
|
65
|
-
request.query = "q=query"
|
66
|
-
expect(request.query).to eq("q=query")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with query parameter as Hash" do
|
71
|
-
context "with flat query builder" do
|
72
|
-
before do
|
73
|
-
request.url = "http://example.com"
|
74
|
-
request.query = {:q => ["nested", "query"]}
|
75
|
-
end
|
76
|
-
|
77
|
-
it "lets you specify query parameter as Hash" do
|
78
|
-
expect(request.url.to_s).to eq("http://example.com?q=nested&q=query")
|
79
|
-
end
|
80
|
-
|
81
|
-
it "getter return String for query parameter as Hash" do
|
82
|
-
expect(request.query).to eq("q=nested&q=query")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
context "with nested query builder" do
|
86
|
-
before do
|
87
|
-
HTTPI.query_builder = :nested
|
88
|
-
|
89
|
-
request.url = "http://example.com"
|
90
|
-
request.query = {:q => ["nested", "query"]}
|
91
|
-
end
|
92
|
-
after { HTTPI.query_builder = :flat }
|
93
|
-
|
94
|
-
it "lets you specify query parameter as Hash" do
|
95
|
-
expect(request.url.to_s).to eq("http://example.com?q%5B%5D=nested&q%5B%5D=query")
|
96
|
-
end
|
97
|
-
|
98
|
-
it "getter return String for query parameter as Hash" do
|
99
|
-
expect(request.query).to eq("q%5B%5D=nested&q%5B%5D=query")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "#proxy" do
|
106
|
-
it "lets you specify the proxy URL to use as a String" do
|
107
|
-
request.proxy = "http://proxy.example.com"
|
108
|
-
expect(request.proxy).to eq(URI("http://proxy.example.com"))
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'also accepts the socks URL to use as a String' do
|
112
|
-
request.proxy ="socks://socks.example.com"
|
113
|
-
expect(request.proxy).to eq(URI("socks://socks.example.com"))
|
114
|
-
end
|
115
|
-
|
116
|
-
it "also accepts a URI object" do
|
117
|
-
request.proxy = URI("http://proxy.example.com")
|
118
|
-
expect(request.proxy).to eq(URI("http://proxy.example.com"))
|
119
|
-
end
|
120
|
-
|
121
|
-
it "raises an ArgumentError in case of an invalid url" do
|
122
|
-
expect { request.proxy = "invalid" }.to raise_error(ArgumentError)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "#ssl" do
|
127
|
-
it "returns false if no request url was specified" do
|
128
|
-
expect(request).not_to be_ssl
|
129
|
-
end
|
130
|
-
|
131
|
-
it "returns false if the request url does not start with https" do
|
132
|
-
request.url = "http://example.com"
|
133
|
-
expect(request).not_to be_ssl
|
134
|
-
end
|
135
|
-
|
136
|
-
it "returns true if the request url starts with https" do
|
137
|
-
request.url = "https://example.com"
|
138
|
-
expect(request).to be_ssl
|
139
|
-
end
|
140
|
-
|
141
|
-
context "with an explicit value" do
|
142
|
-
it "returns the value" do
|
143
|
-
request.ssl = true
|
144
|
-
expect(request).to be_ssl
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "#headers" do
|
150
|
-
it "lets you specify a Hash of HTTP request headers" do
|
151
|
-
request.headers = { "Accept-Encoding" => "gzip" }
|
152
|
-
expect(request.headers).to eq HTTPI::Utils::Headers.new.merge({ "Accept-Encoding" => "gzip" })
|
153
|
-
end
|
154
|
-
|
155
|
-
it "defaults to return an empty Hash" do
|
156
|
-
expect(request.headers).to eq({})
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "#gzip" do
|
161
|
-
it "adds the proper 'Accept-Encoding' header" do
|
162
|
-
request.gzip
|
163
|
-
expect(request.headers["Accept-Encoding"]).to eq("gzip,deflate")
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "#set_cookies" do
|
168
|
-
it "sets the cookie header for the next request" do
|
169
|
-
request.set_cookies response_with_cookie("some-cookie=choc-chip")
|
170
|
-
expect(request.headers["Cookie"]).to eq("some-cookie=choc-chip")
|
171
|
-
end
|
172
|
-
|
173
|
-
it "sets additional cookies from subsequent requests" do
|
174
|
-
request.set_cookies response_with_cookie("some-cookie=choc-chip")
|
175
|
-
request.set_cookies response_with_cookie("second-cookie=oatmeal")
|
176
|
-
|
177
|
-
expect(request.headers["Cookie"]).to include("some-cookie=choc-chip", "second-cookie=oatmeal")
|
178
|
-
end
|
179
|
-
|
180
|
-
it "accepts an Array of cookies" do
|
181
|
-
cookies = [
|
182
|
-
new_cookie("some-cookie=choc-chip"),
|
183
|
-
new_cookie("second-cookie=oatmeal")
|
184
|
-
]
|
185
|
-
|
186
|
-
request.set_cookies(cookies)
|
187
|
-
|
188
|
-
expect(request.headers["Cookie"]).to include("some-cookie=choc-chip", "second-cookie=oatmeal")
|
189
|
-
end
|
190
|
-
|
191
|
-
it "doesn't do anything if the response contains no cookies" do
|
192
|
-
request.set_cookies HTTPI::Response.new(200, {}, "")
|
193
|
-
expect(request.headers).not_to include("Cookie")
|
194
|
-
end
|
195
|
-
|
196
|
-
def new_cookie(cookie_string)
|
197
|
-
HTTPI::Cookie.new(cookie_string)
|
198
|
-
end
|
199
|
-
|
200
|
-
def response_with_cookie(cookie)
|
201
|
-
HTTPI::Response.new(200, { "Set-Cookie" => "#{cookie}; Path=/; HttpOnly" }, "")
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe "#body" do
|
206
|
-
context "with query parameter as String" do
|
207
|
-
it "lets you specify the HTTP request body using a String" do
|
208
|
-
request.body = "<some>xml</some>"
|
209
|
-
expect(request.body).to eq("<some>xml</some>")
|
210
|
-
end
|
211
|
-
end
|
212
|
-
context "with flat query builder" do
|
213
|
-
it "lets you specify the HTTP request body using a Hash" do
|
214
|
-
request.body = {:foo => :bar, :baz => :foo}
|
215
|
-
expect(request.body.split("&")).to match_array(["foo=bar", "baz=foo"])
|
216
|
-
end
|
217
|
-
end
|
218
|
-
context "with query parameter as Hash" do
|
219
|
-
context "with flat query builder" do
|
220
|
-
it "request body using a Hash" do
|
221
|
-
request.body = {:foo => :bar, :baz => :foo}
|
222
|
-
expect(request.body.split("&")).to match_array(["foo=bar", "baz=foo"])
|
223
|
-
end
|
224
|
-
it "request body using a Hash with Array" do
|
225
|
-
request.body = {:foo => :bar, :baz => [:foo, :tst]}
|
226
|
-
expect(request.body.split("&")).to match_array(["foo=bar", "baz=foo", "baz=tst"])
|
227
|
-
end
|
228
|
-
end
|
229
|
-
context "with nested query builder" do
|
230
|
-
before { HTTPI.query_builder = :nested }
|
231
|
-
after { HTTPI.query_builder = :flat }
|
232
|
-
it "request body using a Hash" do
|
233
|
-
request.body = {:foo => :bar, :baz => :foo}
|
234
|
-
expect(request.body.split("&")).to match_array(["foo=bar", "baz=foo"])
|
235
|
-
end
|
236
|
-
it "request body using a Hash with Array" do
|
237
|
-
request.body = {:foo => :bar, :baz => [:foo, :tst]}
|
238
|
-
expect(request.body.split("&")).to match_array(["foo=bar", "baz%5B%5D=foo", "baz%5B%5D=tst"])
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe "#open_timeout" do
|
245
|
-
it "lets you specify the open timeout" do
|
246
|
-
request.open_timeout = 30
|
247
|
-
expect(request.open_timeout).to eq(30)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe "#read_timeout" do
|
252
|
-
it "lets you specify the read timeout" do
|
253
|
-
request.read_timeout = 45
|
254
|
-
expect(request.read_timeout).to eq(45)
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
describe "#auth" do
|
259
|
-
it "returns the authentication object" do
|
260
|
-
expect(request.auth).to be_an(HTTPI::Auth::Config)
|
261
|
-
end
|
262
|
-
|
263
|
-
it "memoizes the authentication object" do
|
264
|
-
expect(request.auth).to equal(request.auth)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
describe "#auth?" do
|
269
|
-
it "returns true when auth credentials are specified" do
|
270
|
-
request.auth.basic "username", "password"
|
271
|
-
expect(request.auth?).to be_truthy
|
272
|
-
end
|
273
|
-
|
274
|
-
it "returns false otherwise" do
|
275
|
-
expect(request.auth?).to be_falsey
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
describe '#follow_redirect?' do
|
280
|
-
it 'returns true when follow_redirect is set to true' do
|
281
|
-
request.follow_redirect = true
|
282
|
-
expect(request.follow_redirect?).to be_truthy
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'returns false by default' do
|
286
|
-
expect(request.follow_redirect?).to be_falsey
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
end
|
data/spec/httpi/response_spec.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "httpi/response"
|
3
|
-
|
4
|
-
describe HTTPI::Response do
|
5
|
-
|
6
|
-
context "normal" do
|
7
|
-
let(:response) { HTTPI::Response.new 200, {}, Fixture.xml }
|
8
|
-
|
9
|
-
describe "#error?" do
|
10
|
-
it "returns false" do
|
11
|
-
expect(response).not_to be_an_error
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#headers" do
|
16
|
-
it "returns the HTTP response headers" do
|
17
|
-
expect(response.headers).to eq({})
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#code" do
|
22
|
-
it "returns the HTTP response code" do
|
23
|
-
expect(response.code).to eq(200)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "always returns an Integer" do
|
27
|
-
response = HTTPI::Response.new "200", {}, ""
|
28
|
-
expect(response.code).to eq(200)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#multipart" do
|
33
|
-
it "returns false" do
|
34
|
-
expect(response).not_to be_multipart
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#cookies" do
|
39
|
-
it "returns an empty list" do
|
40
|
-
expect(response.cookies).to eq([])
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with cookies" do
|
46
|
-
let(:response) { HTTPI::Response.new 200, { "Set-Cookie" => "some-cookie=choc-chip; Path=/; HttpOnly" }, "" }
|
47
|
-
|
48
|
-
describe "#cookies" do
|
49
|
-
it "returns a list of cookies" do
|
50
|
-
cookie = response.cookies.first
|
51
|
-
expect(cookie).to be_a(HTTPI::Cookie)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "empty" do
|
57
|
-
let(:response) { HTTPI::Response.new 204, {}, nil }
|
58
|
-
|
59
|
-
describe "#body" do
|
60
|
-
it "returns an empty String" do
|
61
|
-
expect(response.body).to eq("")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "multipart" do
|
67
|
-
let(:response) { HTTPI::Response.new 200, { "Content-Type" => "multipart/related" }, "multipart" }
|
68
|
-
|
69
|
-
describe "#multipart" do
|
70
|
-
it "returns true" do
|
71
|
-
expect(response).to be_multipart
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "error" do
|
77
|
-
let(:response) { HTTPI::Response.new 404, {}, "" }
|
78
|
-
|
79
|
-
describe "#error?" do
|
80
|
-
it "returns true" do
|
81
|
-
expect(response).to be_an_error
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "gzipped" do
|
87
|
-
let(:response) { HTTPI::Response.new 200, { "Content-Encoding" => "gzip" }, Fixture.gzip }
|
88
|
-
|
89
|
-
describe "#headers" do
|
90
|
-
it "returns the HTTP response headers" do
|
91
|
-
expect(response.headers).to eq HTTPI::Utils::Headers.new.merge({ "Content-Encoding" => "gzip" })
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "#body" do
|
96
|
-
it "returns the (gzip decoded) HTTP response body" do
|
97
|
-
expect(response.body).to eq(Fixture.xml)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "bubbles Zlib errors" do
|
101
|
-
arbitrary_error = Class.new(ArgumentError)
|
102
|
-
Zlib::GzipReader.expects(:new).raises(arbitrary_error)
|
103
|
-
expect { response.body }.to raise_error(arbitrary_error)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "#raw_body" do
|
108
|
-
it "returns the raw HTML response body" do
|
109
|
-
expect(response.raw_body).to eq(Fixture.gzip)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context "DIME" do
|
115
|
-
let(:response) { HTTPI::Response.new 200, { "Content-Type" => "application/dime" }, Fixture.dime }
|
116
|
-
|
117
|
-
describe "#headers" do
|
118
|
-
it "returns the HTTP response headers" do
|
119
|
-
expect(response.headers).to eq HTTPI::Utils::Headers.new.merge({ "Content-Type" => "application/dime" })
|
120
|
-
end
|
121
|
-
|
122
|
-
it "preserves casing" do
|
123
|
-
expect(response.headers.keys).to eq ["Content-Type"]
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "#body" do
|
128
|
-
it "returns the (dime decoded) HTTP response body" do
|
129
|
-
expect(response.body).to eq(Fixture.xml_dime)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#raw_body" do
|
134
|
-
it "returns the raw HTML response body" do
|
135
|
-
expect(response.raw_body).to eq(Fixture.dime)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "#attachments" do
|
140
|
-
it "returns proper attachment when given a dime response" do
|
141
|
-
response.attachments.first.data == File.read(File.expand_path("../../fixtures/attachment.gif", __FILE__))
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "integration/support/server"
|
3
|
-
|
4
|
-
describe HTTPI::Adapter::Curb do
|
5
|
-
|
6
|
-
# curb is not supported on jruby
|
7
|
-
unless RUBY_PLATFORM =~ /java/
|
8
|
-
|
9
|
-
subject(:adapter) { :curb }
|
10
|
-
|
11
|
-
context "http requests" do
|
12
|
-
before :all do
|
13
|
-
@server = IntegrationServer.run
|
14
|
-
end
|
15
|
-
|
16
|
-
after :all do
|
17
|
-
@server.stop
|
18
|
-
end
|
19
|
-
|
20
|
-
it "sends and receives HTTP headers" do
|
21
|
-
request = HTTPI::Request.new(@server.url + "x-header")
|
22
|
-
request.headers["X-Header"] = "HTTPI"
|
23
|
-
|
24
|
-
response = HTTPI.get(request, adapter)
|
25
|
-
expect(response.body).to include("HTTPI")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "it supports headers with multiple values" do
|
29
|
-
request = HTTPI::Request.new(@server.url + "cookies")
|
30
|
-
|
31
|
-
response = HTTPI.get(request, adapter)
|
32
|
-
cookies = ["cookie1=chip1; path=/", "cookie2=chip2; path=/"]
|
33
|
-
expect(response.headers["Set-Cookie"]).to eq(cookies)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "it supports read timeout" do
|
37
|
-
require "curb"
|
38
|
-
|
39
|
-
request = HTTPI::Request.new(@server.url + "timeout")
|
40
|
-
request.read_timeout = 0.5 # seconds
|
41
|
-
|
42
|
-
expect do
|
43
|
-
HTTPI.get(request, adapter)
|
44
|
-
end.to raise_exception(Curl::Err::TimeoutError)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "executes GET requests" do
|
48
|
-
response = HTTPI.get(@server.url, adapter)
|
49
|
-
expect(response.body).to eq("get")
|
50
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
51
|
-
end
|
52
|
-
|
53
|
-
it "executes POST requests" do
|
54
|
-
response = HTTPI.post(@server.url, "<some>xml</some>", adapter)
|
55
|
-
expect(response.body).to eq("post")
|
56
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
57
|
-
end
|
58
|
-
|
59
|
-
it "executes HEAD requests" do
|
60
|
-
response = HTTPI.head(@server.url, adapter)
|
61
|
-
expect(response.code).to eq(200)
|
62
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
63
|
-
end
|
64
|
-
|
65
|
-
it "executes PUT requests" do
|
66
|
-
response = HTTPI.put(@server.url, "<some>xml</some>", adapter)
|
67
|
-
expect(response.body).to eq("put")
|
68
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
69
|
-
end
|
70
|
-
|
71
|
-
it "executes DELETE requests" do
|
72
|
-
response = HTTPI.delete(@server.url, adapter)
|
73
|
-
expect(response.body).to eq("delete")
|
74
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
75
|
-
end
|
76
|
-
|
77
|
-
it "supports basic authentication" do
|
78
|
-
request = HTTPI::Request.new(@server.url + "basic-auth")
|
79
|
-
request.auth.basic("admin", "secret")
|
80
|
-
|
81
|
-
response = HTTPI.get(request, adapter)
|
82
|
-
expect(response.body).to eq("basic-auth")
|
83
|
-
end
|
84
|
-
|
85
|
-
# Rack::Auth::Digest is removed in Rack 3.1
|
86
|
-
xit "supports digest authentication" do
|
87
|
-
request = HTTPI::Request.new(@server.url + "digest-auth")
|
88
|
-
request.auth.digest("admin", "secret")
|
89
|
-
|
90
|
-
response = HTTPI.get(request, adapter)
|
91
|
-
expect(response.body).to eq("digest-auth")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "supports chunked response" do
|
95
|
-
request = HTTPI::Request.new(@server.url)
|
96
|
-
res = ""
|
97
|
-
request.on_body do |body|
|
98
|
-
res += body
|
99
|
-
end
|
100
|
-
response = HTTPI.post(request, adapter)
|
101
|
-
expect(res).to eq("post")
|
102
|
-
expect(response.body).to eq("")
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
context "https requests" do
|
108
|
-
before :all do
|
109
|
-
@server = IntegrationServer.run(:ssl => true)
|
110
|
-
end
|
111
|
-
|
112
|
-
after :all do
|
113
|
-
@server.stop
|
114
|
-
end
|
115
|
-
|
116
|
-
it "raises when no certificate was set up" do
|
117
|
-
expect { HTTPI.post(@server.url, "", adapter) }.to raise_error(HTTPI::SSLError)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "works when set up properly" do
|
121
|
-
request = HTTPI::Request.new(@server.url)
|
122
|
-
request.auth.ssl.ca_cert_file = IntegrationServer.ssl_ca_file
|
123
|
-
|
124
|
-
response = HTTPI.get(request, adapter)
|
125
|
-
expect(response.body).to eq("get")
|
126
|
-
end
|
127
|
-
|
128
|
-
it "works with ciphers" do
|
129
|
-
request = HTTPI::Request.new(@server.url)
|
130
|
-
request.auth.ssl.ca_cert_file = IntegrationServer.ssl_ca_file
|
131
|
-
request.auth.ssl.ciphers = OpenSSL::SSL::SSLContext.new.ciphers
|
132
|
-
|
133
|
-
response = HTTPI.get(request, adapter)
|
134
|
-
expect(response.body).to eq("get")
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
@@ -1,108 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "integration/support/server"
|
3
|
-
|
4
|
-
describe HTTPI::Adapter::EmHttpRequest do
|
5
|
-
|
6
|
-
# em_http is not supported on java
|
7
|
-
unless RUBY_PLATFORM =~ /java/
|
8
|
-
require "em-synchrony"
|
9
|
-
|
10
|
-
subject(:adapter) { :em_http }
|
11
|
-
|
12
|
-
around :each do |example|
|
13
|
-
EM.synchrony do
|
14
|
-
example.run
|
15
|
-
EM.stop
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "http requests" do
|
20
|
-
before :all do
|
21
|
-
# for some reason, these specs don't work with "localhost". [dh, 2012-12-15]
|
22
|
-
@server = IntegrationServer.run(:host => "127.0.0.1")
|
23
|
-
end
|
24
|
-
|
25
|
-
after :all do
|
26
|
-
@server.stop
|
27
|
-
end
|
28
|
-
|
29
|
-
it "sends and receives HTTP headers" do
|
30
|
-
request = HTTPI::Request.new(@server.url + "x-header")
|
31
|
-
request.headers["X-Header"] = "HTTPI"
|
32
|
-
|
33
|
-
response = HTTPI.get(request, adapter)
|
34
|
-
expect(response.body).to include("HTTPI")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "it supports headers with multiple values" do
|
38
|
-
request = HTTPI::Request.new(@server.url + "cookies")
|
39
|
-
|
40
|
-
response = HTTPI.get(request, adapter)
|
41
|
-
cookies = ["cookie1=chip1; path=/", "cookie2=chip2; path=/"]
|
42
|
-
expect(response.headers["Set-Cookie"]).to eq(cookies)
|
43
|
-
end
|
44
|
-
|
45
|
-
if RUBY_PLATFORM =~ /java/
|
46
|
-
pending <<-MSG
|
47
|
-
It seems like JRuby is missing support for inactivity timeout! See related issues on GitHub:
|
48
|
-
- https://github.com/eventmachine/eventmachine/issues/155
|
49
|
-
- https://github.com/eventmachine/eventmachine/pull/312
|
50
|
-
MSG
|
51
|
-
else
|
52
|
-
it "it supports read timeout" do
|
53
|
-
request = HTTPI::Request.new(@server.url + "timeout")
|
54
|
-
request.read_timeout = 0.5 # seconds
|
55
|
-
|
56
|
-
expect do
|
57
|
-
HTTPI.get(request, adapter)
|
58
|
-
end.to raise_exception(HTTPI::TimeoutError)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "executes GET requests" do
|
63
|
-
response = HTTPI.get(@server.url, adapter)
|
64
|
-
expect(response.body).to eq("get")
|
65
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "executes POST requests" do
|
69
|
-
response = HTTPI.post(@server.url, "<some>xml</some>", adapter)
|
70
|
-
expect(response.body).to eq("post")
|
71
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
72
|
-
end
|
73
|
-
|
74
|
-
it "executes HEAD requests" do
|
75
|
-
response = HTTPI.head(@server.url, adapter)
|
76
|
-
expect(response.code).to eq(200)
|
77
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "executes PUT requests" do
|
81
|
-
response = HTTPI.put(@server.url, "<some>xml</some>", adapter)
|
82
|
-
expect(response.body).to eq("put")
|
83
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
84
|
-
end
|
85
|
-
|
86
|
-
it "executes DELETE requests" do
|
87
|
-
response = HTTPI.delete(@server.url, adapter)
|
88
|
-
expect(response.body).to eq("delete")
|
89
|
-
expect(response.headers["Content-Type"]).to eq("text/plain")
|
90
|
-
end
|
91
|
-
|
92
|
-
it "supports basic authentication" do
|
93
|
-
request = HTTPI::Request.new(@server.url + "basic-auth")
|
94
|
-
request.auth.basic("admin", "secret")
|
95
|
-
|
96
|
-
response = HTTPI.get(request, adapter)
|
97
|
-
expect(response.body).to eq("basic-auth")
|
98
|
-
end
|
99
|
-
|
100
|
-
# it does not support digest authentication
|
101
|
-
|
102
|
-
# it does not support chunked response
|
103
|
-
end
|
104
|
-
|
105
|
-
# it does not support ssl authentication
|
106
|
-
|
107
|
-
end
|
108
|
-
end
|