ethon 0.10.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +41 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +16 -1
- data/Gemfile +14 -4
- data/Guardfile +1 -0
- data/README.md +4 -1
- data/Rakefile +1 -0
- data/ethon.gemspec +2 -1
- data/lib/ethon.rb +1 -0
- data/lib/ethon/curl.rb +1 -0
- data/lib/ethon/curls/classes.rb +1 -0
- data/lib/ethon/curls/codes.rb +1 -1
- data/lib/ethon/curls/constants.rb +1 -0
- data/lib/ethon/curls/form_options.rb +1 -0
- data/lib/ethon/curls/functions.rb +4 -12
- data/lib/ethon/curls/infos.rb +4 -3
- data/lib/ethon/curls/messages.rb +1 -0
- data/lib/ethon/curls/options.rb +35 -23
- data/lib/ethon/curls/settings.rb +2 -0
- data/lib/ethon/easy.rb +3 -1
- data/lib/ethon/easy/callbacks.rb +25 -3
- data/lib/ethon/easy/debug_info.rb +1 -0
- data/lib/ethon/easy/features.rb +1 -0
- data/lib/ethon/easy/form.rb +5 -2
- data/lib/ethon/easy/header.rb +2 -7
- data/lib/ethon/easy/http.rb +1 -0
- data/lib/ethon/easy/http/actionable.rb +2 -1
- data/lib/ethon/easy/http/custom.rb +1 -0
- data/lib/ethon/easy/http/delete.rb +1 -0
- data/lib/ethon/easy/http/get.rb +1 -0
- data/lib/ethon/easy/http/head.rb +1 -0
- data/lib/ethon/easy/http/options.rb +1 -0
- data/lib/ethon/easy/http/patch.rb +1 -0
- data/lib/ethon/easy/http/post.rb +1 -0
- data/lib/ethon/easy/http/postable.rb +1 -0
- data/lib/ethon/easy/http/put.rb +1 -0
- data/lib/ethon/easy/http/putable.rb +1 -0
- data/lib/ethon/easy/informations.rb +1 -0
- data/lib/ethon/easy/mirror.rb +1 -0
- data/lib/ethon/easy/operations.rb +16 -1
- data/lib/ethon/easy/options.rb +11 -2
- data/lib/ethon/easy/params.rb +1 -0
- data/lib/ethon/easy/queryable.rb +4 -1
- data/lib/ethon/easy/response_callbacks.rb +27 -0
- data/lib/ethon/easy/util.rb +1 -0
- data/lib/ethon/errors.rb +1 -0
- data/lib/ethon/errors/ethon_error.rb +1 -0
- data/lib/ethon/errors/global_init.rb +1 -0
- data/lib/ethon/errors/invalid_option.rb +1 -0
- data/lib/ethon/errors/invalid_value.rb +1 -0
- data/lib/ethon/errors/multi_add.rb +1 -0
- data/lib/ethon/errors/multi_fdset.rb +1 -0
- data/lib/ethon/errors/multi_remove.rb +1 -0
- data/lib/ethon/errors/multi_timeout.rb +1 -0
- data/lib/ethon/errors/select.rb +1 -0
- data/lib/ethon/libc.rb +1 -0
- data/lib/ethon/loggable.rb +1 -0
- data/lib/ethon/multi.rb +1 -0
- data/lib/ethon/multi/operations.rb +1 -0
- data/lib/ethon/multi/options.rb +9 -8
- data/lib/ethon/multi/stack.rb +1 -0
- data/lib/ethon/version.rb +2 -1
- data/profile/benchmarks.rb +1 -0
- data/profile/memory_leaks.rb +1 -0
- data/profile/perf_spec_helper.rb +1 -0
- data/profile/support/memory_test_helpers.rb +1 -0
- data/profile/support/os_memory_leak_tracker.rb +1 -0
- data/profile/support/ruby_object_leak_tracker.rb +1 -0
- data/spec/ethon/curl_spec.rb +1 -0
- data/spec/ethon/easy/callbacks_spec.rb +8 -1
- data/spec/ethon/easy/debug_info_spec.rb +2 -0
- data/spec/ethon/easy/features_spec.rb +1 -0
- data/spec/ethon/easy/form_spec.rb +10 -0
- data/spec/ethon/easy/header_spec.rb +1 -30
- data/spec/ethon/easy/http/custom_spec.rb +1 -0
- data/spec/ethon/easy/http/delete_spec.rb +1 -0
- data/spec/ethon/easy/http/get_spec.rb +1 -0
- data/spec/ethon/easy/http/head_spec.rb +1 -0
- data/spec/ethon/easy/http/options_spec.rb +1 -0
- data/spec/ethon/easy/http/patch_spec.rb +1 -0
- data/spec/ethon/easy/http/post_spec.rb +1 -0
- data/spec/ethon/easy/http/put_spec.rb +1 -0
- data/spec/ethon/easy/http_spec.rb +1 -0
- data/spec/ethon/easy/informations_spec.rb +1 -0
- data/spec/ethon/easy/mirror_spec.rb +1 -0
- data/spec/ethon/easy/operations_spec.rb +1 -0
- data/spec/ethon/easy/options_spec.rb +31 -1
- data/spec/ethon/easy/queryable_spec.rb +14 -3
- data/spec/ethon/easy/response_callbacks_spec.rb +58 -1
- data/spec/ethon/easy/util_spec.rb +1 -0
- data/spec/ethon/easy_spec.rb +8 -2
- data/spec/ethon/libc_spec.rb +1 -0
- data/spec/ethon/loggable_spec.rb +1 -0
- data/spec/ethon/multi/operations_spec.rb +1 -0
- data/spec/ethon/multi/options_spec.rb +1 -0
- data/spec/ethon/multi/stack_spec.rb +1 -0
- data/spec/ethon/multi_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/localhost_server.rb +2 -1
- data/spec/support/server.rb +1 -0
- metadata +6 -7
- data/.travis.yml +0 -26
data/lib/ethon/errors/select.rb
CHANGED
data/lib/ethon/libc.rb
CHANGED
data/lib/ethon/loggable.rb
CHANGED
data/lib/ethon/multi.rb
CHANGED
data/lib/ethon/multi/options.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Ethon
|
2
3
|
class Multi
|
3
4
|
|
@@ -8,7 +9,7 @@ module Ethon
|
|
8
9
|
# Sets max_total_connections option.
|
9
10
|
#
|
10
11
|
# @example Set max_total_connections option.
|
11
|
-
#
|
12
|
+
# multi.max_total_conections = $value
|
12
13
|
#
|
13
14
|
# @param [ String ] value The value to set.
|
14
15
|
#
|
@@ -20,7 +21,7 @@ module Ethon
|
|
20
21
|
# Sets maxconnects option.
|
21
22
|
#
|
22
23
|
# @example Set maxconnects option.
|
23
|
-
#
|
24
|
+
# multi.maxconnects = $value
|
24
25
|
#
|
25
26
|
# @param [ String ] value The value to set.
|
26
27
|
#
|
@@ -32,19 +33,19 @@ module Ethon
|
|
32
33
|
# Sets pipelining option.
|
33
34
|
#
|
34
35
|
# @example Set pipelining option.
|
35
|
-
#
|
36
|
+
# multi.pipelining = $value
|
36
37
|
#
|
37
38
|
# @param [ String ] value The value to set.
|
38
39
|
#
|
39
40
|
# @return [ void ]
|
40
41
|
def pipelining=(value)
|
41
|
-
Curl.set_option(:pipelining, value_for(value, :
|
42
|
+
Curl.set_option(:pipelining, value_for(value, :int), handle, :multi)
|
42
43
|
end
|
43
44
|
|
44
45
|
# Sets socketdata option.
|
45
46
|
#
|
46
47
|
# @example Set socketdata option.
|
47
|
-
#
|
48
|
+
# multi.socketdata = $value
|
48
49
|
#
|
49
50
|
# @param [ String ] value The value to set.
|
50
51
|
#
|
@@ -56,7 +57,7 @@ module Ethon
|
|
56
57
|
# Sets socketfunction option.
|
57
58
|
#
|
58
59
|
# @example Set socketfunction option.
|
59
|
-
#
|
60
|
+
# multi.socketfunction = $value
|
60
61
|
#
|
61
62
|
# @param [ String ] value The value to set.
|
62
63
|
#
|
@@ -68,7 +69,7 @@ module Ethon
|
|
68
69
|
# Sets timerdata option.
|
69
70
|
#
|
70
71
|
# @example Set timerdata option.
|
71
|
-
#
|
72
|
+
# multi.timerdata = $value
|
72
73
|
#
|
73
74
|
# @param [ String ] value The value to set.
|
74
75
|
#
|
@@ -80,7 +81,7 @@ module Ethon
|
|
80
81
|
# Sets timerfunction option.
|
81
82
|
#
|
82
83
|
# @example Set timerfunction option.
|
83
|
-
#
|
84
|
+
# multi.timerfunction = $value
|
84
85
|
#
|
85
86
|
# @param [ String ] value The value to set.
|
86
87
|
#
|
data/lib/ethon/multi/stack.rb
CHANGED
data/lib/ethon/version.rb
CHANGED
data/profile/benchmarks.rb
CHANGED
data/profile/memory_leaks.rb
CHANGED
data/profile/perf_spec_helper.rb
CHANGED
data/spec/ethon/curl_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Ethon::Easy::Callbacks do
|
@@ -8,7 +9,7 @@ describe Ethon::Easy::Callbacks do
|
|
8
9
|
expect(Ethon::Curl).to receive(:set_option).exactly(3).times
|
9
10
|
end
|
10
11
|
|
11
|
-
it "sets write
|
12
|
+
it "sets write-, debug-, and headerfunction" do
|
12
13
|
easy.set_callbacks
|
13
14
|
end
|
14
15
|
|
@@ -28,6 +29,12 @@ describe Ethon::Easy::Callbacks do
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
32
|
+
describe "#progress_callback" do
|
33
|
+
it "returns 0" do
|
34
|
+
expect(easy.progress_callback.call(0,1,1,1,1)).to be(0)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
31
38
|
describe "#body_write_callback" do
|
32
39
|
let(:body_write_callback) { easy.instance_variable_get(:@body_write_callback) }
|
33
40
|
let(:stream) { double(:read_string => "") }
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Ethon::Easy::Form do
|
@@ -41,6 +42,15 @@ describe Ethon::Easy::Form do
|
|
41
42
|
expect(form.multipart?).to be_truthy
|
42
43
|
end
|
43
44
|
end
|
45
|
+
|
46
|
+
context "when options contains multipart=true" do
|
47
|
+
before { form.instance_variable_set(:@multipart, true) }
|
48
|
+
let(:pairs) { [['a', '1'], ['b', '2']] }
|
49
|
+
|
50
|
+
it "returns true" do
|
51
|
+
expect(form.multipart?).to be_truthy
|
52
|
+
end
|
53
|
+
end
|
44
54
|
end
|
45
55
|
|
46
56
|
describe "#materialize" do
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Ethon::Easy::Header do
|
@@ -46,36 +47,6 @@ describe Ethon::Easy::Header do
|
|
46
47
|
expect(easy.response_body).to include('"HTTP_USER_AGENT":"Ethon"')
|
47
48
|
end
|
48
49
|
end
|
49
|
-
|
50
|
-
context "when header value is empty string" do
|
51
|
-
let(:headers) { { 'User-Agent' => "" } }
|
52
|
-
|
53
|
-
if(Ethon::Curl.version_info[:version] >= "7.23.0")
|
54
|
-
it "sends header with empty value" do
|
55
|
-
expect(easy.response_body).to include('"HTTP_USER_AGENT":""')
|
56
|
-
end
|
57
|
-
else
|
58
|
-
it "does not send header (curl < 7.23.0 does not support empty values)" do
|
59
|
-
expect(easy.response_body).to_not include('"HTTP_USER_AGENT"')
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "when header value is nil" do
|
65
|
-
let(:headers) { { 'User-Agent' => nil } }
|
66
|
-
|
67
|
-
it "does not send header" do
|
68
|
-
expect(easy.response_body).to_not include('"HTTP_USER_AGENT"')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when header value is integer" do
|
73
|
-
let(:headers) { { 'User-Agent' => 0 } }
|
74
|
-
|
75
|
-
it "sends as string" do
|
76
|
-
expect(easy.response_body).to include('"HTTP_USER_AGENT":"0"')
|
77
|
-
end
|
78
|
-
end
|
79
50
|
end
|
80
51
|
end
|
81
52
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Ethon::Easy::Options do
|
@@ -12,7 +13,7 @@ describe Ethon::Easy::Options do
|
|
12
13
|
:proxyuserpwd, :readdata, :readfunction, :redir_protocols, :ssl_verifyhost,
|
13
14
|
:ssl_verifypeer, :sslcert, :sslcerttype, :sslkey, :sslkeytype, :sslversion,
|
14
15
|
:timeout, :timeout_ms, :unrestricted_auth, :upload, :url, :useragent,
|
15
|
-
:userpwd, :verbose
|
16
|
+
:userpwd, :verbose, :pipewait, :dns_shuffle_addresses, :path_as_is
|
16
17
|
].each do |name|
|
17
18
|
describe "#{name}=" do
|
18
19
|
it "responds_to" do
|
@@ -74,6 +75,35 @@ describe Ethon::Easy::Options do
|
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
78
|
+
describe '#multipart?' do
|
79
|
+
context 'by default' do
|
80
|
+
it 'returns false' do
|
81
|
+
expect(easy.multipart?).to be_falsey
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when #multipart=nil' do
|
86
|
+
it 'returns false' do
|
87
|
+
easy.multipart = nil
|
88
|
+
expect(easy.multipart?).to be_falsey
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when #multipart=true' do
|
93
|
+
it 'returns true' do
|
94
|
+
easy.multipart = true
|
95
|
+
expect(easy.multipart?).to be_truthy
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when #multipart=false' do
|
100
|
+
it 'returns false' do
|
101
|
+
easy.multipart = false
|
102
|
+
expect(easy.multipart?).to be_falsey
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
77
107
|
describe "#httppost=" do
|
78
108
|
it "raises unless given a FFI::Pointer" do
|
79
109
|
expect{ easy.httppost = 1 }.to raise_error(Ethon::Errors::InvalidValue)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Ethon::Easy::Queryable do
|
@@ -122,6 +123,14 @@ describe Ethon::Easy::Queryable do
|
|
122
123
|
expect(pairs).to include(["b[]", 3])
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
127
|
+
context "when params_encoding is :none" do
|
128
|
+
before { params.params_encoding = :none }
|
129
|
+
it "does no transformation" do
|
130
|
+
expect(pairs).to include([:a, 1])
|
131
|
+
expect(pairs).to include([:b, [2, 3]])
|
132
|
+
end
|
133
|
+
end
|
125
134
|
end
|
126
135
|
|
127
136
|
context "when params contains something nested in an array" do
|
@@ -152,9 +161,11 @@ describe Ethon::Easy::Queryable do
|
|
152
161
|
end
|
153
162
|
|
154
163
|
context "when MIME" do
|
155
|
-
|
156
|
-
|
157
|
-
|
164
|
+
if defined?(MIME)
|
165
|
+
context "when mime type" do
|
166
|
+
it "sets mime type to text" do
|
167
|
+
expect(mime_type).to eq("application/x-ruby")
|
168
|
+
end
|
158
169
|
end
|
159
170
|
end
|
160
171
|
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Ethon::Easy::ResponseCallbacks do
|
4
5
|
let(:easy) { Ethon::Easy.new }
|
5
6
|
|
6
|
-
[:on_complete, :on_headers, :on_body].each do |callback_type|
|
7
|
+
[:on_complete, :on_headers, :on_body, :on_progress].each do |callback_type|
|
7
8
|
describe "##{callback_type}" do
|
8
9
|
it "responds" do
|
9
10
|
expect(easy).to respond_to("#{callback_type}")
|
@@ -68,6 +69,62 @@ describe Ethon::Easy::ResponseCallbacks do
|
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
72
|
+
describe "#progress" do
|
73
|
+
context "when requesting for realz" do
|
74
|
+
it "executes callback" do
|
75
|
+
post = Ethon::Easy::Http::Post.new("http://localhost:3001", {:body => "bar=fu"})
|
76
|
+
post.setup(easy)
|
77
|
+
@called = false
|
78
|
+
@has_dltotal = false
|
79
|
+
@has_ultotal = false
|
80
|
+
easy.on_progress { @called = true }
|
81
|
+
easy.on_progress { |dltotal, _, _, _| @has_dltotal ||= true }
|
82
|
+
easy.on_progress { |_, _, ultotal, _| @has_ultotal ||= true }
|
83
|
+
easy.perform
|
84
|
+
expect(@called).to be true
|
85
|
+
expect(@has_dltotal).to be true
|
86
|
+
expect(@has_ultotal).to be true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when pretending" do
|
91
|
+
before do
|
92
|
+
@dltotal = nil
|
93
|
+
@dlnow = nil
|
94
|
+
@ultotal = nil
|
95
|
+
@ulnow = nil
|
96
|
+
easy.on_progress { |dltotal, dlnow, ultotal, ulnow| @dltotal = dltotal ; @dlnow = dlnow; @ultotal = ultotal; @ulnow = ulnow }
|
97
|
+
end
|
98
|
+
|
99
|
+
it "executes blocks and passes dltotal" do
|
100
|
+
easy.progress(1, 2, 3, 4)
|
101
|
+
expect(@dltotal).to eq(1)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "executes blocks and passes dlnow" do
|
105
|
+
easy.progress(1, 2, 3, 4)
|
106
|
+
expect(@dlnow).to eq(2)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "executes blocks and passes ultotal" do
|
110
|
+
easy.progress(1, 2, 3, 4)
|
111
|
+
expect(@ultotal).to eq(3)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "executes blocks and passes ulnow" do
|
115
|
+
easy.progress(1, 2, 3, 4)
|
116
|
+
expect(@ulnow).to eq(4)
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when @on_progress nil" do
|
120
|
+
it "doesn't raise" do
|
121
|
+
easy.instance_variable_set(:@on_progress, nil)
|
122
|
+
expect{ easy.progress(1, 2, 3, 4) }.to_not raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
71
128
|
describe "#body" do
|
72
129
|
before do
|
73
130
|
@chunk = nil
|