ethon 0.5.12 → 0.6.0

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.
Files changed (66) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +11 -0
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +1 -1
  7. data/Guardfile +9 -0
  8. data/ethon.gemspec +26 -0
  9. data/lib/ethon/curl.rb +0 -12
  10. data/lib/ethon/curls/constants.rb +6 -22
  11. data/lib/ethon/curls/functions.rb +38 -41
  12. data/lib/ethon/curls/infos.rb +19 -0
  13. data/lib/ethon/curls/options.rb +416 -219
  14. data/lib/ethon/curls/settings.rb +1 -0
  15. data/lib/ethon/easy.rb +12 -18
  16. data/lib/ethon/easy/callbacks.rb +40 -6
  17. data/lib/ethon/easy/debug_info.rb +46 -0
  18. data/lib/ethon/easy/mirror.rb +39 -0
  19. data/lib/ethon/easy/options.rb +17 -1235
  20. data/lib/ethon/easy/queryable.rb +6 -8
  21. data/lib/ethon/easy/response_callbacks.rb +1 -1
  22. data/lib/ethon/version.rb +1 -1
  23. data/profile/benchmarks.rb +137 -0
  24. data/profile/memory_leaks.rb +113 -0
  25. data/profile/perf_spec_helper.rb +36 -0
  26. data/profile/support/memory_test_helpers.rb +75 -0
  27. data/profile/support/os_memory_leak_tracker.rb +47 -0
  28. data/profile/support/ruby_object_leak_tracker.rb +48 -0
  29. data/spec/ethon/curl_spec.rb +27 -0
  30. data/spec/ethon/easy/callbacks_spec.rb +31 -0
  31. data/spec/ethon/easy/debug_info_spec.rb +52 -0
  32. data/spec/ethon/easy/form_spec.rb +76 -0
  33. data/spec/ethon/easy/header_spec.rb +78 -0
  34. data/spec/ethon/easy/http/custom_spec.rb +176 -0
  35. data/spec/ethon/easy/http/delete_spec.rb +20 -0
  36. data/spec/ethon/easy/http/get_spec.rb +89 -0
  37. data/spec/ethon/easy/http/head_spec.rb +79 -0
  38. data/spec/ethon/easy/http/options_spec.rb +50 -0
  39. data/spec/ethon/easy/http/patch_spec.rb +50 -0
  40. data/spec/ethon/easy/http/post_spec.rb +220 -0
  41. data/spec/ethon/easy/http/put_spec.rb +124 -0
  42. data/spec/ethon/easy/http_spec.rb +44 -0
  43. data/spec/ethon/easy/informations_spec.rb +82 -0
  44. data/spec/ethon/easy/mirror_spec.rb +39 -0
  45. data/spec/ethon/easy/operations_spec.rb +251 -0
  46. data/spec/ethon/easy/options_spec.rb +135 -0
  47. data/spec/ethon/easy/queryable_spec.rb +188 -0
  48. data/spec/ethon/easy/response_callbacks_spec.rb +50 -0
  49. data/spec/ethon/easy/util_spec.rb +27 -0
  50. data/spec/ethon/easy_spec.rb +105 -0
  51. data/spec/ethon/libc_spec.rb +13 -0
  52. data/spec/ethon/loggable_spec.rb +21 -0
  53. data/spec/ethon/multi/operations_spec.rb +297 -0
  54. data/spec/ethon/multi/options_spec.rb +70 -0
  55. data/spec/ethon/multi/stack_spec.rb +79 -0
  56. data/spec/ethon/multi_spec.rb +21 -0
  57. data/spec/spec_helper.rb +27 -0
  58. data/spec/support/localhost_server.rb +94 -0
  59. data/spec/support/server.rb +114 -0
  60. metadata +91 -31
  61. data/lib/ethon/curls/auth_types.rb +0 -25
  62. data/lib/ethon/curls/http_versions.rb +0 -22
  63. data/lib/ethon/curls/postredir.rb +0 -15
  64. data/lib/ethon/curls/protocols.rb +0 -36
  65. data/lib/ethon/curls/proxy_types.rb +0 -25
  66. data/lib/ethon/curls/ssl_versions.rb +0 -23
@@ -1,6 +1,7 @@
1
1
  module Ethon
2
2
  module Curl
3
3
  callback :callback, [:pointer, :size_t, :size_t, :pointer], :size_t
4
+ callback :debug_callback, [:pointer, :debug_info_type, :pointer, :size_t, :pointer], :int
4
5
  ffi_lib_flags :now, :global
5
6
  ffi_lib ['libcurl', 'libcurl.so.4']
6
7
  end
data/lib/ethon/easy.rb CHANGED
@@ -8,6 +8,8 @@ require 'ethon/easy/form'
8
8
  require 'ethon/easy/http'
9
9
  require 'ethon/easy/operations'
10
10
  require 'ethon/easy/response_callbacks'
11
+ require 'ethon/easy/debug_info'
12
+ require 'ethon/easy/mirror'
11
13
 
12
14
  module Ethon
13
15
 
@@ -245,7 +247,9 @@ module Ethon
245
247
  def reset
246
248
  @url = nil
247
249
  @hash = nil
250
+ @mirror = nil
248
251
  @on_complete = nil
252
+ @procs = nil
249
253
  Curl.easy_reset(handle)
250
254
  set_callbacks
251
255
  end
@@ -261,7 +265,7 @@ module Ethon
261
265
  #
262
266
  # @api private
263
267
  def escape(value)
264
- string_pointer = Curl.easy_escape(handle, value, 0)
268
+ string_pointer = Curl.easy_escape(handle, value, value.bytesize)
265
269
  returned_string = string_pointer.read_string
266
270
  Curl.free(string_pointer)
267
271
  returned_string
@@ -272,16 +276,12 @@ module Ethon
272
276
  #
273
277
  # @return [ Hash ] The informations hash.
274
278
  def to_hash
275
- return @hash if defined?(@hash) && @hash
276
- @hash = {
277
- :return_code => return_code,
278
- :response_headers => response_headers,
279
- :response_body => response_body
280
- }
281
- Easy::Informations::AVAILABLE_INFORMATIONS.keys.each do |info|
282
- @hash[info] = send(info)
283
- end
284
- @hash
279
+ Kernel.warn("Ethon: Easy#to_hash is deprecated and will be removed, please use #mirror.")
280
+ mirror.to_hash
281
+ end
282
+
283
+ def mirror
284
+ @mirror ||= Mirror.from_easy(self)
285
285
  end
286
286
 
287
287
  # Return pretty log out.
@@ -291,13 +291,7 @@ module Ethon
291
291
  #
292
292
  # @return [ String ] The log out.
293
293
  def log_inspect
294
- hash = {
295
- :url => url,
296
- :response_code => response_code,
297
- :return_code => return_code,
298
- :total_time => total_time
299
- }
300
- "EASY #{hash.map{|k, v| "#{k}=#{v}"}.flatten.join(' ')}"
294
+ "EASY #{mirror.log_informations.map{|k, v| "#{k}=#{v}"}.flatten.join(' ')}"
301
295
  end
302
296
  end
303
297
  end
@@ -9,7 +9,7 @@ module Ethon
9
9
 
10
10
  # :nodoc:
11
11
  def self.included(base)
12
- base.send(:attr_accessor, *[:response_body, :response_headers])
12
+ base.send(:attr_accessor, *[:response_body, :response_headers, :debug_info])
13
13
  end
14
14
 
15
15
  # Set writefunction and headerfunction callback.
@@ -21,8 +21,10 @@ module Ethon
21
21
  def set_callbacks
22
22
  Curl.set_option(:writefunction, body_write_callback, handle)
23
23
  Curl.set_option(:headerfunction, header_write_callback, handle)
24
+ Curl.set_option(:debugfunction, debug_callback, handle)
24
25
  @response_body = ""
25
26
  @response_headers = ""
27
+ @debug_info = Ethon::Easy::DebugInfo.new
26
28
  end
27
29
 
28
30
  # Returns the body write callback.
@@ -51,6 +53,22 @@ module Ethon
51
53
  }
52
54
  end
53
55
 
56
+ # Returns the debug callback. This callback is currently used
57
+ # write the raw http request headers.
58
+ #
59
+ # @example Return the callback.
60
+ # easy.body_write_callback
61
+ #
62
+ # @return [ Proc ] The callback.
63
+ def debug_callback
64
+ @debug_callback ||= proc {|handle, type, data, size, udata|
65
+ message = data.read_string(size)
66
+ @debug_info.add type, message
67
+ print message unless [:data_in, :data_out].include?(type)
68
+ 0
69
+ }
70
+ end
71
+
54
72
  # Set the read callback. This callback is used by libcurl to
55
73
  # read data when performing a PUT request.
56
74
  #
@@ -60,19 +78,35 @@ module Ethon
60
78
  # @param [ String ] body The body.
