ethon 0.11.0 → 0.16.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 +19 -1
- data/Gemfile +5 -0
- data/Guardfile +1 -0
- data/README.md +24 -1
- data/Rakefile +1 -0
- data/ethon.gemspec +2 -1
- data/lib/ethon/curl.rb +1 -0
- data/lib/ethon/curls/classes.rb +13 -2
- 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 +65 -27
- data/lib/ethon/curls/settings.rb +3 -0
- data/lib/ethon/easy/callbacks.rb +6 -4
- 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 +23 -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 +7 -1
- 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 +23 -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 +29 -0
- data/spec/ethon/easy/mirror_spec.rb +3 -1
- data/spec/ethon/easy/operations_spec.rb +4 -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 +9 -10
- data/.travis.yml +0 -28
data/lib/ethon/easy/http/post.rb
CHANGED
data/lib/ethon/easy/http/put.rb
CHANGED
data/lib/ethon/easy/http.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Ethon
|
2
3
|
class Easy
|
3
4
|
|
@@ -70,7 +71,28 @@ module Ethon
|
|
70
71
|
|
71
72
|
# Return the total number of redirections that were
|
72
73
|
# actually followed.
|
73
|
-
:redirect_count => :long
|
74
|
+
:redirect_count => :long,
|
75
|
+
|
76
|
+
# URL a redirect would take you to, had you enabled redirects (Added in 7.18.2)
|
77
|
+
:redirect_url => :string,
|
78
|
+
|
79
|
+
# Return the bytes, the total amount of bytes that were uploaded
|
80
|
+
:size_upload => :double,
|
81
|
+
|
82
|
+
# Return the bytes, the total amount of bytes that were downloaded.
|
83
|
+
# The amount is only for the latest transfer and will be reset again
|
84
|
+
# for each new transfer. This counts actual payload data, what's
|
85
|
+
# also commonly called body. All meta and header data are excluded
|
86
|
+
# and will not be counted in this number.
|
87
|
+
:size_download => :double,
|
88
|
+
|
89
|
+
# Return the bytes/second, the average upload speed that curl
|
90
|
+
# measured for the complete upload
|
91
|
+
:speed_upload => :double,
|
92
|
+
|
93
|
+
# Return the bytes/second, the average download speed that curl
|
94
|
+
# measured for the complete download
|
95
|
+
:speed_download => :double
|
74
96
|
}
|
75
97
|
|
76
98
|
AVAILABLE_INFORMATIONS.each do |name, type|
|
data/lib/ethon/easy/mirror.rb
CHANGED
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
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Ethon
|
2
3
|
class Easy
|
3
4
|
|
@@ -42,7 +43,12 @@ module Ethon
|
|
42
43
|
return if @headers_called
|
43
44
|
@headers_called = true
|
44
45
|
if defined?(@on_headers) and not @on_headers.nil?
|
45
|
-
|
46
|
+
result = nil
|
47
|
+
@on_headers.each do |callback|
|
48
|
+
result = callback.call(self)
|
49
|
+
break if result == :abort
|
50
|
+
end
|
51
|
+
result
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
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::Callbacks do
|
@@ -55,4 +56,26 @@ describe Ethon::Easy::Callbacks do
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
59
|
+
|
60
|
+
describe "#header_write_callback" do
|
61
|
+
let(:header_write_callback) { easy.instance_variable_get(:@header_write_callback) }
|
62
|
+
let(:stream) { double(:read_string => "") }
|
63
|
+
context "when header returns not :abort" do
|
64
|
+
it "returns number bigger than 0" do
|
65
|
+
expect(header_write_callback.call(stream, 1, 1, nil) > 0).to be(true)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when header returns :abort" do
|
70
|
+
before do
|
71
|
+
easy.on_headers.clear
|
72
|
+
easy.on_headers { :abort }
|
73
|
+
end
|
74
|
+
let(:header_write_callback) { easy.instance_variable_get(:@header_write_callback) }
|
75
|
+
|
76
|
+
it "returns -1 to indicate abort to libcurl" do
|
77
|
+
expect(header_write_callback.call(stream, 1, 1, nil)).to eq(-1)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
58
81
|
end
|