ethon 0.11.0 → 0.15.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 +5 -0
- data/Guardfile +1 -0
- data/README.md +1 -1
- data/Rakefile +1 -0
- data/ethon.gemspec +2 -1
- 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 +18 -0
- data/lib/ethon/curls/form_options.rb +1 -0
- data/lib/ethon/curls/functions.rb +5 -13
- data/lib/ethon/curls/infos.rb +4 -3
- data/lib/ethon/curls/messages.rb +1 -0
- data/lib/ethon/curls/options.rb +62 -25
- data/lib/ethon/curls/settings.rb +3 -0
- data/lib/ethon/easy/callbacks.rb +4 -3
- data/lib/ethon/easy/debug_info.rb +1 -0
- data/lib/ethon/easy/features.rb +1 -0
- data/lib/ethon/easy/form.rb +1 -0
- data/lib/ethon/easy/header.rb +1 -0
- data/lib/ethon/easy/http/actionable.rb +1 -0
- 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/http.rb +1 -0
- data/lib/ethon/easy/informations.rb +20 -1
- data/lib/ethon/easy/mirror.rb +1 -0
- data/lib/ethon/easy/operations.rb +1 -0
- data/lib/ethon/easy/options.rb +1 -0
- data/lib/ethon/easy/params.rb +1 -0
- data/lib/ethon/easy/queryable.rb +4 -1
- data/lib/ethon/easy/response_callbacks.rb +1 -0
- data/lib/ethon/easy/util.rb +1 -0
- data/lib/ethon/easy.rb +1 -1
- 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/errors.rb +1 -0
- data/lib/ethon/libc.rb +1 -0
- data/lib/ethon/loggable.rb +1 -0
- data/lib/ethon/multi/operations.rb +46 -8
- data/lib/ethon/multi/options.rb +9 -8
- data/lib/ethon/multi/stack.rb +1 -0
- data/lib/ethon/multi.rb +23 -0
- data/lib/ethon/version.rb +2 -1
- data/lib/ethon.rb +1 -0
- 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 +1 -0
- data/spec/ethon/easy/debug_info_spec.rb +1 -0
- data/spec/ethon/easy/features_spec.rb +1 -0
- data/spec/ethon/easy/form_spec.rb +1 -0
- data/spec/ethon/easy/header_spec.rb +1 -0
- 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 +23 -0
- data/spec/ethon/easy/mirror_spec.rb +2 -0
- data/spec/ethon/easy/operations_spec.rb +1 -0
- data/spec/ethon/easy/options_spec.rb +2 -1
- data/spec/ethon/easy/queryable_spec.rb +9 -0
- data/spec/ethon/easy/response_callbacks_spec.rb +1 -0
- data/spec/ethon/easy/util_spec.rb +1 -0
- data/spec/ethon/easy_spec.rb +3 -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 +114 -0
- data/spec/ethon/multi/stack_spec.rb +1 -0
- data/spec/ethon/multi_spec.rb +131 -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 -28
data/lib/ethon/easy/options.rb
CHANGED
data/lib/ethon/easy/params.rb
CHANGED
data/lib/ethon/easy/queryable.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Ethon
|
2
3
|
class Easy
|
3
4
|
|
@@ -102,6 +103,8 @@ module Ethon
|
|
102
103
|
encode_rack_array_pairs(h, prefix, pairs)
|
103
104
|
elsif params_encoding == :multi
|
104
105
|
encode_multi_array_pairs(h, prefix, pairs)
|
106
|
+
elsif params_encoding == :none
|
107
|
+
pairs << [prefix, h]
|
105
108
|
else
|
106
109
|
encode_indexed_array_pairs(h, prefix, pairs)
|
107
110
|
end
|
@@ -128,7 +131,7 @@ module Ethon
|
|
128
131
|
pairs_for(v, key, pairs)
|
129
132
|
end
|
130
133
|
end
|
131
|
-
|
134
|
+
|
132
135
|
def encode_multi_array_pairs(h, prefix, pairs)
|
133
136
|
h.each_with_index do |v, i|
|
134
137
|
key = prefix
|
data/lib/ethon/easy/util.rb
CHANGED
data/lib/ethon/easy.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'ethon/easy/informations'
|
2
3
|
require 'ethon/easy/features'
|
3
4
|
require 'ethon/easy/callbacks'
|
@@ -159,7 +160,6 @@ module Ethon
|
|
159
160
|
# * :recv_error: Failure with receiving network data.
|
160
161
|
# * :ssl_certproblem: problem with the local client certificate.
|
161
162
|
# * :ssl_cipher: Couldn't use specified cipher.
|
162
|
-
# * :ssl_cacert: Peer certificate cannot be authenticated with known CA certificates.
|
163
163
|
# * :bad_content_encoding: Unrecognized transfer encoding.
|
164
164
|
# * :ldap_invalid_url: Invalid LDAP URL.
|
165
165
|
# * :filesize_exceeded: Maximum file size exceeded.
|
data/lib/ethon/errors/select.rb
CHANGED
data/lib/ethon/errors.rb
CHANGED
data/lib/ethon/libc.rb
CHANGED
data/lib/ethon/loggable.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Ethon
|
2
3
|
class Multi # :nodoc
|
3
4
|
# This module contains logic to run a multi.
|
@@ -23,12 +24,16 @@ module Ethon
|
|
23
24
|
#
|
24
25
|
# @return [ void ]
|
25
26
|
def init_vars
|
26
|
-
@
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
if @execution_mode == :perform
|
28
|
+
@timeout = ::FFI::MemoryPointer.new(:long)
|
29
|
+
@timeval = Curl::Timeval.new
|
30
|
+
@fd_read = Curl::FDSet.new
|
31
|
+
@fd_write = Curl::FDSet.new
|
32
|
+
@fd_excep = Curl::FDSet.new
|
33
|
+
@max_fd = ::FFI::MemoryPointer.new(:int)
|
34
|
+
elsif @execution_mode == :socket_action
|
35
|
+
@running_count_pointer = FFI::MemoryPointer.new(:int)
|
36
|
+
end
|
32
37
|
end
|
33
38
|
|
34
39
|
# Perform multi.
|
@@ -38,6 +43,8 @@ module Ethon
|
|
38
43
|
# @example Perform multi.
|
39
44
|
# multi.perform
|
40
45
|
def perform
|
46
|
+
ensure_execution_mode(:perform)
|
47
|
+
|
41
48
|
Ethon.logger.debug(STARTED_MULTI)
|
42
49
|
while ongoing?
|
43
50
|
run
|
@@ -66,9 +73,38 @@ module Ethon
|
|
66
73
|
)
|
67
74
|
end
|
68
75
|
|
69
|
-
|
76
|
+
# Continue execution with an external IO loop.
|
77
|
+
#
|
78
|
+
# @example When no sockets are ready yet, or to begin.
|
79
|
+
# multi.socket_action
|
80
|
+
#
|
81
|
+
# @example When a socket is readable
|
82
|
+
# multi.socket_action(io_object, [:in])
|
83
|
+
#
|
84
|
+
# @example When a socket is readable and writable
|
85
|
+
# multi.socket_action(io_object, [:in, :out])
|
86
|
+
#
|
87
|
+
# @return [ Symbol ] The Curl.multi_socket_action return code.
|
88
|
+
def socket_action(io = nil, readiness = 0)
|
89
|
+
ensure_execution_mode(:socket_action)
|
90
|
+
|
91
|
+
fd = if io.nil?
|
92
|
+
::Ethon::Curl::SOCKET_TIMEOUT
|
93
|
+
elsif io.is_a?(Integer)
|
94
|
+
io
|
95
|
+
else
|
96
|
+
io.fileno
|
97
|
+
end
|
98
|
+
|
99
|
+
code = Curl.multi_socket_action(handle, fd, readiness, @running_count_pointer)
|
100
|
+
@running_count = @running_count_pointer.read_int
|
70
101
|
|
71
|
-
|
102
|
+
check
|
103
|
+
|
104
|
+
code
|
105
|
+
end
|
106
|
+
|
107
|
+
# Return whether the multi still contains requests or not.
|
72
108
|
#
|
73
109
|
# @example Return if ongoing.
|
74
110
|
# multi.ongoing?
|
@@ -78,6 +114,8 @@ module Ethon
|
|
78
114
|
easy_handles.size > 0 || (!defined?(@running_count) || running_count > 0)
|
79
115
|
end
|
80
116
|
|
117
|
+
private
|
118
|
+
|
81
119
|
# Get timeout.
|
82
120
|
#
|
83
121
|
# @example Get timeout.
|
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/multi.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'ethon/easy/util'
|
2
3
|
require 'ethon/multi/stack'
|
3
4
|
require 'ethon/multi/operations'
|
@@ -73,10 +74,21 @@ module Ethon
|
|
73
74
|
# is 1 will not be treated as unlimited. Instead it will open only 1
|
74
75
|
# connection and try to pipeline on it.
|
75
76
|
# (Added in 7.30.0)
|
77
|
+
# @option options :execution_mode [Boolean]
|
78
|
+
# Either :perform (default) or :socket_action, specifies the usage
|
79
|
+
# method that will be used on this multi object. The default :perform
|
80
|
+
# mode provides a #perform function that uses curl_multi_perform
|
81
|
+
# behind the scenes to automatically continue execution until all
|
82
|
+
# requests have completed. The :socket_action mode provides an API
|
83
|
+
# that allows the {Multi} object to be integrated into an external
|
84
|
+
# IO loop, by calling #socket_action and responding to the
|
85
|
+
# socketfunction and timerfunction callbacks, using the underlying
|
86
|
+
# curl_multi_socket_action semantics.
|
76
87
|
#
|
77
88
|
# @return [ Multi ] The new multi.
|
78
89
|
def initialize(options = {})
|
79
90
|
Curl.init
|
91
|
+
@execution_mode = options.delete(:execution_mode) || :perform
|
80
92
|
set_attributes(options)
|
81
93
|
init_vars
|
82
94
|
end
|
@@ -99,5 +111,16 @@ module Ethon
|
|
99
111
|
method("#{key}=").call(value)
|
100
112
|
end
|
101
113
|
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
# Internal function to gate functions to a specific execution mode
|
118
|
+
#
|
119
|
+
# @raise ArgumentError
|
120
|
+
#
|
121
|
+
# @api private
|
122
|
+
def ensure_execution_mode(expected_mode)
|
123
|
+
raise ArgumentError, "Expected the Multi to be in #{expected_mode} but it was in #{@execution_mode}" if expected_mode != @execution_mode
|
124
|
+
end
|
102
125
|
end
|
103
126
|
end
|
data/lib/ethon/version.rb
CHANGED
data/lib/ethon.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::Informations do
|
@@ -93,5 +94,27 @@ describe Ethon::Easy::Informations do
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
97
|
+
describe "#size_upload" do
|
98
|
+
it "returns float" do
|
99
|
+
expect(easy.size_upload).to be_a(Float)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#size_download" do
|
104
|
+
it "returns float" do
|
105
|
+
expect(easy.size_download).to be_a(Float)
|
106
|
+
end
|
107
|
+
end
|
96
108
|
|
109
|
+
describe "#speed_upload" do
|
110
|
+
it "returns float" do
|
111
|
+
expect(easy.speed_upload).to be_a(Float)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#speed_download" do
|
116
|
+
it "returns float" do
|
117
|
+
expect(easy.speed_download).to be_a(Float)
|
118
|
+
end
|
119
|
+
end
|
97
120
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Ethon::Easy::Mirror do
|
@@ -9,6 +10,7 @@ describe Ethon::Easy::Mirror do
|
|
9
10
|
:return_code, :response_code, :response_body, :response_headers,
|
10
11
|
:total_time, :starttransfer_time, :appconnect_time,
|
11
12
|
:pretransfer_time, :connect_time, :namelookup_time, :redirect_time,
|
13
|
+
:size_upload, :size_download, :speed_upload, :speed_upload,
|
12
14
|
:effective_url, :primary_ip, :redirect_count, :debug_info
|
13
15
|
].each do |name|
|
14
16
|
it "contains #{name}" do
|
@@ -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
|
@@ -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
|
data/spec/ethon/easy_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Ethon::Easy do
|
@@ -106,8 +107,8 @@ describe Ethon::Easy do
|
|
106
107
|
easy.on_complete { 'on_complete' }
|
107
108
|
easy.on_headers { 'on_headers' }
|
108
109
|
easy.on_progress { 'on_progress' }
|
109
|
-
easy.response_body = 'test_body'
|
110
|
-
easy.response_headers = 'test_headers'
|
110
|
+
easy.response_body = String.new('test_body')
|
111
|
+
easy.response_headers = String.new('test_headers')
|
111
112
|
easy
|
112
113
|
end
|
113
114
|
let!(:e) { easy.dup }
|
data/spec/ethon/libc_spec.rb
CHANGED
data/spec/ethon/loggable_spec.rb
CHANGED