61
79
  def set_read_callback(body)
62
80
  @request_body_read = 0
63
- @read_callback = proc {|stream, size, num, object|
81
+ readfunction do |stream, size, num, object|
64
82
  size = size * num
65
- left = body.bytesize - @request_body_read
83
+ body_size = if body.respond_to?(:bytesize)
84
+ body.bytesize
85
+ elsif body.respond_to?(:size)
86
+ body.size
87
+ elsif body.is_a?(File)
88
+ File.size(body.path)
89
+ end
90
+
91
+ left = body_size - @request_body_read
66
92
  size = left if size > left
93
+
67
94
  if size > 0
95
+ chunk = if body.respond_to?(:byteslice)
96
+ body.byteslice(@request_body_read, size)
97
+ elsif body.respond_to?(:read)
98
+ body.read(size)
99
+ else
100
+ body[@request_body_read, size]
101
+ end
102
+
68
103
  stream.write_string(
69
- body.respond_to?(:byteslice) ? body.byteslice(@request_body_read, size) : body[@request_body_read, size], size
104
+ chunk, size
70
105
  )
71
106
  @request_body_read += size
72
107
  end
73
108
  size
74
- }
75
- self.readfunction = read_callback
109
+ end
76
110
  end
77
111
 
78
112
  # Returns the body read callback.
@@ -0,0 +1,46 @@
1
+ module Ethon
2
+ class Easy
3
+
4
+ # This class is used to store and retreive debug information,
5
+ # which is only saved when verbose is set to true.
6
+ #
7
+ # @api private
8
+ class DebugInfo
9
+
10
+ MESSAGE_TYPES = Ethon::Curl::DebugInfoType.to_h.keys
11
+
12
+ class Message
13
+ attr_reader :type, :message
14
+
15
+ def initialize(type, message)
16
+ @type = type
17
+ @message = message
18
+ end
19
+ end
20
+
21
+ def initialize
22
+ @messages = []
23
+ end
24
+
25
+ def add(type, message)
26
+ @messages << Message.new(type, message)
27
+ end
28
+
29
+ def messages_for(type)
30
+ @messages.select {|m| m.type == type }.map(&:message)
31
+ end
32
+
33
+ MESSAGE_TYPES.each do |type|
34
+ eval %Q|def #{type}; messages_for(:#{type}); end|
35
+ end
36
+
37
+ def to_a
38
+ @messages.map(&:message)
39
+ end
40
+
41
+ def to_h
42
+ Hash[MESSAGE_TYPES.map {|k| [k, send(k)] }]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ module Ethon
2
+ class Easy
3
+ class Mirror
4
+ attr_reader :options
5
+ alias_method :to_hash, :options
6
+
7
+ def self.informations_to_mirror
8
+ Informations::AVAILABLE_INFORMATIONS.keys +
9
+ [:return_code, :response_headers, :response_body, :debug_info]
10
+ end
11
+
12
+ def self.informations_to_log
13
+ [:url, :response_code, :return_code, :total_time]
14
+ end
15
+
16
+ def self.from_easy(easy)
17
+ options = {}
18
+ informations_to_mirror.each do |info|
19
+ options[info] = easy.send(info)
20
+ end
21
+ new(options)
22
+ end
23
+
24
+ def initialize(options = {})
25
+ @options = options
26
+ end
27
+
28
+ def log_informations
29
+ Hash[*self.class.informations_to_log.map do |info|
30
+ [info, options[info]]
31
+ end.flatten]
32
+ end
33
+
34
+ informations_to_mirror.each do |info|
35
+ eval %Q|def #{info}; options[#{info}]; end|
36
+ end
37
+ end
38
+ end
39
+ end
@@ -4,1247 +4,29 @@ module Ethon
4
4
  # This module contains the logic and knowledge about the
5
5
  # available options on easy.
6
6
  module Options
7
-
8
7
  attr_reader :url
9
8
 
