scnr-ethon 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +379 -0
  3. data/LICENSE +20 -0
  4. data/README.md +118 -0
  5. data/ethon.gemspec +29 -0
  6. data/lib/ethon/curl.rb +90 -0
  7. data/lib/ethon/curls/classes.rb +65 -0
  8. data/lib/ethon/curls/codes.rb +122 -0
  9. data/lib/ethon/curls/constants.rb +80 -0
  10. data/lib/ethon/curls/form_options.rb +37 -0
  11. data/lib/ethon/curls/functions.rb +58 -0
  12. data/lib/ethon/curls/infos.rb +151 -0
  13. data/lib/ethon/curls/messages.rb +19 -0
  14. data/lib/ethon/curls/options.rb +503 -0
  15. data/lib/ethon/curls/settings.rb +12 -0
  16. data/lib/ethon/easy/callbacks.rb +149 -0
  17. data/lib/ethon/easy/debug_info.rb +47 -0
  18. data/lib/ethon/easy/features.rb +31 -0
  19. data/lib/ethon/easy/form.rb +107 -0
  20. data/lib/ethon/easy/header.rb +61 -0
  21. data/lib/ethon/easy/http/actionable.rb +157 -0
  22. data/lib/ethon/easy/http/custom.rb +29 -0
  23. data/lib/ethon/easy/http/delete.rb +25 -0
  24. data/lib/ethon/easy/http/get.rb +24 -0
  25. data/lib/ethon/easy/http/head.rb +24 -0
  26. data/lib/ethon/easy/http/options.rb +24 -0
  27. data/lib/ethon/easy/http/patch.rb +24 -0
  28. data/lib/ethon/easy/http/post.rb +26 -0
  29. data/lib/ethon/easy/http/postable.rb +32 -0
  30. data/lib/ethon/easy/http/put.rb +27 -0
  31. data/lib/ethon/easy/http/putable.rb +25 -0
  32. data/lib/ethon/easy/http.rb +68 -0
  33. data/lib/ethon/easy/informations.rb +116 -0
  34. data/lib/ethon/easy/mirror.rb +36 -0
  35. data/lib/ethon/easy/operations.rb +65 -0
  36. data/lib/ethon/easy/options.rb +50 -0
  37. data/lib/ethon/easy/params.rb +29 -0
  38. data/lib/ethon/easy/queryable.rb +154 -0
  39. data/lib/ethon/easy/response_callbacks.rb +136 -0
  40. data/lib/ethon/easy/util.rb +28 -0
  41. data/lib/ethon/easy.rb +315 -0
  42. data/lib/ethon/errors/ethon_error.rb +9 -0
  43. data/lib/ethon/errors/global_init.rb +13 -0
  44. data/lib/ethon/errors/invalid_option.rb +13 -0
  45. data/lib/ethon/errors/invalid_value.rb +13 -0
  46. data/lib/ethon/errors/multi_add.rb +12 -0
  47. data/lib/ethon/errors/multi_fdset.rb +12 -0
  48. data/lib/ethon/errors/multi_remove.rb +12 -0
  49. data/lib/ethon/errors/multi_timeout.rb +13 -0
  50. data/lib/ethon/errors/select.rb +13 -0
  51. data/lib/ethon/errors.rb +17 -0
  52. data/lib/ethon/libc.rb +21 -0
  53. data/lib/ethon/loggable.rb +59 -0
  54. data/lib/ethon/multi/operations.rb +228 -0
  55. data/lib/ethon/multi/options.rb +117 -0
  56. data/lib/ethon/multi/stack.rb +49 -0
  57. data/lib/ethon/multi.rb +126 -0
  58. data/lib/ethon/version.rb +6 -0
  59. data/lib/ethon.rb +36 -0
  60. metadata +117 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b1ae3b1d9930b0935371b3ee1ce8d233ec0f1d9ef8170380d160ffea2469891
