ethon 0.5.2 → 0.5.3
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.
- data/CHANGELOG.md +20 -1
- data/Gemfile +6 -7
- data/README.md +1 -6
- data/lib/ethon.rb +7 -3
- data/lib/ethon/curls/classes.rb +1 -1
- data/lib/ethon/curls/functions.rb +1 -0
- data/lib/ethon/easy.rb +4 -5
- data/lib/ethon/easy/header.rb +4 -13
- data/lib/ethon/easy/http/actionable.rb +5 -13
- data/lib/ethon/easy/http/postable.rb +2 -1
- data/lib/ethon/easy/http/putable.rb +0 -1
- data/lib/ethon/easy/operations.rb +7 -3
- data/lib/ethon/easy/options.rb +492 -75
- data/lib/ethon/libc.rb +8 -0
- data/lib/ethon/multi.rb +1 -0
- data/lib/ethon/multi/operations.rb +19 -11
- data/lib/ethon/multi/options.rb +69 -51
- data/lib/ethon/version.rb +1 -1
- metadata +4 -3
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,26 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
-
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.5.
|
5
|
+
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.5.3...master)
|
6
|
+
|
7
|
+
## 0.5.3
|
8
|
+
|
9
|
+
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.5.2...v0.5.3)
|
10
|
+
|
11
|
+
Enhancements:
|
12
|
+
|
13
|
+
* Deprecate Easy#prepare. It is no longer necessary.
|
14
|
+
* Unroll metaprogramming for easy and multi options.
|
15
|
+
* More specs.
|
16
|
+
|
17
|
+
Bugfixes:
|
18
|
+
|
19
|
+
* Correct size for FDSets
|
20
|
+
* Add proxytypes to enums.
|
21
|
+
|
22
|
+
## 0.5.2
|
23
|
+
|
24
|
+
[Full Changelog](http://github.com/typhoeus/ethon/compare/v0.5.1...v0.5.2)
|
6
25
|
|
7
26
|
Enhancements:
|
8
27
|
|
data/Gemfile
CHANGED
@@ -9,14 +9,13 @@ group :development, :test do
|
|
9
9
|
gem "sinatra", "~> 1.3"
|
10
10
|
gem "json"
|
11
11
|
|
12
|
-
if RUBY_PLATFORM == "java"
|
13
|
-
gem "spoon"
|
14
|
-
else
|
15
|
-
gem "patron", "~> 0.4"
|
16
|
-
gem "curb", "~> 0.8.0"
|
17
|
-
end
|
18
|
-
|
19
12
|
unless ENV["CI"]
|
20
13
|
gem "guard-rspec", "~> 0.7"
|
14
|
+
gem 'rb-fsevent', '~> 0.9.1'
|
21
15
|
end
|
22
16
|
end
|
17
|
+
|
18
|
+
group :perf do
|
19
|
+
gem "patron", "~> 0.4"
|
20
|
+
gem "curb", "~> 0.8.0"
|
21
|
+
end
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
In the greek mythology Ethon is a gigantic eagle the son of Typhoeus and Echidna. So much for the history.
|
4
4
|
In the modern world Ethon is a very basic libcurl wrapper using ffi.
|
5
5
|
|
6
|
-
* [Documentation](http://rubydoc.info/github/typhoeus/ethon)
|
6
|
+
* [Documentation](http://rubydoc.info/github/typhoeus/ethon/frames/Ethon)
|
7
7
|
* [Website](http://typhoeus.github.com/)
|
8
8
|
* [Mailinglist](http://groups.google.com/group/typhoeus)
|
9
9
|
|
@@ -23,7 +23,6 @@ Making the first request is realy simple:
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
easy = Ethon::Easy.new(url: "www.example.com")
|
26
|
-
easy.prepare
|
27
26
|
easy.perform
|
28
27
|
#=> :ok
|
29
28
|
```
|
@@ -32,7 +31,6 @@ You have access to various options like following redirects:
|
|
32
31
|
|
33
32
|
```ruby
|
34
33
|
easy = Ethon::Easy.new(url: "www.example.com", followlocation: true)
|
35
|
-
easy.prepare
|
36
34
|
easy.perform
|
37
35
|
#=> :ok
|
38
36
|
```
|
@@ -41,7 +39,6 @@ Once you're done you can look at the response code and body:
|
|
41
39
|
|
42
40
|
```ruby
|
43
41
|
easy = Ethon::Easy.new(url: "www.example.com", followlocation: true)
|
44
|
-
easy.prepare
|
45
42
|
easy.perform
|
46
43
|
easy.response_code
|
47
44
|
#=> 200
|
@@ -56,7 +53,6 @@ In order to make life easier there are some helpers for doing http requests:
|
|
56
53
|
```ruby
|
57
54
|
easy = Ethon::Easy.new
|
58
55
|
easy.http_request("www.example.com", :get, { params: {a: 1} })
|
59
|
-
easy.prepare
|
60
56
|
easy.perform
|
61
57
|
#=> :ok
|
62
58
|
```
|
@@ -64,7 +60,6 @@ easy.perform
|
|
64
60
|
```ruby
|
65
61
|
easy = Ethon::Easy.new
|
66
62
|
easy.http_request("www.example.com", :post, { params: { a: 1 }, body: { b: 2 } })
|
67
|
-
easy.prepare
|
68
63
|
easy.perform
|
69
64
|
#=> :ok
|
70
65
|
```
|
data/lib/ethon.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'ffi'
|
3
|
-
require 'rbconfig'
|
4
3
|
require 'thread'
|
5
4
|
require 'mime/types'
|
6
5
|
require 'tempfile'
|
7
6
|
|
7
|
+
require 'ethon/libc'
|
8
8
|
require 'ethon/curl'
|
9
|
-
require 'ethon/errors'
|
10
9
|
require 'ethon/easy'
|
11
|
-
require 'ethon/
|
10
|
+
require 'ethon/errors'
|
12
11
|
require 'ethon/loggable'
|
12
|
+
require 'ethon/multi'
|
13
13
|
require 'ethon/version'
|
14
14
|
|
15
15
|
# Ethon is a very simple libcurl.
|
@@ -20,5 +20,9 @@ require 'ethon/version'
|
|
20
20
|
# see how others use Ethon look at the Typhoeus code.
|
21
21
|
#
|
22
22
|
# @see https://www.github.com/typhoeus/typhoeus Typhoeus
|
23
|
+
#
|
24
|
+
# @note Please update to the latest libcurl version in order
|
25
|
+
# to benefit from all features and bugfixes.
|
26
|
+
# http://curl.haxx.se/download.html
|
23
27
|
module Ethon
|
24
28
|
end
|
data/lib/ethon/curls/classes.rb
CHANGED
@@ -18,7 +18,7 @@ module Ethon
|
|
18
18
|
# :nodoc:
|
19
19
|
class FDSet < ::FFI::Struct
|
20
20
|
# XXX how does this work on non-windows? how can curl know the new size...
|
21
|
-
FD_SETSIZE =
|
21
|
+
FD_SETSIZE = ::Ethon::Libc.getdtablesize
|
22
22
|
|
23
23
|
if Curl.windows?
|
24
24
|
layout :fd_count, :u_int,
|
@@ -8,6 +8,7 @@ module Ethon
|
|
8
8
|
# :nodoc:
|
9
9
|
def self.extended(base)
|
10
10
|
base.attach_function :global_init, :curl_global_init, [:long], :int
|
11
|
+
base.attach_function :free, :curl_free, [:pointer], :void
|
11
12
|
|
12
13
|
base.attach_function :easy_init, :curl_easy_init, [], :pointer
|
13
14
|
base.attach_function :easy_cleanup, :curl_easy_cleanup, [:pointer], :void
|
data/lib/ethon/easy.rb
CHANGED
@@ -17,7 +17,6 @@ module Ethon
|
|
17
17
|
# @example You can access the libcurl easy interface through this class, every request is based on it. The simplest setup looks like that:
|
18
18
|
#
|
19
19
|
# e = Ethon::Easy.new(url: "www.example.com")
|
20
|
-
# e.prepare
|
21
20
|
# e.perform
|
22
21
|
# #=> :ok
|
23
22
|
#
|
@@ -26,7 +25,6 @@ module Ethon
|
|
26
25
|
# e.reset # reset easy handle
|
27
26
|
# e.url = "www.google.com"
|
28
27
|
# e.followlocation = true
|
29
|
-
# e.prepare
|
30
28
|
# e.perform
|
31
29
|
# #=> :ok
|
32
30
|
#
|
@@ -810,6 +808,7 @@ module Ethon
|
|
810
808
|
Curl.init
|
811
809
|
ObjectSpace.define_finalizer(self, self.class.finalizer(self))
|
812
810
|
set_attributes(options)
|
811
|
+
set_callbacks
|
813
812
|
end
|
814
813
|
|
815
814
|
# Set given options.
|
@@ -839,10 +838,10 @@ module Ethon
|
|
839
838
|
# @example Reset.
|
840
839
|
# easy.reset
|
841
840
|
def reset
|
842
|
-
|
843
|
-
|
844
|
-
end
|
841
|
+
@url = nil
|
842
|
+
@hash = nil
|
845
843
|
Curl.easy_reset(handle)
|
844
|
+
set_callbacks
|
846
845
|
end
|
847
846
|
|
848
847
|
# Url escapes the value.
|
data/lib/ethon/easy/header.rb
CHANGED
@@ -23,7 +23,10 @@ module Ethon
|
|
23
23
|
#
|
24
24
|
# @param [ Hash ] headers The headers.
|
25
25
|
def headers=(headers)
|
26
|
-
|
26
|
+
headers ||= {}
|
27
|
+
@header_list = nil
|
28
|
+
headers.each {|k, v| @header_list = Curl.slist_append(@header_list, compose_header(k,v)) }
|
29
|
+
Curl.set_option(:httpheader, @header_list, handle)
|
27
30
|
end
|
28
31
|
|
29
32
|
# Return header_list.
|
@@ -36,18 +39,6 @@ module Ethon
|
|
36
39
|
@header_list ||= nil
|
37
40
|
end
|
38
41
|
|
39
|
-
# Set previously defined headers in libcurl.
|
40
|
-
#
|
41
|
-
# @example Set headers in libcurl.
|
42
|
-
# easy.set_headers
|
43
|
-
#
|
44
|
-
# @return [ Symbol ] The return value from Curl.set_option.
|
45
|
-
def set_headers
|
46
|
-
@header_list = nil
|
47
|
-
headers.each {|k, v| @header_list = Curl.slist_append(@header_list, compose_header(k,v)) }
|
48
|
-
Curl.set_option(:httpheader, @header_list, handle)
|
49
|
-
end
|
50
|
-
|
51
42
|
# Compose libcurl header string from key and value.
|
52
43
|
# Also replaces null bytes, because libcurl will complain about
|
53
44
|
# otherwise.
|
@@ -70,23 +70,15 @@ module Ethon
|
|
70
70
|
# @param [ easy ] easy the easy to setup.
|
71
71
|
def setup(easy)
|
72
72
|
@easy = easy
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
if params.empty?
|
74
|
+
easy.url = url
|
75
|
+
else
|
76
|
+
set_params(easy)
|
77
|
+
end
|
76
78
|
set_form(easy) unless form.empty?
|
77
79
|
easy.set_attributes(options)
|
78
80
|
end
|
79
81
|
|
80
|
-
# Setup request as if there were no params and form.
|
81
|
-
#
|
82
|
-
# @example Setup nothing.
|
83
|
-
# action.set_nothing(easy)
|
84
|
-
#
|
85
|
-
# @param [ Easy ] easy The easy to setup.
|
86
|
-
def set_nothing(easy)
|
87
|
-
easy.url = url
|
88
|
-
end
|
89
|
-
|
90
82
|
# Setup request with params.
|
91
83
|
#
|
92
84
|
# @example Setup nothing.
|
@@ -4,6 +4,7 @@ module Ethon
|
|
4
4
|
|
5
5
|
# This module contains logic for setting up a [multipart] POST body.
|
6
6
|
module Postable
|
7
|
+
|
7
8
|
# Set things up when form is provided.
|
8
9
|
# Deals with multipart forms.
|
9
10
|
#
|
@@ -19,8 +20,8 @@ module Ethon
|
|
19
20
|
easy.httppost = form.first.read_pointer
|
20
21
|
else
|
21
22
|
form.escape = true
|
23
|
+
easy.postfieldsize = form.to_s.bytesize
|
22
24
|
easy.copypostfields = form.to_s
|
23
|
-
easy.postfieldsize = easy.copypostfields.bytesize
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -36,10 +36,14 @@ module Ethon
|
|
36
36
|
# easy.prepare
|
37
37
|
#
|
38
38
|
# @api public
|
39
|
+
#
|
40
|
+
# @deprecated It is no longer necessary to call prepare.
|
39
41
|
def prepare
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
Ethon.logger.warn(
|
43
|
+
"ETHON: It is no longer necessay to call "+
|
44
|
+
"Easy#prepare. Its going to be removed "+
|
45
|
+
"in future versions."
|
46
|
+
)
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
data/lib/ethon/easy/options.rb
CHANGED
@@ -7,81 +7,491 @@ module Ethon
|
|
7
7
|
# @api private
|
8
8
|
module Options
|
9
9
|
|
10
|
-
|
11
|
-
def self.included(base)
|
12
|
-
base.extend ClassMethods
|
13
|
-
base.const_set(:AVAILABLE_OPTIONS, [
|
14
|
-
:dns_cache_timeout, :httppost, :httpget, :nobody, :upload,
|
15
|
-
:customrequest, :cainfo, :capath, :connecttimeout, :connecttimeout_ms,
|
16
|
-
:forbid_reuse, :followlocation, :httpauth, :infilesize, :interface,
|
17
|
-
:keypasswd, :maxredirs, :nosignal, :postfieldsize, :copypostfields, :proxy,
|
18
|
-
:proxyauth, :proxyport, :proxytype, :proxyuserpwd, :timeout, :timeout_ms,
|
19
|
-
:readdata, :sslcert, :ssl_verifypeer, :ssl_verifyhost, :sslcerttype,
|
20
|
-
:sslkey, :sslkeytype, :sslversion, :url, :useragent, :userpwd,
|
21
|
-
:verbose, :readfunction
|
22
|
-
])
|
23
|
-
base.send(:attr_accessor, *Ethon::Easy::AVAILABLE_OPTIONS)
|
24
|
-
end
|
25
|
-
|
26
|
-
module ClassMethods # :nodoc:
|
27
|
-
|
28
|
-
# Return the available options.
|
29
|
-
#
|
30
|
-
# @example Return the available options.
|
31
|
-
# easy.available_options
|
32
|
-
#
|
33
|
-
# @return [ Array ] The available options.
|
34
|
-
def available_options
|
35
|
-
Ethon::Easy::AVAILABLE_OPTIONS
|
36
|
-
end
|
10
|
+
attr_reader :url
|
37
11
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
12
|
+
# Sets cainfo option.
|
13
|
+
#
|
14
|
+
# @example Set cainfo option.
|
15
|
+
# easy.cainfo = $value
|
16
|
+
#
|
17
|
+
# @param [ String ] value The value to set.
|
18
|
+
#
|
19
|
+
# @return [ void ]
|
20
|
+
def cainfo=(value)
|
21
|
+
Curl.set_option(:cainfo, value_for(value, :string), handle)
|
22
|
+
end
|
50
23
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
24
|
+
# Sets capath option.
|
25
|
+
#
|
26
|
+
# @example Set capath option.
|
27
|
+
# easy.capath = $value
|
28
|
+
#
|
29
|
+
# @param [ String ] value The value to set.
|
30
|
+
#
|
31
|
+
# @return [ void ]
|
32
|
+
def capath=(value)
|
33
|
+
Curl.set_option(:capath, value_for(value, :string), handle)
|
34
|
+
end
|
60
35
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
]
|
72
|
-
end
|
36
|
+
# Sets connecttimeout option.
|
37
|
+
#
|
38
|
+
# @example Set connecttimeout option.
|
39
|
+
# easy.connecttimeout = 1
|
40
|
+
#
|
41
|
+
# @param [ Integer ] value The value to set.
|
42
|
+
#
|
43
|
+
# @return [ void ]
|
44
|
+
def connecttimeout=(value)
|
45
|
+
Curl.set_option(:connecttimeout, value_for(value, :int), handle)
|
73
46
|
end
|
74
47
|
|
75
|
-
#
|
48
|
+
# Sets connecttimeout_ms option.
|
76
49
|
#
|
77
|
-
# @example Set
|
78
|
-
# easy.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
50
|
+
# @example Set connecttimeout_ms option.
|
51
|
+
# easy.connecttimeout_ms = 1
|
52
|
+
#
|
53
|
+
# @param [ Integer ] value The value to set.
|
54
|
+
#
|
55
|
+
# @return [ void ]
|
56
|
+
def connecttimeout_ms=(value)
|
57
|
+
Curl.set_option(:connecttimeout_ms, value_for(value, :int), handle)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Sets copypostfields option.
|
61
|
+
#
|
62
|
+
# @example Set copypostfields option.
|
63
|
+
# easy.copypostfields = $value
|
64
|
+
#
|
65
|
+
# @param [ String ] value The value to set.
|
66
|
+
#
|
67
|
+
# @return [ void ]
|
68
|
+
def copypostfields=(value)
|
69
|
+
Curl.set_option(:copypostfields, value_for(value, :string), handle)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Sets customrequest option.
|
73
|
+
#
|
74
|
+
# @example Set customrequest option.
|
75
|
+
# easy.customrequest = $value
|
76
|
+
#
|
77
|
+
# @param [ String ] value The value to set.
|
78
|
+
#
|
79
|
+
# @return [ void ]
|
80
|
+
def customrequest=(value)
|
81
|
+
Curl.set_option(:customrequest, value_for(value, :string), handle)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Sets dns_cache_timeout option.
|
85
|
+
#
|
86
|
+
# @example Set dns_cache_timeout option.
|
87
|
+
# easy.dns_cache_timeout = 1
|
88
|
+
#
|
89
|
+
# @param [ Integer ] value The value to set.
|
90
|
+
#
|
91
|
+
# @return [ void ]
|
92
|
+
def dns_cache_timeout=(value)
|
93
|
+
Curl.set_option(:dns_cache_timeout, value_for(value, :int), handle)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Sets followlocation option.
|
97
|
+
#
|
98
|
+
# @example Set followlocation option.
|
99
|
+
# easy.followlocation = true
|
100
|
+
#
|
101
|
+
# @param [ Boolean ] value The value to set.
|
102
|
+
#
|
103
|
+
# @return [ void ]
|
104
|
+
def followlocation=(value)
|
105
|
+
Curl.set_option(:followlocation, value_for(value, :bool), handle)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Sets forbid_reuse option.
|
109
|
+
#
|
110
|
+
# @example Set forbid_reuse option.
|
111
|
+
# easy.forbid_reuse = true
|
112
|
+
#
|
113
|
+
# @param [ Boolean ] value The value to set.
|
114
|
+
#
|
115
|
+
# @return [ void ]
|
116
|
+
def forbid_reuse=(value)
|
117
|
+
Curl.set_option(:forbid_reuse, value_for(value, :bool), handle)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Sets httpauth option.
|
121
|
+
#
|
122
|
+
# @example Set httpauth option.
|
123
|
+
# easy.httpauth = $value
|
124
|
+
#
|
125
|
+
# @param [ $type_doc ] value The value to set.
|
126
|
+
#
|
127
|
+
# @return [ void ]
|
128
|
+
def httpauth=(value)
|
129
|
+
Curl.set_option(:httpauth, value_for(value, :enum, :httpauth), handle)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Sets httpget option.
|
133
|
+
#
|
134
|
+
# @example Set httpget option.
|
135
|
+
# easy.httpget = true
|
136
|
+
#
|
137
|
+
# @param [ Boolean ] value The value to set.
|
138
|
+
#
|
139
|
+
# @return [ void ]
|
140
|
+
def httpget=(value)
|
141
|
+
Curl.set_option(:httpget, value_for(value, :bool), handle)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Sets httppost option.
|
145
|
+
#
|
146
|
+
# @example Set httppost option.
|
147
|
+
# easy.httppost = $value
|
148
|
+
#
|
149
|
+
# @param [ String ] value The value to set.
|
150
|
+
#
|
151
|
+
# @return [ void ]
|
152
|
+
def httppost=(value)
|
153
|
+
Curl.set_option(:httppost, value_for(value, :string), handle)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Sets infilesize option.
|
157
|
+
#
|
158
|
+
# @example Set infilesize option.
|
159
|
+
# easy.infilesize = 1
|
160
|
+
#
|
161
|
+
# @param [ Integer ] value The value to set.
|
162
|
+
#
|
163
|
+
# @return [ void ]
|
164
|
+
def infilesize=(value)
|
165
|
+
Curl.set_option(:infilesize, value_for(value, :int), handle)
|
166
|
+
end
|
167
|
+
|
168
|
+
# Sets interface option.
|
169
|
+
#
|
170
|
+
# @example Set interface option.
|
171
|
+
# easy.interface = $value
|
172
|
+
#
|
173
|
+
# @param [ String ] value The value to set.
|
174
|
+
#
|
175
|
+
# @return [ void ]
|
176
|
+
def interface=(value)
|
177
|
+
Curl.set_option(:interface, value_for(value, :string), handle)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Sets keypasswd option.
|
181
|
+
#
|
182
|
+
# @example Set keypasswd option.
|
183
|
+
# easy.keypasswd = $value
|
184
|
+
#
|
185
|
+
# @param [ String ] value The value to set.
|
186
|
+
#
|
187
|
+
# @return [ void ]
|
188
|
+
def keypasswd=(value)
|
189
|
+
Curl.set_option(:keypasswd, value_for(value, :string), handle)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Sets maxredirs option.
|
193
|
+
#
|
194
|
+
# @example Set maxredirs option.
|
195
|
+
# easy.maxredirs = 1
|
196
|
+
#
|
197
|
+
# @param [ Integer ] value The value to set.
|
198
|
+
#
|
199
|
+
# @return [ void ]
|
200
|
+
def maxredirs=(value)
|
201
|
+
Curl.set_option(:maxredirs, value_for(value, :int), handle)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Sets nobody option.
|
205
|
+
#
|
206
|
+
# @example Set nobody option.
|
207
|
+
# easy.nobody = true
|
208
|
+
#
|
209
|
+
# @param [ Boolean ] value The value to set.
|
210
|
+
#
|
211
|
+
# @return [ void ]
|
212
|
+
def nobody=(value)
|
213
|
+
Curl.set_option(:nobody, value_for(value, :bool), handle)
|
214
|
+
end
|
215
|
+
|
216
|
+
# Sets nosignal option.
|
217
|
+
#
|
218
|
+
# @example Set nosignal option.
|
219
|
+
# easy.nosignal = true
|
220
|
+
#
|
221
|
+
# @param [ Boolean ] value The value to set.
|
222
|
+
#
|
223
|
+
# @return [ void ]
|
224
|
+
def nosignal=(value)
|
225
|
+
Curl.set_option(:nosignal, value_for(value, :bool), handle)
|
226
|
+
end
|
227
|
+
|
228
|
+
# Sets postfieldsize option.
|
229
|
+
#
|
230
|
+
# @example Set postfieldsize option.
|
231
|
+
# easy.postfieldsize = 1
|
232
|
+
#
|
233
|
+
# @param [ Integer ] value The value to set.
|
234
|
+
#
|
235
|
+
# @return [ void ]
|
236
|
+
def postfieldsize=(value)
|
237
|
+
Curl.set_option(:postfieldsize, value_for(value, :int), handle)
|
238
|
+
end
|
239
|
+
|
240
|
+
# Sets proxy option.
|
241
|
+
#
|
242
|
+
# @example Set proxy option.
|
243
|
+
# easy.proxy = $value
|
244
|
+
#
|
245
|
+
# @param [ String ] value The value to set.
|
246
|
+
#
|
247
|
+
# @return [ void ]
|
248
|
+
def proxy=(value)
|
249
|
+
Curl.set_option(:proxy, value_for(value, :string), handle)
|
250
|
+
end
|
251
|
+
|
252
|
+
# Sets proxyauth option.
|
253
|
+
#
|
254
|
+
# @example Set proxyauth option.
|
255
|
+
# easy.proxyauth = $value
|
256
|
+
#
|
257
|
+
# @param [ String ] value The value to set.
|
258
|
+
#
|
259
|
+
# @return [ void ]
|
260
|
+
def proxyauth=(value)
|
261
|
+
Curl.set_option(:proxyauth, value_for(value, :string), handle)
|
83
262
|
end
|
84
263
|
|
264
|
+
# Sets proxyport option.
|
265
|
+
#
|
266
|
+
# @example Set proxyport option.
|
267
|
+
# easy.proxyport = 1
|
268
|
+
#
|
269
|
+
# @param [ Integer ] value The value to set.
|
270
|
+
#
|
271
|
+
# @return [ void ]
|
272
|
+
def proxyport=(value)
|
273
|
+
Curl.set_option(:proxyport, value_for(value, :int), handle)
|
274
|
+
end
|
275
|
+
|
276
|
+
# Sets proxytype option.
|
277
|
+
#
|
278
|
+
# @example Set proxytype option.
|
279
|
+
# easy.proxytype = $value
|
280
|
+
#
|
281
|
+
# @param [ String ] value The value to set.
|
282
|
+
#
|
283
|
+
# @return [ void ]
|
284
|
+
def proxytype=(value)
|
285
|
+
Curl.set_option(:proxytype, value_for(value, :string), handle)
|
286
|
+
end
|
287
|
+
|
288
|
+
# Sets proxyuserpwd option.
|
289
|
+
#
|
290
|
+
# @example Set proxyuserpwd option.
|
291
|
+
# easy.proxyuserpwd = $value
|
292
|
+
#
|
293
|
+
# @param [ String ] value The value to set.
|
294
|
+
#
|
295
|
+
# @return [ void ]
|
296
|
+
def proxyuserpwd=(value)
|
297
|
+
Curl.set_option(:proxyuserpwd, value_for(value, :string), handle)
|
298
|
+
end
|
299
|
+
|
300
|
+
# Sets readdata option.
|
301
|
+
#
|
302
|
+
# @example Set readdata option.
|
303
|
+
# easy.readdata = $value
|
304
|
+
#
|
305
|
+
# @param [ String ] value The value to set.
|
306
|
+
#
|
307
|
+
# @return [ void ]
|
308
|
+
def readdata=(value)
|
309
|
+
Curl.set_option(:readdata, value_for(value, :string), handle)
|
310
|
+
end
|
311
|
+
|
312
|
+
# Sets readfunction option.
|
313
|
+
#
|
314
|
+
# @example Set readfunction option.
|
315
|
+
# easy.readfunction = $value
|
316
|
+
#
|
317
|
+
# @param [ String ] value The value to set.
|
318
|
+
#
|
319
|
+
# @return [ void ]
|
320
|
+
def readfunction=(value)
|
321
|
+
Curl.set_option(:readfunction, value_for(value, :string), handle)
|
322
|
+
end
|
323
|
+
|
324
|
+
# Sets ssl_verifyhost option.
|
325
|
+
#
|
326
|
+
# @example Set ssl_verifyhost option.
|
327
|
+
# easy.ssl_verifyhost = 1
|
328
|
+
#
|
329
|
+
# @param [ Integer ] value The value to set.
|
330
|
+
#
|
331
|
+
# @return [ void ]
|
332
|
+
def ssl_verifyhost=(value)
|
333
|
+
Curl.set_option(:ssl_verifyhost, value_for(value, :int), handle)
|
334
|
+
end
|
335
|
+
|
336
|
+
# Sets ssl_verifypeer option.
|
337
|
+
#
|
338
|
+
# @example Set ssl_verifypeer option.
|
339
|
+
# easy.ssl_verifypeer = true
|
340
|
+
#
|
341
|
+
# @param [ Boolean ] value The value to set.
|
342
|
+
#
|
343
|
+
# @return [ void ]
|
344
|
+
def ssl_verifypeer=(value)
|
345
|
+
Curl.set_option(:ssl_verifypeer, value_for(value, :bool), handle)
|
346
|
+
end
|
347
|
+
|
348
|
+
# Sets sslcert option.
|
349
|
+
#
|
350
|
+
# @example Set sslcert option.
|
351
|
+
# easy.sslcert = $value
|
352
|
+
#
|
353
|
+
# @param [ String ] value The value to set.
|
354
|
+
#
|
355
|
+
# @return [ void ]
|
356
|
+
def sslcert=(value)
|
357
|
+
Curl.set_option(:sslcert, value_for(value, :string), handle)
|
358
|
+
end
|
359
|
+
|
360
|
+
# Sets sslcerttype option.
|
361
|
+
#
|
362
|
+
# @example Set sslcerttype option.
|
363
|
+
# easy.sslcerttype = $value
|
364
|
+
#
|
365
|
+
# @param [ String ] value The value to set.
|
366
|
+
#
|
367
|
+
# @return [ void ]
|
368
|
+
def sslcerttype=(value)
|
369
|
+
Curl.set_option(:sslcerttype, value_for(value, :string), handle)
|
370
|
+
end
|
371
|
+
|
372
|
+
# Sets sslkey option.
|
373
|
+
#
|
374
|
+
# @example Set sslkey option.
|
375
|
+
# easy.sslkey = $value
|
376
|
+
#
|
377
|
+
# @param [ String ] value The value to set.
|
378
|
+
#
|
379
|
+
# @return [ void ]
|
380
|
+
def sslkey=(value)
|
381
|
+
Curl.set_option(:sslkey, value_for(value, :string), handle)
|
382
|
+
end
|
383
|
+
|
384
|
+
# Sets sslkeytype option.
|
385
|
+
#
|
386
|
+
# @example Set sslkeytype option.
|
387
|
+
# easy.sslkeytype = $value
|
388
|
+
#
|
389
|
+
# @param [ String ] value The value to set.
|
390
|
+
#
|
391
|
+
# @return [ void ]
|
392
|
+
def sslkeytype=(value)
|
393
|
+
Curl.set_option(:sslkeytype, value_for(value, :string), handle)
|
394
|
+
end
|
395
|
+
|
396
|
+
# Sets sslversion option.
|
397
|
+
#
|
398
|
+
# @example Set sslversion option.
|
399
|
+
# easy.sslversion = $value
|
400
|
+
#
|
401
|
+
# @param [ $type_doc ] value The value to set.
|
402
|
+
#
|
403
|
+
# @return [ void ]
|
404
|
+
def sslversion=(value)
|
405
|
+
Curl.set_option(:sslversion, value_for(value, :enum, :sslversion), handle)
|
406
|
+
end
|
407
|
+
|
408
|
+
# Sets timeout option.
|
409
|
+
#
|
410
|
+
# @example Set timeout option.
|
411
|
+
# easy.timeout = 1
|
412
|
+
#
|
413
|
+
# @param [ Integer ] value The value to set.
|
414
|
+
#
|
415
|
+
# @return [ void ]
|
416
|
+
def timeout=(value)
|
417
|
+
Curl.set_option(:timeout, value_for(value, :int), handle)
|
418
|
+
end
|
419
|
+
|
420
|
+
# Sets timeout_ms option.
|
421
|
+
#
|
422
|
+
# @example Set timeout_ms option.
|
423
|
+
# easy.timeout_ms = 1
|
424
|
+
#
|
425
|
+
# @param [ Integer ] value The value to set.
|
426
|
+
#
|
427
|
+
# @return [ void ]
|
428
|
+
def timeout_ms=(value)
|
429
|
+
Curl.set_option(:timeout_ms, value_for(value, :int), handle)
|
430
|
+
end
|
431
|
+
|
432
|
+
# Sets upload option.
|
433
|
+
#
|
434
|
+
# @example Set upload option.
|
435
|
+
# easy.upload = true
|
436
|
+
#
|
437
|
+
# @param [ Boolean ] value The value to set.
|
438
|
+
#
|
439
|
+
# @return [ void ]
|
440
|
+
def upload=(value)
|
441
|
+
Curl.set_option(:upload, value_for(value, :bool), handle)
|
442
|
+
end
|
443
|
+
|
444
|
+
# Sets url option.
|
445
|
+
#
|
446
|
+
# @example Set url option.
|
447
|
+
# easy.url = $value
|
448
|
+
#
|
449
|
+
# @param [ String ] value The value to set.
|
450
|
+
#
|
451
|
+
# @return [ void ]
|
452
|
+
def url=(value)
|
453
|
+
@url = value
|
454
|
+
Curl.set_option(:url, value_for(value, :string), handle)
|
455
|
+
end
|
456
|
+
|
457
|
+
# Sets useragent option.
|
458
|
+
#
|
459
|
+
# @example Set useragent option.
|
460
|
+
# easy.useragent = $value
|
461
|
+
#
|
462
|
+
# @param [ String ] value The value to set.
|
463
|
+
#
|
464
|
+
# @return [ void ]
|
465
|
+
def useragent=(value)
|
466
|
+
Curl.set_option(:useragent, value_for(value, :string), handle)
|
467
|
+
end
|
468
|
+
|
469
|
+
# Sets userpwd option.
|
470
|
+
#
|
471
|
+
# @example Set userpwd option.
|
472
|
+
# easy.userpwd = $value
|
473
|
+
#
|
474
|
+
# @param [ String ] value The value to set.
|
475
|
+
#
|
476
|
+
# @return [ void ]
|
477
|
+
def userpwd=(value)
|
478
|
+
Curl.set_option(:userpwd, value_for(value, :string), handle)
|
479
|
+
end
|
480
|
+
|
481
|
+
# Sets verbose option.
|
482
|
+
#
|
483
|
+
# @example Set verbose option.
|
484
|
+
# easy.verbose = true
|
485
|
+
#
|
486
|
+
# @param [ Boolean ] value The value to set.
|
487
|
+
#
|
488
|
+
# @return [ void ]
|
489
|
+
def verbose=(value)
|
490
|
+
Curl.set_option(:verbose, value_for(value, :bool), handle)
|
491
|
+
end
|
492
|
+
|
493
|
+
private
|
494
|
+
|
85
495
|
# Return the value to set to easy handle. It is converted with the help
|
86
496
|
# of bool_options, enum_options and int_options.
|
87
497
|
#
|
@@ -95,19 +505,26 @@ module Ethon
|
|
95
505
|
# @raise [ Ethon::Errors::InvalidValue ] If specified option
|
96
506
|
# points to an enum and the value doen't correspond to
|
97
507
|
# the valid values.
|
98
|
-
def value_for(option)
|
99
|
-
value = method(option).call
|
508
|
+
def value_for(value, type, option = nil)
|
100
509
|
return nil if value.nil?
|
101
510
|
|
102
|
-
if
|
511
|
+
if type == :bool
|
103
512
|
value ? 1 : 0
|
104
|
-
elsif
|
105
|
-
|
513
|
+
elsif type == :int
|
514
|
+
value.to_i
|
515
|
+
elsif type == :enum && option == :httpauth
|
516
|
+
Curl::Auth.to_h.fetch(value) do
|
106
517
|
raise Errors::InvalidValue.new(option, value)
|
107
518
|
end
|
108
|
-
elsif
|
109
|
-
value
|
110
|
-
|
519
|
+
elsif type == :enum && option == :sslversion
|
520
|
+
Curl::SSLVersion.to_h.fetch(value) do
|
521
|
+
raise Errors::InvalidValue.new(option, value)
|
522
|
+
end
|
523
|
+
elsif type == :enum && option == :proxytype
|
524
|
+
Curl::Proxy.to_h.fetch(value) do
|
525
|
+
raise Errors::InvalidValue.new(option, value)
|
526
|
+
end
|
527
|
+
elsif value.is_a?(String)
|
111
528
|
Util.escape_zero_byte(value)
|
112
529
|
else
|
113
530
|
value
|
data/lib/ethon/libc.rb
ADDED
data/lib/ethon/multi.rb
CHANGED
@@ -30,16 +30,6 @@ module Ethon
|
|
30
30
|
@max_fd = ::FFI::MemoryPointer.new(:int)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Return wether the multi still requests or not.
|
34
|
-
#
|
35
|
-
# @example Return if ongoing.
|
36
|
-
# multi.ongoing?
|
37
|
-
#
|
38
|
-
# @return [ Boolean ] True if ongoing, else false.
|
39
|
-
def ongoing?
|
40
|
-
easy_handles.size > 0 || (!defined?(@running_count) || running_count > 0)
|
41
|
-
end
|
42
|
-
|
43
33
|
# Perform multi.
|
44
34
|
#
|
45
35
|
# @return [ nil ]
|
@@ -69,8 +59,26 @@ module Ethon
|
|
69
59
|
# multi.prepare
|
70
60
|
#
|
71
61
|
# @api public
|
62
|
+
#
|
63
|
+
# @deprecated It is no longer necessary to call prepare.
|
72
64
|
def prepare
|
73
|
-
|
65
|
+
Ethon.logger.warn(
|
66
|
+
"ETHON: It is no longer necessay to call "+
|
67
|
+
"Multi#prepare. Its going to be removed "+
|
68
|
+
"in future versions."
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
# Return wether the multi still requests or not.
|
75
|
+
#
|
76
|
+
# @example Return if ongoing.
|
77
|
+
# multi.ongoing?
|
78
|
+
#
|
79
|
+
# @return [ Boolean ] True if ongoing, else false.
|
80
|
+
def ongoing?
|
81
|
+
easy_handles.size > 0 || (!defined?(@running_count) || running_count > 0)
|
74
82
|
end
|
75
83
|
|
76
84
|
# Get timeout.
|
data/lib/ethon/multi/options.rb
CHANGED
@@ -5,63 +5,80 @@ module Ethon
|
|
5
5
|
# available options on multi.
|
6
6
|
module Options
|
7
7
|
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
# Sets maxconnects option.
|
9
|
+
#
|
10
|
+
# @example Set maxconnects option.
|
11
|
+
# easy.maxconnects = $value
|
12
|
+
#
|
13
|
+
# @param [ String ] value The value to set.
|
14
|
+
#
|
15
|
+
# @return [ void ]
|
16
|
+
def maxconnects=(value)
|
17
|
+
Curl.set_option(:maxconnects, value_for(value, :int), handle)
|
16
18
|
end
|
17
19
|
|
18
|
-
|
20
|
+
# Sets pipelining option.
|
21
|
+
#
|
22
|
+
# @example Set pipelining option.
|
23
|
+
# easy.pipelining = $value
|
24
|
+
#
|
25
|
+
# @param [ String ] value The value to set.
|
26
|
+
#
|
27
|
+
# @return [ void ]
|
28
|
+
def pipelining=(value)
|
29
|
+
Curl.set_option(:pipelining, value_for(value, :bool), handle)
|
30
|
+
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
# Sets socketdata option.
|
33
|
+
#
|
34
|
+
# @example Set socketdata option.
|
35
|
+
# easy.socketdata = $value
|
36
|
+
#
|
37
|
+
# @param [ String ] value The value to set.
|
38
|
+
#
|
39
|
+
# @return [ void ]
|
40
|
+
def socketdata=(value)
|
41
|
+
Curl.set_option(:socketdata, value_for(value, :string), handle)
|
42
|
+
end
|
29
43
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
# Sets socketfunction option.
|
45
|
+
#
|
46
|
+
# @example Set socketfunction option.
|
47
|
+
# easy.socketfunction = $value
|
48
|
+
#
|
49
|
+
# @param [ String ] value The value to set.
|
50
|
+
#
|
51
|
+
# @return [ void ]
|
52
|
+
def socketfunction=(value)
|
53
|
+
Curl.set_option(:socketfunction, value_for(value, :string), handle)
|
54
|
+
end
|
41
55
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
56
|
+
# Sets timerdata option.
|
57
|
+
#
|
58
|
+
# @example Set timerdata option.
|
59
|
+
# easy.timerdata = $value
|
60
|
+
#
|
61
|
+
# @param [ String ] value The value to set.
|
62
|
+
#
|
63
|
+
# @return [ void ]
|
64
|
+
def timerdata=(value)
|
65
|
+
Curl.set_option(:timerdata, value_for(value, :string), handle)
|
53
66
|
end
|
54
67
|
|
55
|
-
#
|
68
|
+
# Sets timerfunction option.
|
56
69
|
#
|
57
|
-
# @example Set
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
70
|
+
# @example Set timerfunction option.
|
71
|
+
# easy.timerfunction = $value
|
72
|
+
#
|
73
|
+
# @param [ String ] value The value to set.
|
74
|
+
#
|
75
|
+
# @return [ void ]
|
76
|
+
def timerfunction=(value)
|
77
|
+
Curl.set_option(:timerfunction, value_for(value, :string), handle)
|
63
78
|
end
|
64
79
|
|
80
|
+
private
|
81
|
+
|
65
82
|
# Return the value to set to multi handle. It is converted with the help
|
66
83
|
# of bool_options, enum_options and int_options.
|
67
84
|
#
|
@@ -69,14 +86,15 @@ module Ethon
|
|
69
86
|
# multi.value_for(:verbose)
|
70
87
|
#
|
71
88
|
# @return [ Object ] The casted value.
|
72
|
-
def value_for(option)
|
73
|
-
value = method(option).call
|
89
|
+
def value_for(value, type, option = nil)
|
74
90
|
return nil if value.nil?
|
75
91
|
|
76
|
-
if
|
92
|
+
if type == :bool
|
77
93
|
value ? 1 : 0
|
78
|
-
elsif
|
94
|
+
elsif type == :int
|
79
95
|
value.to_i
|
96
|
+
elsif value.is_a?(String)
|
97
|
+
Ethon::Easy::Util.escape_zero_byte(value)
|
80
98
|
else
|
81
99
|
value
|
82
100
|
end
|
data/lib/ethon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/ethon/errors/multi_timeout.rb
|
96
96
|
- lib/ethon/errors/select.rb
|
97
97
|
- lib/ethon/errors.rb
|
98
|
+
- lib/ethon/libc.rb
|
98
99
|
- lib/ethon/loggable.rb
|
99
100
|
- lib/ethon/multi/operations.rb
|
100
101
|
- lib/ethon/multi/options.rb
|
@@ -121,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
122
|
version: '0'
|
122
123
|
segments:
|
123
124
|
- 0
|
124
|
-
hash: -
|
125
|
+
hash: -3112365376601188521
|
125
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
127
|
none: false
|
127
128
|
requirements:
|