10
- # Sets the contents of the Accept-Encoding: header sent in a HTTP
11
- # request, and enables decoding of a response when a
12
- # Content-Encoding: header is received. Three encodings are
13
- # supported: identity, which does nothing, deflate which requests
14
- # the server to compress its response using the zlib algorithm,
15
- # and gzip which requests the gzip algorithm. If a zero-length
16
- # string is set, then an Accept-Encoding: header containing all
17
- # supported encodings is sent.
18
- # This is a request, not an order; the server may or may not do it.
19
- # This option must be set (to any non-NULL value) or else any
20
- # unsolicited encoding done by the server is ignored. See the
21
- # special file lib/README.encoding for details.
22
- # (This option was called CURLOPT_ENCODING before 7.21.6)
23
- #
24
- # @example Set accept_encoding option.
25
- # easy.accept_encoding = "gzip"
26
- #
27
- # @param [ String ] value The value to set.
28
- #
29
- # @return [ void ]
30
- def accept_encoding=(value)
31
- Curl.set_option(:accept_encoding, value_for(value, :string), handle)
32
- end
33
-
34
- # Pass a string to a zero-terminated string naming a file holding one
35
- # or more certificates with which to verify the peer. This makes sense
36
- # only when used in combination with the CURLOPT_SSL_VERIFYPEER option.
37
- # If CURLOPT_SSL_VERIFYPEER is zero, CURLOPT_CAINFO need not even
38
- # indicate an accessible file. This option is by default set to the
39
- # system path where libcurl's cacert bundle is assumed to be stored,
40
- # as established at build time. When built against NSS, this is the
41
- # directory that the NSS certificate database resides in.
42
- #
43
- # @example Set cainfo option.
44
- # easy.cainfo = "/path/to/file"
45
- #
46
- # @param [ String ] value The value to set.
47
- #
48
- # @return [ void ]
49
- def cainfo=(value)
50
- Curl.set_option(:cainfo, value_for(value, :string), handle)
51
- end
52
-
53
- # Pass a string to a zero-terminated string naming a directory holding
54
- # multiple CA certificates with which to verify the peer. If libcurl is
55
- # built against OpenSSL, the certificate directory must be prepared using
56
- # the openssl c_rehash utility. This makes sense only when used in
57
- # combination with the CURLOPT_SSL_VERIFYPEER option. If
58
- # CURLOPT_SSL_VERIFYPEER is zero, CURLOPT_CAPATH need not even indicate
59
- # an accessible path. The CURLOPT_CAPATH function apparently does not
60
- # work in Windows due to some limitation in openssl. This option is
61
- # OpenSSL-specific and does nothing if libcurl is built to use GnuTLS.
62
- # NSS-powered libcurl provides the option only for backward
63
- # compatibility.
64
- #
65
- # @example Set capath option.
66
- # easy.capath = "/path/to/file"
67
- #
68
- # @param [ String ] value The value to set.
69
- #
70
- # @return [ void ]
71
- def capath=(value)
72
- Curl.set_option(:capath, value_for(value, :string), handle)
73
- end
74
-
75
- # Pass a long. It should contain the maximum time in seconds that you
76
- # allow the connection to the server to take. This only limits the
77
- # connection phase, once it has connected, this option is of no more
78
- # use. Set to zero to switch to the default built-in connection timeout
79
- # \- 300 seconds. See also the CURLOPT_TIMEOUT option.
80
- # In Unix-like systems, this might cause signals to be used unless
81
- # CURLOPT_NOSIGNAL is set.
82
- #
83
- # @example Set connecttimeout option.
84
- # easy.connecttimeout = 1
85
- #
86
- # @param [ Integer ] value The value to set.
87
- #
88
- # @return [ void ]
89
- def connecttimeout=(value)
90
- Curl.set_option(:connecttimeout, value_for(value, :int), handle)
91
- end
92
-
93
- # Like CURLOPT_CONNECTTIMEOUT but takes the number of milliseconds
94
- # instead. If libcurl is built to use the standard system name
95
- # resolver, that portion of the connect will still use full-second
96
- # resolution for timeouts with a minimum timeout allowed of one second.
97
- # (Added in 7.16.2)
98
- #
99
- # @example Set connecttimeout_ms option.
100
- # easy.connecttimeout_ms = 1
101
- #
102
- # @param [ Integer ] value The value to set.
103
- #
104
- # @return [ void ]
105
- def connecttimeout_ms=(value)
106
- Curl.set_option(:connecttimeout_ms, value_for(value, :int), handle)
107
- end
108
-
109
- # Sets the cookie value
110
- #
111
- # If you want to read/write the cookie from a file,
112
- # see cookiefile= and cookiejar=
113
- #
114
- # @example Set the cookie option
115
- # easy.cookie = "cookie-value"
116
- #
117
- # @param [ String ] value The cookie value
118
- #
119
- # @return [ void ]
120
- def cookie=(value)
121
- Curl.set_option(:cookie, value_for(value, :string), handle)
122
- end
123
-
124
- # Sets the cookie jar file
125
- # The file will only be used to write the cookie value
126
- # If you want to read the cookie from a file, see cookiefile=
127
- #
128
- # If the file does not exist, it will try to create it
129
- #
130
- # @example Set cookiejar option
131
- # easy.cookiejar = "/path/to/file"
132
- #
133
- # @param [ String ] file The path to the file
134
- #
135
- # @return [ void ]
136
- def cookiejar=(file)
137
- Curl.set_option(:cookiejar, value_for(file, :string), handle)
138
- end
139
-
140
- # Sets the cookie file
141
- # The file will only be used to read the cookie value
142
- # If you want to set the cookie in a file, see cookiejar=
143
- #
144
- # @example Set cookiefile option
145
- # easy.cookiefile = "/path/to/file"
146
- #
147
- # @param [ String ] file The path to the file
148
- #
149
- # @return [ void ]
150
- def cookiefile=(file)
151
- Curl.set_option(:cookiefile, value_for(file, :string), handle)
152
- end
153
-
154
- # Pass a string as parameter, which should be the full data to post in
155
- # a HTTP POST operation. It behaves as the CURLOPT_POSTFIELDS option,
156
- # but the original data are copied by the library, allowing the
157
- # application to overwrite the original data after setting this option.
158
- # Because data are copied, care must be taken when using this option in
159
- # conjunction with CURLOPT_POSTFIELDSIZE or
160
- # CURLOPT_POSTFIELDSIZE_LARGE: If the size has not been set prior to
161
- # CURLOPT_COPYPOSTFIELDS, the data are assumed to be a NUL-terminated
162
- # string; else the stored size informs the library about the data byte
163
- # count to copy. In any case, the size must not be changed after
164
- # CURLOPT_COPYPOSTFIELDS, unless another CURLOPT_POSTFIELDS or
165
- # CURLOPT_COPYPOSTFIELDS option is issued. (Added in 7.17.1)
166
- #
167
- # @example Set copypostfields option.
168
- # easy.copypostfields = "PATCH"
169
- #
170
- # @param [ String ] value The value to set.
171
- #
172
- # @return [ void ]
173
- def copypostfields=(value)
174
- Curl.set_option(:copypostfields, value_for(value, :string), handle)
175
- end
176
-
177
- # Pass a pointer to a zero-terminated string as parameter. It can be
178
- # used to specify the request instead of GET or HEAD when performing
179
- # HTTP based requests, instead of LIST and NLST when performing FTP
180
- # directory listings and instead of LIST and RETR when issuing POP3
181
- # based commands. This is particularly useful, for example, for
182
- # performing a HTTP DELETE request or a POP3 DELE command.
183
- # Please don't perform this at will, on HTTP based requests, by making
184
- # sure your server supports the command you are sending first.
185
- # When you change the request method by setting CURLOPT_CUSTOMREQUEST
186
- # to something, you don't actually change how libcurl behaves or acts
187
- # in regards to the particular request method, it will only change the
188
- # actual string sent in the request.
189
- # For example:
190
- # With the HTTP protocol, when you tell libcurl to do a HEAD request,
191
- # but then specify a GET though a custom request libcurl will still act
192
- # as if it sent a HEAD. To switch to a proper HEAD use CURLOPT_NOBODY,
193
- # to switch to a proper POST use CURLOPT_POST or CURLOPT_POSTFIELDS and
194
- # to switch to a proper GET use CURLOPT_HTTPGET.
195
- # With the POP3 protocol when you tell libcurl to use a custom request
196
- # it will behave like a LIST or RETR command was sent where it expects
197
- # data to be returned by the server. As such CURLOPT_NOBODY should be
198
- # used when specifying commands such as DELE and NOOP for example.
199
- # Restore to the internal default by setting this to NULL.
200
- # Many people have wrongly used this option to replace the entire
201
- # request with their own, including multiple headers and POST contents.
202
- # While that might work in many cases, it will cause libcurl to send
203
- # invalid requests and it could possibly confuse the remote server
204
- # badly. Use CURLOPT_POST and CURLOPT_POSTFIELDS to set POST data. Use
205
- # CURLOPT_HTTPHEADER to replace or extend the set of headers sent by
206
- # libcurl. Use CURLOPT_HTTP_VERSION to change HTTP version.
207
- # (Support for POP3 added in 7.26.0)
208
- #
209
- # @example Set customrequest option.
210
- # easy.customrequest = "PATCH"
211
- #
212
- # @param [ String ] value The value to set.
213
- #
214
- # @return [ void ]
215
- def customrequest=(value)
216
- Curl.set_option(:customrequest, value_for(value, :string), handle)
217
- end
218
-
219
- # Pass a long, this sets the timeout in seconds. Name resolutions will be
220
- # kept in memory for this number of seconds. Set to zero to completely
221
- # disable caching, or set to -1 to make the cached entries remain
222
- # forever. By default, libcurl caches this info for 60 seconds.
223
- # The name resolve functions of various libc implementations don't
224
- # re-read name server information unless explicitly told so (for
225
- # example, by calling res_init(3)). This may cause libcurl to keep
226
- # using the older server even if DHCP has updated the server info, and
227
- # this may look like a DNS cache issue to the casual libcurl-app user.
228
- #
229
- # @example Set dns_cache_timeout option.
230
- # easy.dns_cache_timeout = 1
231
- #
232
- # @param [ Integer ] value The value to set.
233
- #
234
- # @return [ void ]
235
- def dns_cache_timeout=(value)
236
- Curl.set_option(:dns_cache_timeout, value_for(value, :int), handle)
237
- end
238
-
239
- # A parameter set to 1 tells the library to follow any Location: header
240
- # that the server sends as part of a HTTP header.
241
- # This means that the library will re-send the same request on the new
242
- # location and follow new Location: headers all the way until no more
243
- # such headers are returned. CURLOPT_MAXREDIRS can be used to limit the
244
- # number of redirects libcurl will follow.
245
- # Since 7.19.4, libcurl can limit what protocols it will automatically
246
- # follow. The accepted protocols are set with CURLOPT_REDIR_PROTOCOLS
247
- # and it excludes the FILE protocol by default.
248
- #
249
- # @example Set followlocation option.
250
- # easy.followlocation = true
251
- #
252
- # @param [ Boolean ] value The value to set.
253
- #
254
- # @return [ void ]
255
- def followlocation=(value)
256
- Curl.set_option(:followlocation, value_for(value, :bool), handle)
257
- end
258
-
259
- # Pass a long. Set to 1 to make the next transfer explicitly close the
260
- # connection when done. Normally, libcurl keeps all connections alive
261
- # when done with one transfer in case a succeeding one follows that can
262
- # re-use them. This option should be used with caution and only if you
263
- # understand what it does. Set to 0 to have libcurl keep the connection
264
- # open for possible later re-use (default behavior).
265
- #
266
- # @example Set forbid_reuse option.
267
- # easy.forbid_reuse = true
268
- #
269
- # @param [ Boolean ] value The value to set.
270
- #
271
- # @return [ void ]
272
- def forbid_reuse=(value)
273
- Curl.set_option(:forbid_reuse, value_for(value, :bool), handle)
274
- end
275
-
276
- # Pass a long as parameter, which is set to a bitmask, to tell libcurl
277
- # which authentication method(s) you want it to use. The available bits
278
- # are listed below. If more than one bit is set, libcurl will first
279
- # query the site to see which authentication methods it supports and
280
- # then pick the best one you allow it to use. For some methods, this
281
- # will induce an extra network round-trip. Set the actual name and
282
- # password with the CURLOPT_USERPWD option or with the CURLOPT_USERNAME
283
- # and the CURLOPT_PASSWORD options. (Added in 7.10.6)
284
- #
285
- # @example Set httpauth option.
286
- # easy.httpauth = :basic
287
- #
288
- # @param [ $type_doc ] value The value to set.
289
- #
290
- # @return [ void ]
291
- def httpauth=(value)
292
- Curl.set_option(:httpauth, value_for(value, :enum, :httpauth), handle)
293
- end
294
-
295
- # Pass a long. If the long is 1, this forces the HTTP request to get
296
- # back to GET. Usable if a POST, HEAD, PUT, or a custom request has
297
- # been used previously using the same curl handle.
298
- # When setting CURLOPT_HTTPGET to 1, it will automatically set
299
- # CURLOPT_NOBODY to 0 (since 7.14.1).
300
- #
301
- # @example Set httpget option.
302
- # easy.httpget = true
303
- #
304
- # @param [ Boolean ] value The value to set.
305
- #
306
- # @return [ void ]
307
- def httpget=(value)
308
- Curl.set_option(:httpget, value_for(value, :bool), handle)
309
- end
310
-
311
- # Tells libcurl you want a multipart/formdata HTTP POST to be made and
312
- # you instruct what data to pass on to the server. Pass a pointer to a
313
- # linked list of curl_httppost structs as parameter. The easiest way to
314
- # create such a list, is to use curl_formadd(3) as documented. The data
315
- # in this list must remain intact until you close this curl handle
316
- # again with curl_easy_cleanup(3).
317
- # Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue"
318
- # header. You can disable this header with CURLOPT_HTTPHEADER as usual.
319
- # When setting CURLOPT_HTTPPOST, it will automatically set
320
- # CURLOPT_NOBODY to 0 (since 7.14.1).
321
- #
322
- # @example Set httppost option.
323
- # easy.httppost = value
324
- #
325
- # @param [ String ] value The value to set.
326
- #
327
- # @return [ void ]
328
- def httppost=(value)
329
- Curl.set_option(:httppost, value_for(value, :string), handle)
330
- end
331
-
332
- # Pass a long, set to one of the values described below. They force
333
- # libcurl to use the specific HTTP versions. This is not sensible
334
- # to do unless you have a good reason.
335
- #
336
- # Options:
337
- #
338
- # * :none: We don't care about what version the library uses.
339
- # libcurl will use whatever it thinks fit.
340
- # * :httpv1_0: Enforce HTTP 1.0 requests.
341
- # * :httpv1_1: Enforce HTTP 1.1 requests.
342
- #
343
- # @example Set http_version option.
344
- # easy.http_version = :httpv1_0
345
- #
346
- # @param [ Symbol ] value The value to set.
347
- #
348
- # @return [ void ]
349
- def http_version=(value)
350
- Curl.set_option(:http_version, value_for(value, :enum, :http_version), handle)
351
- end
352
-
353
- # When uploading a file to a remote site, this option should be used to
354
- # tell libcurl what the expected size of the infile is. This value
355
- # should be passed as a long. See also CURLOPT_INFILESIZE_LARGE.
356
- # For uploading using SCP, this option or CURLOPT_INFILESIZE_LARGE is
357
- # mandatory.
358
- # When sending emails using SMTP, this command can be used to specify
359
- # the optional SIZE parameter for the MAIL FROM command. (Added in
360
- # 7.23.0)
361
- # This option does not limit how much data libcurl will actually send,
362
- # as that is controlled entirely by what the read callback returns.
363
- #
364
- # @example Set infilesize option.
365
- # easy.infilesize = 1
366
- #
367
- # @param [ Integer ] value The value to set.
368
- #
369
- # @return [ void ]
370
- def infilesize=(value)
371
- Curl.set_option(:infilesize, value_for(value, :int), handle)
372
- end
373
-
374
- # Pass a string as parameter. This sets the interface name to use as
375
- # outgoing network interface. The name can be an interface name, an IP
376
- # address, or a host name.
377
- # Starting with 7.24.0: If the parameter starts with "if!" then it is
378
- # treated as only as interface name and no attempt will ever be named
379
- # to do treat it as an IP address or to do name resolution on it. If
380
- # the parameter starts with "host!" it is treated as either an IP
381
- # address or a hostname. Hostnames are resolved synchronously. Using
382
- # the if! format is highly recommended when using the multi interfaces
383
- # to avoid allowing the code to block. If "if!" is specified but the
384
- # parameter does not match an existing interface,
385
- # CURLE_INTERFACE_FAILED is returned.
386
- #
387
- # @example Set interface option.
388
- # easy.interface = "eth0"
389
- #
390
- # @param [ String ] value The value to set.
391
- #
392
- # @return [ void ]
393
- def interface=(value)
394
- Curl.set_option(:interface, value_for(value, :string), handle)
395
- end
396
-
397
- # Pass a pointer to a zero terminated string as parameter. It will be
398
- # used as the password required to use the CURLOPT_SSLKEY or
399
- # CURLOPT_SSH_PRIVATE_KEYFILE private key. You never needed a pass
400
- # phrase to load a certificate but you need one to load your private key.
401
- # (This option was known as CURLOPT_SSLKEYPASSWD up to 7.16.4 and
402
- # CURLOPT_SSLCERTPASSWD up to 7.9.2)
403
- #
404
- # @example Set keypasswd option.
405
- # easy.keypasswd = "password"
406
- #
407
- # @param [ String ] value The value to set.
408
- #
409
- # @return [ void ]
410
- def keypasswd=(value)
411
- Curl.set_option(:keypasswd, value_for(value, :string), handle)
412
- end
413
-
414
- # Pass a long. The set number will be the redirection limit. If that
415
- # many redirections have been followed, the next redirect will cause an
416
- # error (CURLE_TOO_MANY_REDIRECTS). This option only makes sense if the
417
- # CURLOPT_FOLLOWLOCATION is used at the same time. Added in 7.15.1:
418
- # Setting the limit to 0 will make libcurl refuse any redirect. Set it
419
- # to -1 for an infinite number of redirects (which is the default)
420
- #
421
- # @example Set maxredirs option.
422
- # easy.maxredirs = 1
423
- #
424
- # @param [ Integer ] value The value to set.
425
- #
426
- # @return [ void ]
427
- def maxredirs=(value)
428
- Curl.set_option(:maxredirs, value_for(value, :int), handle)
429
- end
430
-
431
- # Pass a curl_off_t as parameter. If an upload exceeds this speed
432
- # (counted in bytes per second) on cumulative average during the
433
- # transfer, the transfer will pause to keep the average rate less than or
434
- # equal to the parameter value. Defaults to unlimited speed. (Added in
435
- # 7.15.5)
436
- #
437
- # @example Set max_send_speed_large option.
438
- # easy.max_send_speed_large = 1
439
- #
440
- # @param [ Integer ] value The value to set.
441
- #
442
- # @return [ void ]
443
- def max_send_speed_large=(value)
444
- Curl.set_option(:max_send_speed_large, value_for(value, :int), handle)
445
- end
446
-
447
- # Pass a curl_off_t as parameter. If a download exceeds this speed
448
- # (counted in bytes per second) on cumulative average during the
449
- # transfer, the transfer will pause to keep the average rate less than or
450
- # equal to the parameter value. Defaults to unlimited speed. (Added in
451
- # 7.15.5)
452
- #
453
- # @example Set max_recv_speed_large option.
454
- # easy.max_recv_speed_large = 1
455
- #
456
- # @param [ Integer ] value The value to set.
457
- #
458
- # @return [ void ]
459
- def max_recv_speed_large=(value)
460
- Curl.set_option(:max_recv_speed_large, value_for(value, :int), handle)
461
- end
462
-
463
- # A parameter set to 1 tells the library to not include the body-part
464
- # in the output. This is only relevant for protocols that have separate
465
- # header and body parts. On HTTP(S) servers, this will make libcurl do
466
- # a HEAD request.
467
- # To change request to GET, you should use CURLOPT_HTTPGET. Change
468
- # request to POST with CURLOPT_POST etc.
469
- #
470
- # @example Set nobody option.
471
- # easy.nobody = true
472
- #
473
- # @param [ Boolean ] value The value to set.
474
- #
475
- # @return [ void ]
476
- def nobody=(value)
477
- Curl.set_option(:nobody, value_for(value, :bool), handle)
478
- end
479
-
480
- # Pass a long. If it is 1, libcurl will not use any functions that
481
- # install signal handlers or any functions that cause signals to be
482
- # sent to the process. This option is mainly here to allow
483
- # multi-threaded unix applications to still set/use all timeout options
484
- # etc, without risking getting signals. (Added in 7.10)
485
- # If this option is set and libcurl has been built with the standard
486
- # name resolver, timeouts will not occur while the name resolve takes
487
- # place. Consider building libcurl with c-ares support to enable
488
- # asynchronous DNS lookups, which enables nice timeouts for name
489
- # resolves without signals.
490
- # Setting CURLOPT_NOSIGNAL to 1 makes libcurl NOT ask the system to
491
- # ignore SIGPIPE signals, which otherwise are sent by the system when
492
- # trying to send data to a socket which is closed in the other end.
493
- # libcurl makes an effort to never cause such SIGPIPEs to trigger, but
494
- # some operating systems have no way to avoid them and even on those
495
- # that have there are some corner cases when they may still happen,
496
- # contrary to our desire. In addition, using CURLAUTH_NTLM_WB
497
- # authentication could cause a SIGCHLD signal to be raised.
498
- #
499
- # @example Set nosignal option.
500
- # easy.nosignal = true
501
- #
502
- # @param [ Boolean ] value The value to set.
503
- #
504
- # @return [ void ]
505
- def nosignal=(value)
506
- Curl.set_option(:nosignal, value_for(value, :bool), handle)
507
- end
508
-
509
- # If you want to post data to the server without letting libcurl do a
510
- # strlen() to measure the data size, this option must be used. When
511
- # this option is used you can post fully binary data, which otherwise
512
- # is likely to fail. If this size is set to -1, the library will use
513
- # strlen() to get the size.
514
- #
515
- # @example Set postfieldsize option.
516
- # easy.postfieldsize = 1
517
- #
518
- # @param [ Integer ] value The value to set.
519
- #
520
- # @return [ void ]
521
- def postfieldsize=(value)
522
- Curl.set_option(:postfieldsize, value_for(value, :int), handle)
523
- end
524
-
525
- # Pass a bitmask to control how libcurl acts on redirects after
526
- # POSTs that get a 301, 302 or 303 response back. A parameter
527
- # with bit 0 set (value CURL_REDIR_POST_301) tells the library
528
- # to respect RFC 2616/10.3.2 and not convert POST requests into
529
- # GET requests when following a 301 redirection. Setting bit 1
530
- # (value CURL_REDIR_POST_302) makes libcurl maintain the request
531
- # method after a 302 redirect whilst setting bit 2 (value
532
- # CURL_REDIR_POST_303) makes libcurl maintain the request method
533
- # after a 303 redirect. The value CURL_REDIR_POST_ALL is a
534
- # convenience define that sets all three bits.
535
- #
536
- # The non-RFC behaviour is ubiquitous in web browsers, so the
537
- # library does the conversion by default to maintain
538
- # consistency. However, a server may require a POST to remain a
539
- # POST after such a redirection. This option is meaningful only
540
- # when setting CURLOPT_FOLLOWLOCATION. (Added in 7.17.1) (This
541
- # option was known as CURLOPT_POST301 up to 7.19.0 as it only
542
- # supported the 301 then)
543
- #
544
- # @example Set postredir option.
545
- # easy.postredir = :post_all
546
- #
547
- # @param [ Symbol ] value The value to set.
548
- #
549
- # @return [ void ]
550
- def postredir=(value)
551
- Curl.set_option(:postredir, value_for(value, :enum, :postredir), handle)
552
- end
553
-
554
- # Pass a long that holds a bitmask of CURLPROTO_* defines. If used, this
555
- # bitmask limits what protocols libcurl may use in the transfer. This
556
- # allows you to have a libcurl built to support a wide range of protocols
557
- # but still limit specific transfers to only be allowed to use a subset
558
- # of them. By default libcurl will accept all protocols it supports. See
559
- # also CURLOPT_REDIR_PROTOCOLS. (Added in 7.19.4)
560
- #
561
- # @example Set protocols option.
562
- # easy.protocols = :http
563
- #
564
- # @param [ Symbol ] value The value or array of values to set.
565
- #
566
- # @return [ void ]
567
- def protocols=(value)
568
- Curl.set_option(:protocols, value_for(value, :enum, :protocols), handle)
569
- end
570
-
571
- # Pass a long that holds a bitmask of CURLPROTO_* defines. If used, this
572
- # bitmask limits what protocols libcurl may use in a transfer that it
573
- # follows to in a redirect when CURLOPT_FOLLOWLOCATION is enabled. This
574
- # allows you to limit specific transfers to only be allowed to use a
575
- # subset of protocols in redirections. By default libcurl will allow all
576
- # protocols except for FILE and SCP. This is a difference compared to
577
- # pre-7.19.4 versions which unconditionally would follow to all protocols
578
- # supported. (Added in 7.19.4)
579
- #
580
- # @example Set redir_protocols option.
581
- # easy.redir_protocols = :http
582
- #
583
- # @param [ Symbol ] value The value or array of values to set.
584
- #
585
- # @return [ void ]
586
- def redir_protocols=(value)
587
- Curl.set_option(:redir_protocols, value_for(value, :enum, :redir_protocols), handle)
588
- end
589
-
590
- # Set HTTP proxy to use. The parameter should be a string to a zero
591
- # terminated string holding the host name or dotted IP address. To
592
- # specify port number in this string, append :[port] to the end of the
593
- # host name. The proxy string may be prefixed with [protocol]:// since
594
- # any such prefix will be ignored. The proxy's port number may
595
- # optionally be specified with the separate option. If not specified,
596
- # libcurl will default to using port 1080 for proxies.
597
- # CURLOPT_PROXYPORT.
598
- # When you tell the library to use a HTTP proxy, libcurl will
599
- # transparently convert operations to HTTP even if you specify an FTP
600
- # URL etc. This may have an impact on what other features of the
601
- # library you can use, such as CURLOPT_QUOTE and similar FTP specifics
602
- # that don't work unless you tunnel through the HTTP proxy. Such
603
- # tunneling is activated with CURLOPT_HTTPPROXYTUNNEL.
604
- # libcurl respects the environment variables http_proxy, ftp_proxy,
605
- # all_proxy etc, if any of those are set. The CURLOPT_PROXY option does
606
- # however override any possibly set environment variables.
607
- # Setting the proxy string to "" (an empty string) will explicitly
608
- # disable the use of a proxy, even if there is an environment variable
609
- # set for it.
610
- # Since 7.14.1, the proxy host string given in environment variables
611
- # can be specified the exact same way as the proxy can be set with
612
- # CURLOPT_PROXY, include protocol prefix (http://) and embedded user +
613
- # password.
614
- # Since 7.21.7, the proxy string may be specified with a protocol://
615
- # prefix to specify alternative proxy protocols. Use socks4://,
616
- # socks4a://, socks5:// or socks5h:// (the last one to enable socks5
617
- # and asking the proxy to do the resolving, also known as
618
- # CURLPROXY_SOCKS5_HOSTNAME type) to request the specific SOCKS version
619
- # to be used. No protocol specified, http:// and all others will be
620
- # treated as HTTP proxies.
621
- #
622
- # @example Set proxy option.
623
- # easy.proxy = "socks5://27.0.0.1:9050"
624
- #
625
- # @param [ String ] value The value to set.
626
- #
627
- # @return [ void ]
628
- def proxy=(value)
629
- Curl.set_option(:proxy, value_for(value, :string), handle)
630
- end
631
-
632
- # Pass a long as parameter, which is set to a bitmask, to tell libcurl
633
- # which authentication method(s) you want it to use for your proxy
634
- # authentication. If more than one bit is set, libcurl will first query
635
- # the site to see what authentication methods it supports and then pick
636
- # the best one you allow it to use. For some methods, this will induce
637
- # an extra network round-trip. Set the actual name and password with
638
- # the CURLOPT_PROXYUSERPWD option. The bitmask can be constructed by
639
- # or'ing together the bits listed above for the CURLOPT_HTTPAUTH
640
- # option. As of this writing, only Basic, Digest and NTLM work. (Added
641
- # in 7.10.7)
642
- #
643
- # @example Set proxyauth option.
644
- # easy.proxyauth = value
645
- #
646
- # @param [ String ] value The value to set.
647
- #
648
- # @return [ void ]
649
- def proxyauth=(value)
650
- Curl.set_option(:proxyauth, value_for(value, :string), handle)
651
- end
652
-
653
- # Pass a long with this option to set the proxy port to connect to
654
- # unless it is specified in the proxy string CURLOPT_PROXY.
655
- #
656
- # @example Set proxyport option.
657
- # easy.proxyport = 1
658
- #
659
- # @param [ Integer ] value The value to set.
660
- #
661
- # @return [ void ]
662
- def proxyport=(value)
663
- Curl.set_option(:proxyport, value_for(value, :int), handle)
664
- end
665
-
666
- # Pass a long with this option to set type of the proxy. Available
667
- # options for this are CURLPROXY_HTTP, CURLPROXY_HTTP_1_0 (added in
668
- # 7.19.4), CURLPROXY_SOCKS4 (added in 7.10), CURLPROXY_SOCKS5,
669
- # CURLPROXY_SOCKS4A (added in 7.18.0) and CURLPROXY_SOCKS5_HOSTNAME
670
- # (added in 7.18.0). The HTTP type is default. (Added in 7.10)
671
- # If you set CURLOPT_PROXYTYPE to CURLPROXY_HTTP_1_0, it will only
672
- # affect how libcurl speaks to a proxy when CONNECT is used. The HTTP
673
- # version used for "regular" HTTP requests is instead controlled with
674
- # CURLOPT_HTTP_VERSION.
675
- #
676
- # @example Set proxytype option.
677
- # easy.proxytype = :socks5
678
- #
679
- # @param [ String ] value The value to set.
680
- #
681
- # @return [ void ]
682
- #
683
- # @deprecated Please use the proxy option with protocoll handler.
684
- def proxytype=(value)
685
- Ethon.logger.warn(
686
- "ETHON: Easy#proxytype= is deprecated. "+
687
- "Please use Easy#proxy= with protocoll handlers."
688
- )
689
- Curl.set_option(:proxytype, value_for(value, :string), handle)
690
- end
691
-
692
- # Pass a string as parameter, which should be [user name]:[password]
693
- # to use for the connection to the HTTP proxy. Use CURLOPT_PROXYAUTH
694
- # to decide the authentication method.
695
- #
696
- # @example Set proxyuserpwd option.
697
- # easy.proxyuserpwd = "user:password"
698
- #
699
- # @param [ String ] value The value to set.
700
- #
701
- # @return [ void ]
702
- def proxyuserpwd=(value)
703
- Curl.set_option(:proxyuserpwd, value_for(value, :string), handle)
704
- end
705
-
706
- # Data pointer to pass to the file read function. If you use the
707
- # CURLOPT_READFUNCTION option, this is the pointer you'll get as input.
708
- # If you don't specify a read callback but instead rely on the default
709
- # internal read function, this data must be a valid readable FILE *.
710
- # If you're using libcurl as a win32 DLL, you MUST use a
711
- # CURLOPT_READFUNCTION if you set this option.
712
- # This option was also known by the older name CURLOPT_INFILE,
713
- # the name CURLOPT_READDATA was introduced in 7.9.7.
714
- #
715
- # @example Set readdata option.
716
- # easy.readdata = value
717
- #
718
- # @param [ String ] value The value to set.
719
- #
720
- # @return [ void ]
721
- def readdata=(value)
722
- Curl.set_option(:readdata, value_for(value, :string), handle)
723
- end
724
-
725
- # Pass a pointer to a function that matches the following prototype:
726
- # size_t function( void *ptr, size_t size, size_t nmemb, void
727
- # *userdata); This function gets called by libcurl as soon as it needs
728
- # to read data in order to send it to the peer. The data area pointed
729
- # at by the pointer ptr may be filled with at most size multiplied with
730
- # nmemb number of bytes. Your function must return the actual number of
731
- # bytes that you stored in that memory area. Returning 0 will signal
732
- # end-of-file to the library and cause it to stop the current transfer.
733
- # If you stop the current transfer by returning 0 "pre-maturely" (i.e
734
- # before the server expected it, like when you've said you will upload
735
- # N bytes and you upload less than N bytes), you may experience that
736
- # the server "hangs" waiting for the rest of the data that won't come.
737
- # The read callback may return CURL_READFUNC_ABORT to stop the current
738
- # operation immediately, resulting in a CURLE_ABORTED_BY_CALLBACK error
739
- # code from the transfer (Added in 7.12.1)
740
- # From 7.18.0, the function can return CURL_READFUNC_PAUSE which then
741
- # will cause reading from this connection to become paused. See
742
- # curl_easy_pause(3) for further details.
743
- # Bugs: when doing TFTP uploads, you must return the exact amount of
744
- # data that the callback wants, or it will be considered the final
745
- # packet by the server end and the transfer will end there.
746
- # If you set this callback pointer to NULL, or don't set it at all, the
747
- # default internal read function will be used. It is doing an fread()
748
- # on the FILE * userdata set with CURLOPT_READDATA.
749
- #
750
- # @example Set readfunction option.
751
- # easy.readfunction = value
752
- #
753
- # @param [ String ] value The value to set.
754
- #
755
- # @return [ void ]
756
- def readfunction=(value)
757
- Curl.set_option(:readfunction, value_for(value, :string), handle)
758
- end
759
-
760
- # Pass a long as parameter.
761
- # This option determines whether libcurl verifies that the server cert
762
- # is for the server it is known as.
763
- # When negotiating a SSL connection, the server sends a certificate
764
- # indicating its identity.
765
- # When CURLOPT_SSL_VERIFYHOST is 2, that certificate must indicate that
766
- # the server is the server to which you meant to connect, or the
767
- # connection fails.
768
- # Curl considers the server the intended one when the Common Name field
769
- # or a Subject Alternate Name field in the certificate matches the host
770
- # name in the URL to which you told Curl to connect.
771
- # When the value is 1, the certificate must contain a Common Name
772
- # field, but it doesn't matter what name it says. (This is not
773
- # ordinarily a useful setting).
774
- # When the value is 0, the connection succeeds regardless of the names
775
- # in the certificate.
776
- # The default value for this option is 2.
777
- # This option controls checking the server's certificate's claimed
778
- # identity. The server could be lying. To control lying, see
779
- # CURLOPT_SSL_VERIFYPEER. If libcurl is built against NSS and
780
- # CURLOPT_SSL_VERIFYPEER is zero, CURLOPT_SSL_VERIFYHOST is ignored.
781
- #
782
- # @example Set ssl_verifyhost option.
783
- # easy.ssl_verifyhost = 1
784
- #
785
- # @param [ Integer ] value The value to set.
786
- #
787
- # @return [ void ]
788
- def ssl_verifyhost=(value)
789
- Curl.set_option(:ssl_verifyhost, value_for(value, :int), handle)
790
- end
791
-
792
- # Pass a long as parameter. By default, curl assumes a value of 1.
793
- # This option determines whether curl verifies the authenticity of the
794
- # peer's certificate. A value of 1 means curl verifies; 0 (zero) means
795
- # it doesn't.
796
- # When negotiating a SSL connection, the server sends a certificate
797
- # indicating its identity. Curl verifies whether the certificate is
798
- # authentic, i.e. that you can trust that the server is who the
799
- # certificate says it is. This trust is based on a chain of digital
800
- # signatures, rooted in certification authority (CA) certificates you
801
- # supply. curl uses a default bundle of CA certificates (the path for
802
- # that is determined at build time) and you can specify alternate
803
- # certificates with the CURLOPT_CAINFO option or the CURLOPT_CAPATH
804
- # option.
805
- # When CURLOPT_SSL_VERIFYPEER is nonzero, and the verification fails to
806
- # prove that the certificate is authentic, the connection fails. When
807
- # the option is zero, the peer certificate verification succeeds
808
- # regardless.
809
- # Authenticating the certificate is not by itself very useful. You
810
- # typically want to ensure that the server, as authentically identified
811
- # by its certificate, is the server you mean to be talking to. Use
812
- # CURLOPT_SSL_VERIFYHOST to control that. The check that the host name
813
- # in the certificate is valid for the host name you're connecting to is
814
- # done independently of the CURLOPT_SSL_VERIFYPEER option.
815
- #
816
- # @example Set ssl_verifypeer option.
817
- # easy.ssl_verifypeer = true
818
- #
819
- # @param [ Boolean ] value The value to set.
820
- #
821
- # @return [ void ]
822
- def ssl_verifypeer=(value)
823
- Curl.set_option(:ssl_verifypeer, value_for(value, :bool), handle)
824
- end
825
-
826
- # Pass a pointer to a zero terminated string as parameter. The string
827
- # should be the file name of your certificate. The default format is
828
- # "PEM" and can be changed with CURLOPT_SSLCERTTYPE.
829
- # With NSS this can also be the nickname of the certificate you wish to
830
- # authenticate with. If you want to use a file from the current
831
- # directory, please precede it with "./" prefix, in order to avoid
832
- # confusion with a nickname.
833
- #
834
- # @example Set sslcert option.
835
- # easy.sslcert = "name"
836
- #
837
- # @param [ String ] value The value to set.
838
- #
839
- # @return [ void ]
840
- def sslcert=(value)
841
- Curl.set_option(:sslcert, value_for(value, :string), handle)
842
- end
843
-
844
- # Pass a pointer to a zero terminated string as parameter. The string
845
- # should be the format of your certificate. Supported formats are "PEM"
846
- # and "DER". (Added in 7.9.3)
847
- #
848
- # @example Set sslcerttype option.
849
- # easy.sslcerttype = "PEM"
850
- #
851
- # @param [ String ] value The value to set.
852
- #
853
- # @return [ void ]
854
- def sslcerttype=(value)
855
- Curl.set_option(:sslcerttype, value_for(value, :string), handle)
856
- end
857
-
858
- # Pass a pointer to a zero terminated string as parameter. The string
859
- # should be the file name of your private key. The default format is
860
- # "PEM" and can be changed with CURLOPT_SSLKEYTYPE.
861
- #
862
- # @example Set sslkey option.
863
- # easy.sslkey = "/path/to/file"
864
- #
865
- # @param [ String ] value The value to set.
866
- #
867
- # @return [ void ]
868
- def sslkey=(value)
869
- Curl.set_option(:sslkey, value_for(value, :string), handle)
870
- end
871
-
872
- # Pass a pointer to a zero terminated string as parameter. The string
873
- # should be the format of your private key. Supported formats are
874
- # "PEM", "DER" and "ENG".
875
- # The format "ENG" enables you to load the private key from a crypto
876
- # engine. In this case CURLOPT_SSLKEY is used as an identifier passed
877
- # to the engine. You have to set the crypto engine with
878
- # CURLOPT_SSLENGINE. "DER" format key file currently does not work
879
- # because of a bug in OpenSSL.
880
- #
881
- # @example Set sslkeytype option.
882
- # easy.sslkeytype = "PEM"
883
- #
884
- # @param [ String ] value The value to set.
885
- #
886
- # @return [ void ]
887
- def sslkeytype=(value)
888
- Curl.set_option(:sslkeytype, value_for(value, :string), handle)
889
- end
890
-
891
- # Pass a long as parameter to control what version of SSL/TLS to
892
- # attempt to use. The available options are:
893
- # Sets sslversion option.
894
- #
895
- # @example Set sslversion option.
896
- # easy.sslversion = :sslv3
897
- #
898
- # @param [ $type_doc ] value The value to set.
899
- #
900
- # @return [ void ]
901
- def sslversion=(value)
902
- Curl.set_option(:sslversion, value_for(value, :enum, :sslversion), handle)
903
- end
904
-
905
- # Pass a long as parameter containing the maximum time in seconds that
906
- # you allow the libcurl transfer operation to take. Normally, name
907
- # lookups can take a considerable time and limiting operations to less
908
- # than a few minutes risk aborting perfectly normal operations. This
909
- # option will cause curl to use the SIGALRM to enable time-outing
910
- # system calls.
911
- # In unix-like systems, this might cause signals to be used unless
912
- # CURLOPT_NOSIGNAL is set.
913
- # Default timeout is 0 (zero) which means it never times out.
914
- #
915
- # @example Set timeout option.
916
- # easy.timeout = 1
917
- #
918
- # @param [ Integer ] value The value to set.
919
- #
920
- # @return [ void ]
921
- def timeout=(value)
922
- Curl.set_option(:timeout, value_for(value, :int), handle)
923
- end
924
-
925
- # Like CURLOPT_TIMEOUT but takes number of milliseconds instead. If
926
- # libcurl is built to use the standard system name resolver, that
927
- # portion of the transfer will still use full-second resolution for
928
- # timeouts with a minimum timeout allowed of one second. (Added in
929
- # 7.16.2)
930
- #
931
- # @example Set timeout_ms option.
932
- # easy.timeout_ms = 1
933
- #
934
- # @param [ Integer ] value The value to set.
935
- #
936
- # @return [ void ]
937
- def timeout_ms=(value)
938
- Curl.set_option(:timeout_ms, value_for(value, :int), handle)
939
- end
940
-
941
- # A parameter set to 1 tells the library it can continue to send
942
- # authentication (user+password) when following locations, even
943
- # when hostname changed. This option is meaningful only when setting
944
- # CURLOPT_FOLLOWLOCATION.
945
- #
946
- # @example Set unrestricted auth.
947
- # easy.unrestricted_auth = true
948
- #
949
- # @param [ Boolean ] value The value to set.
950
- #
951
- # @return [ void ]
952
- def unrestricted_auth=(value)
953
- Curl.set_option(:unrestricted_auth, value_for(value, :bool), handle)
954
- end
955
-
956
- # A parameter set to 1 tells the library to prepare for an upload. The
957
- # CURLOPT_READDATA and CURLOPT_INFILESIZE or CURLOPT_INFILESIZE_LARGE
958
- # options are also interesting for uploads. If the protocol is HTTP,
959
- # uploading means using the PUT request unless you tell libcurl
960
- # otherwise.
961
- # Using PUT with HTTP 1.1 implies the use of a "Expect: 100-continue"
962
- # header. You can disable this header with CURLOPT_HTTPHEADER as usual.
963
- # If you use PUT to a HTTP 1.1 server, you can upload data without
964
- # knowing the size before starting the transfer if you use chunked
965
- # encoding. You enable this by adding a header like "Transfer-Encoding:
966
- # chunked" with CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked
967
- # transfer, you must specify the size.
968
- #
969
- # @example Set upload option.
970
- # easy.upload = true
971
- #
972
- # @param [ Boolean ] value The value to set.
973
- #
974
- # @return [ void ]
975
- def upload=(value)
976
- Curl.set_option(:upload, value_for(value, :bool), handle)
977
- end
978
-
979
- # Pass in a pointer to the actual URL to deal with. The parameter
980
- # should be a string to a zero terminated string which must be
981
- # URL-encoded in the following format:
982
- # scheme://host:port/path
983
- # For a greater explanation of the format please see RFC 3986.
984
- # If the given URL lacks the scheme, or protocol, part ("http://" or
985
- # "ftp://" etc), libcurl will attempt to resolve which protocol to use
986
- # based on the given host mame. If the protocol is not supported,
987
- # libcurl will return (CURLE_UNSUPPORTED_PROTOCOL) when you call
988
- # curl_easy_perform(3) or curl_multi_perform(3). Use
989
- # curl_version_info(3) for detailed information on which protocols are
990
- # supported.
991
- # The host part of the URL contains the address of the server that you
992
- # want to connect to. This can be the fully qualified domain name of
993
- # the server, the local network name of the machine on your network or
994
- # the IP address of the server or machine represented by either an IPv4
995
- # or IPv6 address. For example:
996
- # http://www.example.com/
997
- # http://hostname/
998
- # http://192.168.0.1/
999
- # http://[2001:1890:1112:1::20]/
1000
- # It is also possible to specify the user name and password as part of
1001
- # the host, for some protocols, when connecting to servers that require
1002
- # authentication.
1003
- # For example the following types of authentication support this:
1004
- # http://user:password@www.example.com
1005
- # ftp://user:password@ftp.example.com
1006
- # pop3://user:password@mail.example.com
1007
- # The port is optional and when not specified libcurl will use the
1008
- # default port based on the determined or specified protocol: 80 for
1009
- # HTTP, 21 for FTP and 25 for SMTP, etc. The following examples show
1010
- # how to specify the port:
1011
- # http://www.example.com:8080/ - This will connect to a web server
1012
- # using port 8080 rather than 80.
1013
- # smtp://mail.example.com:587/ - This will connect to a SMTP server on
1014
- # the alternative mail port.
1015
- # The path part of the URL is protocol specific and whilst some
1016
- # examples are given below this list is not conclusive:
1017
- # HTTP
1018
- # The path part of a HTTP request specifies the file to retrieve and
1019
- # from what directory. If the directory is not specified then the web
1020
- # server's root directory is used. If the file is omitted then the
1021
- # default document will be retrieved for either the directory specified
1022
- # or the root directory. The exact resource returned for each URL is
1023
- # entirely dependent on the server's configuration.
1024
- # http://www.example.com - This gets the main page from the web server.
1025
- # http://www.example.com/index.html - This returns the main page by
1026
- # explicitly requesting it.
1027
- # http://www.example.com/contactus/ - This returns the default document
1028
- # from the contactus directory.
1029
- # FTP
1030
- # The path part of an FTP request specifies the file to retrieve and
1031
- # from what directory. If the file part is omitted then libcurl
1032
- # downloads the directory listing for the directory specified. If the
1033
- # directory is omitted then the directory listing for the root / home
1034
- # directory will be returned.
1035
- # ftp://ftp.example.com - This retrieves the directory listing for the
1036
- # root directory.
1037
- # ftp://ftp.example.com/readme.txt - This downloads the file readme.txt
1038
- # from the root directory.
1039
- # ftp://ftp.example.com/libcurl/readme.txt - This downloads readme.txt
1040
- # from the libcurl directory.
1041
- # ftp://user:password@ftp.example.com/readme.txt - This retrieves the
1042
- # readme.txt file from the user's home directory. When a username and
1043
- # password is specified, everything that is specified in the path part
1044
- # is relative to the user's home directory. To retrieve files from the
1045
- # root directory or a directory underneath the root directory then the
1046
- # absolute path must be specified by prepending an additional forward
1047
- # slash to the beginning of the path.
1048
- # ftp://user:password@ftp.example.com//readme.txt - This retrieves the
1049
- # readme.txt from the root directory when logging in as a specified
1050
- # user.
1051
- # SMTP
1052
- # The path part of a SMTP request specifies the host name to present
1053
- # during communication with the mail server. If the path is omitted
1054
- # then libcurl will attempt to resolve the local computer's host name.
1055
- # However, this may not return the fully qualified domain name that is
1056
- # required by some mail servers and specifying this path allows you to
1057
- # set an alternative name, such as your machine's fully qualified
1058
- # domain name, which you might have obtained from an external function
1059
- # such as gethostname or getaddrinfo.
1060
- # smtp://mail.example.com - This connects to the mail server at
1061
- # example.com and sends your local computer's host name in the HELO /
1062
- # EHLO command.
1063
- # smtp://mail.example.com/client.example.com - This will send
1064
- # client.example.com in the HELO / EHLO command to the mail server at
1065
- # example.com.
1066
- # POP3
1067
- # The path part of a POP3 request specifies the mailbox (message) to
1068
- # retrieve. If the mailbox is not specified then a list of waiting
1069
- # messages is returned instead.
1070
- # pop3://user:password@mail.example.com - This lists the available
1071
- # messages pop3://user:password@mail.example.com/1 - This retrieves the
1072
- # first message
1073
- # SCP
1074
- # The path part of a SCP request specifies the file to retrieve and
1075
- # from what directory. The file part may not be omitted. The file is
1076
- # taken as an absolute path from the root directory on the server. To
1077
- # specify a path relative to the user's home directory on the server,
1078
- # prepend ~/ to the path portion. If the user name is not embedded in
1079
- # the URL, it can be set with the CURLOPT_USERPWD or CURLOPT_USERNAME
1080
- # option.
1081
- # scp://user@example.com/etc/issue - This specifies the file /etc/issue
1082
- # scp://example.com/~/my-file - This specifies the file my-file in the
1083
- # user's home directory on the server
1084
- # SFTP
1085
- # The path part of a SFTP request specifies the file to retrieve and
1086
- # from what directory. If the file part is omitted then libcurl
1087
- # downloads the directory listing for the directory specified. If the
1088
- # path ends in a / then a directory listing is returned instead of a
1089
- # file. If the path is omitted entirely then the directory listing for
1090
- # the root / home directory will be returned. If the user name is not
1091
- # embedded in the URL, it can be set with the CURLOPT_USERPWD or
1092
- # CURLOPT_USERNAME option.
1093
- # sftp://user:password@example.com/etc/issue - This specifies the file
1094
- # /etc/issue
1095
- # sftp://user@example.com/~/my-file - This specifies the file my-file
1096
- # in the user's home directory
1097
- # sftp://ssh.example.com/~/Documents/ - This requests a directory
1098
- # listing of the Documents directory under the user's home directory
1099
- # LDAP
1100
- # The path part of a LDAP request can be used to specify the:
1101
- # Distinguished Name, Attributes, Scope, Filter and Extension for a
1102
- # LDAP search. Each field is separated by a question mark and when that
1103
- # field is not required an empty string with the question mark
1104
- # separator should be included.
1105
- # ldap://ldap.example.com/o=My%20Organisation - This will perform a
1106
- # LDAP search with the DN as My Organisation.
1107
- # ldap://ldap.example.com/o=My%20Organisation?postalAddress - This will
1108
- # perform the same search but will only return postalAddress attributes.
1109
- # ldap://ldap.example.com/?rootDomainNamingContext - This specifies an
1110
- # empty DN and requests information about the rootDomainNamingContext
1111
- # attribute for an Active Directory server.
1112
- # For more information about the individual components of a LDAP URL
1113
- # please see RFC 4516.
1114
- # NOTES
1115
- # Starting with version 7.20.0, the fragment part of the URI will not
1116
- # be sent as part of the path, which was previously the case.
1117
- # CURLOPT_URL is the only option that must be set before
1118
- # curl_easy_perform(3) is called.
1119
- # CURLOPT_PROTOCOLS can be used to limit what protocols libcurl will
1120
- # use for this transfer, independent of what libcurl has been compiled
1121
- # to support. That may be useful if you accept the URL from an external
1122
- # source and want to limit the accessibility.
1123
- #
1124
- # @example Set url option.
1125
- # easy.url = "www.example.com"
1126
- #
1127
- # @param [ String ] value The value to set.
1128
- #
1129
- # @return [ void ]
1130
9
  def url=(value)