4
+ data.tar.gz: e10a1aecce685d0729e10aa0f24efd2923736350b0cf8dfa2ff5f5bd0efabbd2
5
+ SHA512:
6
+ metadata.gz: 1b6f5fbd9c431e207c19d8f6ce4dd8fc5179b147a0b558bf19aa31caa40856e86efa1d63529489f6898604322847b873d192f885f7cc164e59fa72cbf4deca01
7
+ data.tar.gz: 72db218473814cda2ce29cf6a75700d5e0840a59fefc7f3fb8a07925bbd7e9c745c78175b137d455422b9ee49313d274d376d0fd1a145f5ea03857593d85a511
data/CHANGELOG.md ADDED
@@ -0,0 +1,379 @@
1
+ # Changelog
2
+
3
+ ## Master
4
+
5
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.16.0...master)
6
+
7
+ ## 0.16.0
8
+
9
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.15.0...v0.16.0)
10
+
11
+ * Added `redirect_url` value to available informations and `Easy::Mirror`.
12
+ ([Adrien Rey-Jarthon](https://github.com/jarthod)
13
+
14
+ ## 0.15.0
15
+
16
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.14.0...v0.15.0)
17
+
18
+ ## 0.12.0
19
+
20
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.11.0...v0.12.0)
21
+
22
+ - Removed deprecated `CURLE_SSL_CACERT` pinned in curl v7.62.0 ([@arku](https://github.com/arku) in [#158](https://github.com/typhoeus/ethon/pull/158))
23
+
24
+
25
+ ## 0.11.0
26
+
27
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.10.1...v0.11.0)
28
+
29
+ ## 0.10.1
30
+
31
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.10.0...v0.10.1)
32
+
33
+ ## 0.10.0
34
+
35
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.9.1...v0.10.0)
36
+
37
+ ## 0.9.1
38
+
39
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.9.0...v0.9.1)
40
+
41
+ ## 0.9.0
42
+
43
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.8.1...v0.9.0)
44
+
45
+ ## 0.8.1
46
+
47
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.8.0...v0.8.1)
48
+
49
+ * Support optional escaping of params.
50
+ ([Tasos Laskos](https://github.com/zapotek)
51
+ * `Easy::Mirror`: Reduced object allocations and method calls during info handling.
52
+ ([Tasos Laskos](https://github.com/zapotek)
53
+
54
+ ## 0.8.0
55
+
56
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.7.3...v0.7.4)
57
+
58
+ * `Easy::Mirror`: Reduced object allocations and method calls during info handling.
59
+ ([Tasos Laskos](https://github.com/zapotek)
60
+
61
+ ## 0.7.4
62
+
63
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.7.3...v0.7.4)
64
+
65
+ * Support different array encodings for params.
66
+ ([Marcello Barnaba](https://github.com/ifad), [\#104](https://github.com/typhoeus/ethon/pull/104))
67
+ * Programtic access to version infos.
68
+ ([Jonas Wagner](https://github.com/jwagner), [\#90](https://github.com/typhoeus/ethon/pull/90))
69
+
70
+
71
+ ## 0.7.3
72
+
73
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.7.2...v0.7.3)
74
+
75
+ * `Ethon::Curl::FDSet`
76
+ * Set `:fd_array` size to the current MS Windows `FD_SETSIZE` (2048).
77
+ ([Tasos Laskos](https://github.com/zapotek)
78
+
79
+ * Added `redirect_time` value to available informations and `Easy::Mirror`.
80
+ ([Adrien Jarthon](https://github.com/jarthod)
81
+
82
+ ## 0.7.2
83
+
84
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.7.1...v0.7.2)
85
+
86
+ * FFI data-types updated to be more correct.
87
+
88
+ ## 0.7.1
89
+
90
+ * MS Windows determination delegated to `Gem.windows?` for better accuracy.
91
+ * FFI data-types updated to work on MS Windows.
92
+
93
+ ## 0.7.0
94
+
95
+ Not backwards compatible changes:
96
+
97
+ * `mime-types` are no longer a dependency. The gem will be still used if available to determine the mime type of a file which is uploaded. That means you have to have take care of the gem installation yourself.
98
+
99
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.6.3...v0.7.0)
100
+
101
+ ## 0.6.3
102
+
103
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.6.2...v0.6.3)
104
+
105
+ ## 0.6.2
106
+
107
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.6.1...v0.6.2)
108
+
109
+ ## 0.6.1
110
+
111
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.6.0...v0.6.1)
112
+
113
+ The changelog entries are coming soon!
114
+
115
+ ## 0.6.0
116
+
117
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.12...v0.6.0)
118
+
119
+ The changelog entries are coming soon!
120
+
121
+ Bugfixes:
122
+
123
+ * URL-encode nullbytes in parameters instead of escaping them to `\\0`.
124
+ ([Tasos Laskos](https://github.com/zapotek)
125
+
126
+ ## 0.5.12
127
+
128
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.11...v0.5.12)
129
+
130
+ Enhancements:
131
+
132
+ * Performance optimizations.
133
+ ([Kyle Oppenheim](https://github.com/koppenheim) and [Richie Vos](https://github.com/richievos), [\#48](https://github.com/typhoeus/ethon/pull/48))
134
+ * Reuse memory pointer.
135
+ ([Richie Vos](https://github.com/richievos), [\#49](https://github.com/typhoeus/ethon/pull/49))
136
+
137
+ Bugfixes:
138
+
139
+ * Fix windows install.
140
+ ([Derik Olsson](https://github.com/derikolsson), [\#47](https://github.com/typhoeus/ethon/pull/47))
141
+ * Handle urls that already contain query params.
142
+ ([Turner King](https://github.com/turnerking ), [\#45](https://github.com/typhoeus/ethon/pull/45))
143
+
144
+ ## 0.5.11
145
+
146
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.10...v0.5.11)
147
+
148
+ Enhancements:
149
+
150
+ * Add support for postredirs, unrestricted_auth.
151
+ * Add support for cookie, cookiejar, cookiefile.
152
+ ([erwanlr](https://github.com/erwanlr), [\#46](https://github.com/typhoeus/ethon/pull/46))
153
+ * Relax ffi requirements.
154
+ ([voxik](https://github.com/voxik), [\#40](https://github.com/typhoeus/ethon/pull/40))
155
+ * Various documentation improvements.
156
+ ([Craig Little](https://github.com/craiglittle))
157
+
158
+ Bugfixes:
159
+
160
+ * Fix the memory leaks.
161
+ ([Richie Vos](https://github.com/richievos), [\#45](https://github.com/typhoeus/ethon/pull/45))
162
+
163
+ ## 0.5.10
164
+
165
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.9...v0.5.10)
166
+
167
+ Enhancements:
168
+
169
+ * Allow custom requests.
170
+ ([Nathan Sutton](https://github.com/nate), [\#36](https://github.com/typhoeus/ethon/pull/36))
171
+ * Use updated version of FFI.
172
+
173
+ Bugfixes:
174
+
175
+ * Fix windows install issue.
176
+ ([brainsucker](https://github.com/brainsucker), [\#38](https://github.com/typhoeus/ethon/pull/38))
177
+
178
+ ## 0.5.9
179
+
180
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.8...v0.5.9)
181
+
182
+ Enhancements:
183
+
184
+ * Allow to set multiple protocols.
185
+
186
+ ## 0.5.8
187
+
188
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.7...v0.5.8)
189
+
190
+ Enhancements:
191
+
192
+ * Add support for protocols and redir_protocols(
193
+ [libcurl SASL buffer overflow vulnerability](http://curl.haxx.se/docs/adv_20130206.html)).
194
+ * Add max_send_speed_large and max_recv_speed_large([Paul Schuegraf](https://github.com/pschuegr), [\#33](https://github.com/typhoeus/ethon/pull/33))
195
+
196
+ ## 0.5.7
197
+
198
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.6...v0.5.7)
199
+
200
+ Enhancements:
201
+
202
+ * Use new version of ffi.
203
+
204
+ ## 0.5.6
205
+
206
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.4...v0.5.6)
207
+
208
+ Bugfixes:
209
+
210
+ * Easy#reset resets on_complete callbacks.
211
+
212
+ ## 0.5.4
213
+
214
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.3...v0.5.4)
215
+
216
+ Enhancements:
217
+
218
+ * Use Libc#getdtablesize to get the FDSet size.
219
+ * New libcurl option accept_encoding.
220
+ * Documentation updates.
221
+
222
+ ## 0.5.3
223
+
224
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.2...v0.5.3)
225
+
226
+ Enhancements:
227
+
228
+ * Deprecate Easy#prepare. It is no longer necessary.
229
+ * Unroll metaprogramming for easy and multi options.
230
+ * More specs.
231
+
232
+ Bugfixes:
233
+
234
+ * Correct size for FDSets
235
+ * Add proxytypes to enums.
236
+
237
+ ## 0.5.2
238
+
239
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.1...v0.5.2)
240
+
241
+ Enhancements:
242
+
243
+ * New libcurl option keypasswd.
244
+
245
+ Bugfixes:
246
+
247
+ * Correct request logging when using multi interface.
248
+ * Remove invalid libcurl option sslcertpasswd.
249
+
250
+ ## 0.5.1
251
+
252
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.0...v0.5.1)
253
+
254
+ Bugfixes:
255
+
256
+ * Mark Curl.select and Curl.easy_perform as blocking so that the GIL is
257
+ released by ffi.
258
+
259
+ ## 0.5.0
260
+
261
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.4.4...v0.5.0)
262
+
263
+ Enhancements:
264
+
265
+ * New libcurl option proxyuserpwd
266
+ * Rename response_header to response_headers
267
+
268
+ Bugfixes:
269
+
270
+ * Mark Curl.select and Curl.easy_perform as blocking so that the GIL is
271
+ released by ffi.
272
+
273
+ ## 0.4.4
274
+
275
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.4.3...v0.4.4)
276
+
277
+ Enhancements:
278
+
279
+ * Prepare multi explicit like easy
280
+
281
+ ## 0.4.3
282
+
283
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.4.2...v0.4.3)
284
+
285
+ Enhancements:
286
+
287
+ * Remove deprecated libcurl option put
288
+ * More documentation
289
+ * New libcurl option connecttimeout_ms and timeout_ms
290
+ * Support multi options
291
+
292
+ Bugfixes:
293
+
294
+ * Handle nil values in query params
295
+
296
+ ## 0.4.2
297
+
298
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.4.1...v0.4.2)
299
+
300
+ Enhancements:
301
+
302
+ * New libcurl option forbid_reuse
303
+ * Use libcurls escape instead of CGI::escape
304
+
305
+ ## 0.4.1
306
+
307
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.4.0...v0.4.1)
308
+
309
+ Bugfixes:
310
+
311
+ * Handle nested hash in an array in params correct
312
+ ( [\#201](https://github.com/typhoeus/typhoeus/issues/201) )
313
+
314
+ ## 0.4.0
315
+
316
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.3.0...v0.4.0)
317
+
318
+ Enhancements:
319
+
320
+ * ruby 1.8.7 compatible
321
+ * Ethon.logger
322
+ * Deal with string param/body
323
+ * More documentation
324
+
325
+ Bugfixes:
326
+
327
+ * Add multi_cleanup to curl
328
+
329
+ ## 0.3.0
330
+
331
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.2.0...v0.3.0)
332
+
333
+ Enhancements:
334
+
335
+ * New libcurl option proxyport
336
+ * Raise invalid value error when providing a wrong key for sslversion or httpauth
337
+
338
+ Bugfixes:
339
+
340
+ * Libcurl option sslversion is handled correct
341
+
342
+ ## 0.2.0
343
+
344
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.1.0...v0.2.0)
345
+
346
+ Enhancements:
347
+
348
+ * GET requests are using custom requests only when there is a request body
349
+ * Easy#on_complete takes multiple callbacks
350
+ * raise Errors::GlobalInit when libcurls global_init failed instead of
351
+ runtime error
352
+ * raise Errors::InvalidOption if option is invalid
353
+
354
+ ## 0.1.0
355
+
356
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.0.2...v0.1.0)
357
+
358
+ Enhancements:
359
+
360
+ * Documentation
361
+ ( [Alex P](https://github.com/ifesdjeen), [\#13](https://github.com/typhoeus/ethon/issues/13) )
362
+ * New libcurl option dns_cache_timeout
363
+ ( [Chris Heald](https://github.com/cheald), [\#192](https://github.com/typhoeus/typhoeus/pull/192) )
364
+
365
+ Bugfixes:
366
+
367
+ * Libcurl option ssl_verifyhost takes an integer.
368
+ * Add space between header key and value.
369
+
370
+ ## 0.0.2
371
+
372
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.0.1...v0.0.2)
373
+
374
+ Bugfixes:
375
+
376
+ * Add libcurl.so.4 to ffi_lib in order to load correct lib on Debian.
377
+ * Escape zero bytes.
378
+
379
+ ## 0.0.1 Initial version
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012-2016 Hans Hasselberg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ [![Gem Version](https://badge.fury.io/rb/ethon.svg)](https://badge.fury.io/rb/ethon)
2
+ [![Build Status](https://github.com/typhoeus/ethon/workflows/Ruby/badge.svg)](https://github.com/typhoeus/ethon/actions/workflows/ruby.yml)
3
+
4
+ # Ethon
5
+
6
+ In Greek mythology, Ethon, the son of Typhoeus and Echidna, is a gigantic eagle. So much for the history.
7
+ In the modern world, Ethon is a very basic libcurl wrapper using ffi.
8
+
9
+ * [Documentation](http://rubydoc.info/github/typhoeus/ethon/frames/Ethon)
10
+ * [Website](http://typhoeus.github.com/)
11
+ * [Mailing list](http://groups.google.com/group/typhoeus)
12
+
13
+ ## Installation
14
+
15
+ With bundler:
16
+
17
+ gem "ethon"
18
+
19
+ With rubygems:
20
+
21
+ gem install ethon
22
+
23
+ ## Usage
24
+
25
+ Making the first request is simple:
26
+
27
+ ```ruby
28
+ easy = Ethon::Easy.new(url: "www.example.com")
29
+ easy.perform
30
+ #=> :ok
31
+ ```
32
+
33
+ You have access to various options, such as following redirects:
34
+
35
+ ```ruby
36
+ easy = Ethon::Easy.new(url: "www.example.com", followlocation: true)
37
+ easy.perform
38
+ #=> :ok
39
+ ```
40
+
41
+ Once you're done you can inspect the response code and body:
42
+
43
+ ```ruby
44
+ easy = Ethon::Easy.new(url: "www.example.com", followlocation: true)
45
+ easy.perform
46
+ easy.response_code
47
+ #=> 200
48
+ easy.response_body
49
+ #=> "<!doctype html><html ..."
50
+ ```
51
+
52
+ ## Http
53
+
54
+ In order to make life easier, there are some helpers for making HTTP requests:
55
+
56
+ ```ruby
57
+ easy = Ethon::Easy.new
58
+ easy.http_request("www.example.com", :get, { params: {a: 1} })
59
+ easy.perform
60
+ #=> :ok
61
+ ```
62
+
63
+ ```ruby
64
+ easy = Ethon::Easy.new
65
+ easy.http_request("www.example.com", :post, { params: { a: 1 }, body: { b: 2 } })
66
+ easy.perform
67
+ #=> :ok
68
+ ```
69
+
70
+ This is really handy when making requests since you don't have to care about setting
71
+ everything up correctly.
72
+
73
+ ## Http2
74
+ Standard http2 servers require the client to connect once and create a session (multi) and then add simple requests to the multi handler.
75
+ The `perform` method then takes all the requests in the multi handler and sends them to the server.
76
+
77
+ See the following example
78
+ ```ruby
79
+ multi = Ethon::Multi.new
80
+ easy = Ethon::Easy.new
81
+
82
+ easy.http_request("www.example.com/get", :get, { http_version: :httpv2_0 })
83
+
84
+ # Sending a request with http version 2 will send an Upgrade header to the server, which many older servers will not support
85
+ # See below for more info: https://everything.curl.dev/http/http2
86
+ # If this is a problem, send the below:
87
+ easy.http_request("www.example.com/get", :get, { http_version: :httpv2_prior_knowledge })
88
+
89
+ # To set the server to use http2 with https and http1 with http, send the following:
90
+ easy.http_request("www.example.com/get", :get, { http_version: :httpv2_tls })
91
+
92
+ multi.add(easy)
93
+ multi.perform
94
+ ```
95
+
96
+ ## LICENSE
97
+
98
+ (The MIT License)
99
+
100
+ Copyright © 2012-2016 [Hans Hasselberg](http://www.hans.io)
101
+
102
+ Permission is hereby granted, free of charge, to any person obtaining a
103
+ copy of this software and associated documentation files (the "Software"),
104
+ to deal in the Software without restriction, including without
105
+ limitation the rights to use, copy, modify, merge, publish, distribute,
106
+ sublicense, and/or sell copies of the Software, and to permit persons
107
+ to whom the Software is furnished to do so, subject to the following conditions:
108
+
109
+ The above copyright notice and this permission notice shall be included
110
+ in all copies or substantial portions of the Software.
111
+
112
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
113
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
115
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
116
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
117
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
118
+ OTHER DEALINGS IN THE SOFTWARE.
data/ethon.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib/', __FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ require 'ethon/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "scnr-ethon"
10
+ s.version = Ethon::VERSION
11
+ s.platform = Gem::Platform::RUBY
12
+ s.authors = ["Tasos Laskos", "Hans Hasselberg"]
13
+ s.email = ["tasos.laskos@gmail.com", "me@hans.io"]
14
+ s.homepage = "https://github.com/typhoeus/ethon/tree/thread-safe-easy-handle-cleanup"
15
+ s.summary = "Libcurl wrapper."
16
+ s.description = "Very lightweight libcurl wrapper."
17
+
18
+ s.required_rubygems_version = ">= 1.3.6"
19
+ s.license = 'MIT'
20
+
21
+ s.add_dependency('ffi', ['>= 1.15.0'])
22
+
23
+ s.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |file|
25
+ file.start_with?(*%w[. Gemfile Guardfile Rakefile profile spec])
26
+ end
27
+ end
28
+ s.require_path = 'lib'
29
+ end
data/lib/ethon/curl.rb ADDED
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+ require 'ethon/curls/codes'
3
+ require 'ethon/curls/options'
4
+ require 'ethon/curls/infos'
5
+ require 'ethon/curls/form_options'
6
+ require 'ethon/curls/messages'
7
+ require 'ethon/curls/functions'
8
+
9
+ module Ethon
10
+
11
+ # FFI Wrapper module for Curl. Holds constants and required initializers.
12
+ #
13
+ # @api private
14
+ module Curl
15
+ extend ::FFI::Library
16
+ extend Ethon::Curls::Codes
17
+ extend Ethon::Curls::Options
18
+ extend Ethon::Curls::Infos
19
+ extend Ethon::Curls::FormOptions
20
+ extend Ethon::Curls::Messages
21
+
22
+ # :nodoc:
23
+ def self.windows?
24
+ Libc.windows?
25
+ end
26
+
27
+ require 'ethon/curls/constants'
28
+ require 'ethon/curls/settings'
29
+ require 'ethon/curls/classes'
30
+ extend Ethon::Curls::Functions
31
+
32
+ @blocking = true
33
+
34
+ @@initialized = false
35
+ @@curl_mutex = Mutex.new
36
+
37
+ class << self
38
+ # This function sets up the program environment that libcurl needs.
39
+ # Think of it as an extension of the library loader.
40
+ #
41
+ # This function must be called at least once within a program (a program is all the
42
+ # code that shares a memory space) before the program calls any other function in libcurl.
43
+ # The environment it sets up is constant for the life of the program and is the same for
44
+ # every program, so multiple calls have the same effect as one call.
45
+ #
46
+ # The flags option is a bit pattern that tells libcurl exactly what features to init,
47
+ # as described below. Set the desired bits by ORing the values together. In normal
48
+ # operation, you must specify CURL_GLOBAL_ALL. Don't use any other value unless
49
+ # you are familiar with it and mean to control internal operations of libcurl.
50
+ #
51
+ # This function is not thread safe. You must not call it when any other thread in
52
+ # the program (i.e. a thread sharing the same memory) is running. This doesn't just
53
+ # mean no other thread that is using libcurl. Because curl_global_init() calls
54
+ # functions of other libraries that are similarly thread unsafe, it could conflict with
55
+ # any other thread that uses these other libraries.
56
+ #
57
+ # @raise [ Ethon::Errors::GlobalInit ] If Curl.global_init fails.
58
+ def init
59
+ @@curl_mutex.synchronize {
60
+ if not @@initialized
61
+ raise Errors::GlobalInit.new if Curl.global_init(GLOBAL_ALL) != 0
62
+ @@initialized = true
63
+ Ethon.logger.debug("ETHON: Libcurl initialized") if Ethon.logger
64
+ end
65
+ }
66
+ end
67
+
68
+ # This function releases resources acquired by curl_global_init.
69
+ # You should call curl_global_cleanup once for each call you make to
70
+ # curl_global_init, after you are done using libcurl.
71
+ # This function is not thread safe. You must not call it when any other thread in the
72
+ # program (i.e. a thread sharing the same memory) is running. This doesn't just
73
+ # mean no other thread that is using libcurl. Because curl_global_cleanup calls functions of other
74
+ # libraries that are similarly thread unsafe, it could conflict with
75
+ # any other thread that uses these other libraries.
76
+ # See the description in libcurl of global environment requirements
77
+ # for details of how to use this function.
78
+ def cleanup
79
+ @@curl_mutex.synchronize {
80
+ if @@initialized
81
+ Curl.global_cleanup()
82
+ @@initialized = false
83
+ Ethon.logger.debug("ETHON: Libcurl cleanup") if Ethon.logger
84
+ end
85
+ }
86
+ end
87
+
88
+ end
89
+ end
90
+ end