1131
10
  @url = value
1132
- Curl.set_option(:url, value_for(value, :string), handle)
1133
- end
1134
-
1135
- # Pass a pointer to a zero terminated string as parameter. It will be
1136
- # used to set the User-Agent: header in the http request sent to the
1137
- # remote server. This can be used to fool servers or scripts. You can
1138
- # also set any custom header with CURLOPT_HTTPHEADER.
1139
- #
1140
- # @example Set useragent option.
1141
- # easy.useragent = "UserAgent"
1142
- #
1143
- # @param [ String ] value The value to set.
1144
- #
1145
- # @return [ void ]
1146
- def useragent=(value)
1147
- Curl.set_option(:useragent, value_for(value, :string), handle)
1148
- end
1149
-
1150
- # Pass a string as parameter, which should be [user name]:[password] to
1151
- # use for the connection. Use CURLOPT_HTTPAUTH to decide the
1152
- # authentication method.
1153
- # When using NTLM, you can set the domain by prepending it to the user
1154
- # name and separating the domain and name with a forward (/) or
1155
- # backward slash (\). Like this: "domain/user:password" or
1156
- # "domain\user:password". Some HTTP servers (on Windows) support this
1157
- # style even for Basic authentication.
1158
- # When using HTTP and CURLOPT_FOLLOWLOCATION, libcurl might perform
1159
- # several requests to possibly different hosts. libcurl will only send
1160
- # this user and password information to hosts using the initial host
1161
- # name (unless CURLOPT_UNRESTRICTED_AUTH is set), so if libcurl follows
1162
- # locations to other hosts it will not send the user and password to
1163
- # those. This is enforced to prevent accidental information leakage.
1164
- #
1165
- # @example Set userpwd option.
1166
- # easy.userpwd = "user:password"
1167
- #
1168
- # @param [ String ] value The value to set.
1169
- #
1170
- # @return [ void ]
1171
- def userpwd=(value)
1172
- Curl.set_option(:userpwd, value_for(value, :string), handle)
1173
- end
1174
-
1175
- # Set the parameter to 1 to get the library to display a lot of verbose
1176
- # information about its operations. Very useful for libcurl and/or
1177
- # protocol debugging and understanding. The verbose information will be
1178
- # sent to stderr, or the stream set with CURLOPT_STDERR.
1179
- # You hardly ever want this set in production use, you will almost
1180
- # always want this when you debug/report problems. Another neat option
1181
- # for debugging is the CURLOPT_DEBUGFUNCTION.
1182
- # Sets verbose option.
1183
- #
1184
- # @example Set verbose option.
1185
- # easy.verbose = true
1186
- #
1187
- # @param [ Boolean ] value The value to set.
1188
- #
1189
- # @return [ void ]
1190
- def verbose=(value)
1191
- Curl.set_option(:verbose, value_for(value, :bool), handle)
1192
- end
1193
-
1194
- private
1195
-
1196
- # Return the value to set to easy handle. It is converted with the help
1197
- # of bool_options, enum_options and int_options.
1198
- #
1199
- # @example Return casted the value.
1200
- # easy.value_for(:verbose)
1201
- #
1202
- # @param [ Symbol ] option The option to get the value from.
1203
- #
1204
- # @return [ Object ] The casted value.
1205
- #
1206
- # @raise [ Ethon::Errors::InvalidValue ] If specified option
1207
- # points to an enum and the value doen't correspond to
1208
- # the valid values.
1209
- def value_for(value, type, option = nil)
1210
- return nil if value.nil?
1211
-
1212
- if type == :bool
1213
- value ? 1 : 0
1214
- elsif type == :int
1215
- value.to_i
1216
- elsif type == :enum && option == :httpauth
1217
- Curl::Auth.to_h.fetch(value) do
1218
- raise Errors::InvalidValue.new(option, value)
1219
- end
1220
- elsif type == :enum && option == :sslversion
1221
- Curl::SSLVersion.to_h.fetch(value) do
1222
- raise Errors::InvalidValue.new(option, value)
11
+ Curl.set_option(:url, value, handle)
12
+ end
13
+
14
+ Curl.easy_options.each do |opt,props|
15
+ eval %Q<
16
+ def #{opt}=(value)
17
+ Curl.set_option(:#{opt}, value, handle)
18
+ value
1223
19
  end
1224
- elsif type == :enum && option == :http_version
1225
- Curl::HTTPVersion.to_h.fetch(value) do
1226
- raise Errors::InvalidValue.new(option, value)
1227
- end
1228
- elsif type == :enum && (option == :protocols || option == :redir_protocols)
1229
- Array(value).map do |v|
1230
- Curl::Protocols.to_h.fetch(v) do
1231
- raise Errors::InvalidValue.new(option, v)
1232
- end
1233
- end.inject(:+)
1234
- elsif type == :enum && option == :postredir
1235
- Array(value).map do |v|
1236
- Curl::Postredir.to_h.fetch(v) do
1237
- raise Errors::InvalidValue.new(option, v)
20
+ > unless method_defined? opt.to_s+"="
21
+ if props[:type]==:callback then
22
+ eval %Q<
23
+ def #{opt}(&block)
24
+ @procs ||= {}
25
+ @procs[:#{opt}]=block
26
+ Curl.set_option(:#{opt}, block, handle)
27
+ nil
1238
28
  end
1239
- end.inject(:+)
1240
- elsif type == :enum && option == :proxytype
1241
- Curl::Proxy.to_h.fetch(value) do
1242
- raise Errors::InvalidValue.new(option, value)
1243
- end
1244
- elsif value.is_a?(String)
1245
- Util.escape_zero_byte(value)
1246
- else
1247
- value
29
+ > unless method_defined? opt.to_s
1248
30
  end
1249
31
  end
1250
32
  end