curb 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +42 -6
- data/Rakefile +9 -7
- data/ext/curb.c +9 -1
- data/ext/curb.h +3 -3
- data/ext/curb_easy.c +55 -41
- data/ext/curb_macros.h +12 -0
- data/ext/curb_multi.c +50 -24
- data/ext/curb_postfield.c +9 -7
- data/ext/curb_upload.c +1 -0
- data/ext/extconf.rb +2 -0
- data/lib/curl/easy.rb +5 -5
- data/lib/curl/multi.rb +8 -1
- data/lib/curl.rb +11 -3
- data/tests/bug_crash_on_debug.rb +14 -28
- data/tests/bug_crash_on_progress.rb +7 -31
- data/tests/bug_curb_easy_blocks_ruby_threads.rb +8 -13
- data/tests/bug_curb_easy_post_with_string_no_content_length_header.rb +6 -30
- data/tests/bug_follow_redirect_288.rb +83 -0
- data/tests/bug_instance_post_differs_from_class_post.rb +3 -5
- data/tests/bug_issue277.rb +32 -0
- data/tests/bug_multi_segfault.rb +1 -0
- data/tests/bug_raise_on_callback.rb +29 -0
- data/tests/helper.rb +26 -0
- data/tests/tc_curl_easy.rb +12 -4
- data/tests/tc_curl_multi.rb +47 -7
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e28b1d05b46460867acfadc87bbe422d58d8f2cdb93397fa6ded906b01cd7dab
|
4
|
+
data.tar.gz: 33e7037c1c2b23a793ec96c73bc80c008939c880702f884d2b258d4afd18c368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb448726a4fdce1e0832e36a45b2c8e0a078fbc2c04b3fe34f87fc38397f5c4ecc4fe621aed5637750c5c7a7a9d05b30c03f9f7db153c23d3694eb6adb464e8
|
7
|
+
data.tar.gz: 624e3f39af79eff874784a662776debc2b405378c6cdc963a50dee525d36aa225cc5f40558f9b35b396c222416006f66c29fc6193e651b5aa84093fdd52cb2ba
|
data/README.markdown
CHANGED
@@ -1,22 +1,57 @@
|
|
1
|
-
# Curb - Libcurl bindings for Ruby
|
1
|
+
# Curb - Libcurl bindings for Ruby
|
2
2
|
|
3
|
+
* [CI Build Status](https://github.com/taf2/curb/actions/workflows/CI.yml)
|
3
4
|
* [rubydoc rdoc](http://www.rubydoc.info/github/taf2/curb/)
|
4
5
|
* [github project](http://github.com/taf2/curb/tree/master)
|
5
6
|
|
6
7
|
Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the
|
7
8
|
libcurl(3), a fully-featured client-side URL transfer library.
|
8
|
-
cURL and libcurl live at [
|
9
|
+
cURL and libcurl live at [https://curl.se/libcurl/](https://curl.se/libcurl/) .
|
9
10
|
|
10
11
|
Curb is a work-in-progress, and currently only supports libcurl's `easy` and `multi` modes.
|
11
12
|
|
12
13
|
## License
|
13
14
|
|
14
|
-
Curb is copyright (c)2006 Ross Bamford, and released under the terms of the
|
15
|
+
Curb is copyright (c) 2006 Ross Bamford, and released under the terms of the
|
15
16
|
Ruby license. See the LICENSE file for the gory details.
|
16
17
|
|
18
|
+
## Easy mode
|
19
|
+
|
20
|
+
GET request
|
21
|
+
```
|
22
|
+
res = Curl.get("https://www.google.com/") {|http|
|
23
|
+
http.timeout = 10 # raise exception if request/response not handled within 10 seconds
|
24
|
+
}
|
25
|
+
puts res.code
|
26
|
+
puts res.head
|
27
|
+
puts res.body
|
28
|
+
```
|
29
|
+
|
30
|
+
POST request
|
31
|
+
```
|
32
|
+
res = Curl.post("https://your-server.com/endpoint", {post: "this"}.to_json) {|http|
|
33
|
+
http.headers["Content-Type"] = "application/json"
|
34
|
+
}
|
35
|
+
puts res.code
|
36
|
+
puts res.head
|
37
|
+
puts res.body
|
38
|
+
```
|
39
|
+
|
40
|
+
PATCH request
|
41
|
+
```
|
42
|
+
res = Curl.patch("https://your-server.com/endpoint", {post: "this"}.to_json) {|http|
|
43
|
+
http.headers["Content-Type"] = "application/json"
|
44
|
+
}
|
45
|
+
puts res.code
|
46
|
+
puts res.head
|
47
|
+
puts res.body
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
|
17
52
|
## You will need
|
18
53
|
|
19
|
-
* A working Ruby installation (`
|
54
|
+
* A working Ruby installation (`2.0.0+` will work but `2.1+` preferred) (it's possible it still works with 1.8.7 but you'd have to tell me if not...)
|
20
55
|
* A working libcurl development installation
|
21
56
|
(Ideally one of the versions listed in the compatibility chart below that maps to your `curb` version)
|
22
57
|
* A sane build environment (e.g. gcc, make)
|
@@ -29,7 +64,8 @@ tested and reported to work across a variety of platforms / rubies)
|
|
29
64
|
|
30
65
|
| Gem Version | Release Date | libcurl versions |
|
31
66
|
| ----------- | ----------- | ---------------- |
|
32
|
-
| 0.
|
67
|
+
| 1.0.0 | Jan 2022 | 7.58 - 7.81 |
|
68
|
+
| 0.9.8 | Jan 2019 | 7.58 - 7.81 |
|
33
69
|
| 0.9.7 | Nov 2018 | 7.56 - 7.60 |
|
34
70
|
| 0.9.6 | May 2018 | 7.51 - 7.59 |
|
35
71
|
| 0.9.5 | May 2018 | 7.51 - 7.59 |
|
@@ -43,7 +79,7 @@ tested and reported to work across a variety of platforms / rubies)
|
|
43
79
|
$ gem install curb
|
44
80
|
|
45
81
|
On Windows, make sure you're using the [DevKit](http://rubyinstaller.org/downloads/) and
|
46
|
-
the [development version of libcurl](http://curl.
|
82
|
+
the [development version of libcurl](http://curl.se/gknw.net/7.39.0/dist-w32/curl-7.39.0-devel-mingw32.zip). Unzip, then run this in your command
|
47
83
|
line (alter paths to your curl location, but remember to use forward slashes):
|
48
84
|
|
49
85
|
gem install curb --platform=ruby -- --with-curl-lib=C:/curl-7.39.0-devel-mingw32/lib --with-curl-include=C:/curl-7.39.0-devel-mingw32/include
|
data/Rakefile
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#
|
3
3
|
require 'rake/clean'
|
4
4
|
require 'rake/testtask'
|
5
|
+
require "ruby_memcheck"
|
5
6
|
|
6
7
|
CLEAN.include '**/*.o'
|
7
8
|
CLEAN.include "**/*.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
|
@@ -10,13 +11,6 @@ CLOBBER.include '**/*.log'
|
|
10
11
|
CLOBBER.include '**/Makefile'
|
11
12
|
CLOBBER.include '**/extconf.h'
|
12
13
|
|
13
|
-
# Not available for really old rubies, but that's ok.
|
14
|
-
begin
|
15
|
-
require 'pry'
|
16
|
-
rescue LoadError
|
17
|
-
puts "Failed to load pry."
|
18
|
-
end
|
19
|
-
|
20
14
|
# Load support ruby and rake files (in this order)
|
21
15
|
Dir.glob('tasks/*.rb').each { |r| load r}
|
22
16
|
Dir.glob('tasks/*.rake').each { |r| load r}
|
@@ -97,6 +91,14 @@ else
|
|
97
91
|
task :alltests => [:unittests, :bugtests]
|
98
92
|
end
|
99
93
|
|
94
|
+
RubyMemcheck.config(binary_name: 'curb_core')
|
95
|
+
namespace :test do
|
96
|
+
RubyMemcheck::TestTask.new(valgrind: :compile) do|t|
|
97
|
+
t.test_files = FileList['tests/tc_*.rb']
|
98
|
+
t.verbose = false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
100
102
|
Rake::TestTask.new(:unittests) do |t|
|
101
103
|
t.test_files = FileList['tests/tc_*.rb']
|
102
104
|
t.verbose = false
|
data/ext/curb.c
CHANGED
@@ -235,12 +235,16 @@ static VALUE ruby_curl_http2_q(VALUE mod) {
|
|
235
235
|
#endif
|
236
236
|
}
|
237
237
|
|
238
|
+
static void finalize_curb_core(VALUE data) {
|
239
|
+
curl_global_cleanup();
|
240
|
+
}
|
241
|
+
|
238
242
|
void Init_curb_core() {
|
239
|
-
// TODO we need to call curl_global_cleanup at exit!
|
240
243
|
curl_version_info_data *ver;
|
241
244
|
VALUE curlver, curllongver, curlvernum;
|
242
245
|
|
243
246
|
curl_global_init(CURL_GLOBAL_ALL);
|
247
|
+
rb_set_end_proc(finalize_curb_core, Qnil);
|
244
248
|
ver = curl_version_info(CURLVERSION_NOW);
|
245
249
|
|
246
250
|
mCurl = rb_define_module("Curl");
|
@@ -1072,6 +1076,10 @@ void Init_curb_core() {
|
|
1072
1076
|
CURB_DEFINE(CURLOPT_HAPROXYPROTOCOL);
|
1073
1077
|
#endif
|
1074
1078
|
|
1079
|
+
#if HAVE_CURLOPT_PROXY_SSL_VERIFYHOST
|
1080
|
+
CURB_DEFINE(CURLOPT_PROXY_SSL_VERIFYHOST);
|
1081
|
+
#endif
|
1082
|
+
|
1075
1083
|
#if HAVE_CURLPROTO_RTMPTE
|
1076
1084
|
CURB_DEFINE(CURLPROTO_RTMPTE);
|
1077
1085
|
#endif
|
data/ext/curb.h
CHANGED
@@ -28,11 +28,11 @@
|
|
28
28
|
#include "curb_macros.h"
|
29
29
|
|
30
30
|
// These should be managed from the Rake 'release' task.
|
31
|
-
#define CURB_VERSION "1.0.
|
32
|
-
#define CURB_VER_NUM
|
31
|
+
#define CURB_VERSION "1.0.5"
|
32
|
+
#define CURB_VER_NUM 1005
|
33
33
|
#define CURB_VER_MAJ 1
|
34
34
|
#define CURB_VER_MIN 0
|
35
|
-
#define CURB_VER_MIC
|
35
|
+
#define CURB_VER_MIC 5
|
36
36
|
#define CURB_VER_PATCH 0
|
37
37
|
|
38
38
|
|
data/ext/curb_easy.c
CHANGED
@@ -34,7 +34,7 @@ static FILE * rb_io_stdio_file(rb_io_t *fptr) {
|
|
34
34
|
|
35
35
|
/* ================== CURL HANDLER FUNCS ==============*/
|
36
36
|
|
37
|
-
static VALUE callback_exception(VALUE unused) {
|
37
|
+
static VALUE callback_exception(VALUE unused, VALUE exception) {
|
38
38
|
return Qfalse;
|
39
39
|
}
|
40
40
|
|
@@ -329,9 +329,9 @@ static VALUE ruby_curl_easy_allocate(VALUE klass) {
|
|
329
329
|
|
330
330
|
/*
|
331
331
|
* call-seq:
|
332
|
-
* Curl::Easy.new =>
|
333
|
-
* Curl::Easy.new(url = nil) =>
|
334
|
-
* Curl::Easy.new(url = nil) { |self| ... } =>
|
332
|
+
* Curl::Easy.new => #<Curl::Easy...>
|
333
|
+
* Curl::Easy.new(url = nil) => #<Curl::Easy...>
|
334
|
+
* Curl::Easy.new(url = nil) { |self| ... } => #<Curl::Easy...>
|
335
335
|
*
|
336
336
|
* Initialize a new Curl::Easy instance, optionally supplying the URL.
|
337
337
|
* The block form allows further configuration to be supplied before
|
@@ -376,8 +376,8 @@ static VALUE ruby_curl_easy_initialize(int argc, VALUE *argv, VALUE self) {
|
|
376
376
|
|
377
377
|
/*
|
378
378
|
* call-seq:
|
379
|
-
* easy.clone =>
|
380
|
-
* easy.dup =>
|
379
|
+
* easy.clone => <easy clone>
|
380
|
+
* easy.dup => <easy clone>
|
381
381
|
*
|
382
382
|
* Clone this Curl::Easy instance, creating a new instance.
|
383
383
|
* This method duplicates the underlying CURL* handle.
|
@@ -957,7 +957,7 @@ static VALUE ruby_curl_easy_ftp_commands_set(VALUE self, VALUE ftp_commands) {
|
|
957
957
|
}
|
958
958
|
|
959
959
|
/*
|
960
|
-
* call-seq
|
960
|
+
* call-seq:
|
961
961
|
* easy.ftp_commands => array or nil
|
962
962
|
*/
|
963
963
|
static VALUE ruby_curl_easy_ftp_commands_get(VALUE self) {
|
@@ -976,7 +976,7 @@ static VALUE ruby_curl_easy_resolve_set(VALUE self, VALUE resolve) {
|
|
976
976
|
}
|
977
977
|
|
978
978
|
/*
|
979
|
-
* call-seq
|
979
|
+
* call-seq:
|
980
980
|
* easy.resolve => array or nil
|
981
981
|
*/
|
982
982
|
static VALUE ruby_curl_easy_resolve_get(VALUE self) {
|
@@ -1311,7 +1311,7 @@ static VALUE ruby_curl_easy_connect_timeout_set(VALUE self, VALUE connect_timeou
|
|
1311
1311
|
* Obtain the maximum time in seconds that you allow the connection to the
|
1312
1312
|
* server to take.
|
1313
1313
|
*/
|
1314
|
-
static VALUE ruby_curl_easy_connect_timeout_get(VALUE self
|
1314
|
+
static VALUE ruby_curl_easy_connect_timeout_get(VALUE self) {
|
1315
1315
|
CURB_IMMED_GETTER(ruby_curl_easy, connect_timeout, 0);
|
1316
1316
|
}
|
1317
1317
|
|
@@ -1337,7 +1337,7 @@ static VALUE ruby_curl_easy_connect_timeout_ms_set(VALUE self, VALUE connect_tim
|
|
1337
1337
|
* Obtain the maximum time in milliseconds that you allow the connection to the
|
1338
1338
|
* server to take.
|
1339
1339
|
*/
|
1340
|
-
static VALUE ruby_curl_easy_connect_timeout_ms_get(VALUE self
|
1340
|
+
static VALUE ruby_curl_easy_connect_timeout_ms_get(VALUE self) {
|
1341
1341
|
CURB_IMMED_GETTER(ruby_curl_easy, connect_timeout_ms, 0);
|
1342
1342
|
}
|
1343
1343
|
|
@@ -1360,7 +1360,7 @@ static VALUE ruby_curl_easy_dns_cache_timeout_set(VALUE self, VALUE dns_cache_ti
|
|
1360
1360
|
*
|
1361
1361
|
* Obtain the dns cache timeout in seconds.
|
1362
1362
|
*/
|
1363
|
-
static VALUE ruby_curl_easy_dns_cache_timeout_get(VALUE self
|
1363
|
+
static VALUE ruby_curl_easy_dns_cache_timeout_get(VALUE self) {
|
1364
1364
|
CURB_IMMED_GETTER(ruby_curl_easy, dns_cache_timeout, -1);
|
1365
1365
|
}
|
1366
1366
|
|
@@ -1387,7 +1387,7 @@ static VALUE ruby_curl_easy_ftp_response_timeout_set(VALUE self, VALUE ftp_respo
|
|
1387
1387
|
*
|
1388
1388
|
* Obtain the maximum time that libcurl will wait for FTP command responses.
|
1389
1389
|
*/
|
1390
|
-
static VALUE ruby_curl_easy_ftp_response_timeout_get(VALUE self
|
1390
|
+
static VALUE ruby_curl_easy_ftp_response_timeout_get(VALUE self) {
|
1391
1391
|
CURB_IMMED_GETTER(ruby_curl_easy, ftp_response_timeout, 0);
|
1392
1392
|
}
|
1393
1393
|
|
@@ -1410,7 +1410,7 @@ static VALUE ruby_curl_easy_low_speed_limit_set(VALUE self, VALUE low_speed_limi
|
|
1410
1410
|
* Obtain the minimum transfer speed over +low_speed+time+ below which the
|
1411
1411
|
* transfer will be aborted.
|
1412
1412
|
*/
|
1413
|
-
static VALUE ruby_curl_easy_low_speed_limit_get(VALUE self
|
1413
|
+
static VALUE ruby_curl_easy_low_speed_limit_get(VALUE self) {
|
1414
1414
|
CURB_IMMED_GETTER(ruby_curl_easy, low_speed_limit, 0);
|
1415
1415
|
}
|
1416
1416
|
|
@@ -1432,7 +1432,7 @@ static VALUE ruby_curl_easy_low_speed_time_set(VALUE self, VALUE low_speed_time)
|
|
1432
1432
|
* Obtain the time that the transfer should be below +low_speed_limit+ for
|
1433
1433
|
* the library to abort it.
|
1434
1434
|
*/
|
1435
|
-
static VALUE ruby_curl_easy_low_speed_time_get(VALUE self
|
1435
|
+
static VALUE ruby_curl_easy_low_speed_time_get(VALUE self) {
|
1436
1436
|
CURB_IMMED_GETTER(ruby_curl_easy, low_speed_time, 0);
|
1437
1437
|
}
|
1438
1438
|
|
@@ -1452,7 +1452,7 @@ static VALUE ruby_curl_easy_max_send_speed_large_set(VALUE self, VALUE max_send_
|
|
1452
1452
|
*
|
1453
1453
|
* Get the maximal sending transfer speed (in bytes per second)
|
1454
1454
|
*/
|
1455
|
-
static VALUE ruby_curl_easy_max_send_speed_large_get(VALUE self
|
1455
|
+
static VALUE ruby_curl_easy_max_send_speed_large_get(VALUE self) {
|
1456
1456
|
CURB_IMMED_GETTER(ruby_curl_easy, max_send_speed_large, 0);
|
1457
1457
|
}
|
1458
1458
|
|
@@ -1472,7 +1472,7 @@ static VALUE ruby_curl_easy_max_recv_speed_large_set(VALUE self, VALUE max_recv_
|
|
1472
1472
|
*
|
1473
1473
|
* Get the maximal receiving transfer speed (in bytes per second)
|
1474
1474
|
*/
|
1475
|
-
static VALUE ruby_curl_easy_max_recv_speed_large_get(VALUE self
|
1475
|
+
static VALUE ruby_curl_easy_max_recv_speed_large_get(VALUE self) {
|
1476
1476
|
CURB_IMMED_GETTER(ruby_curl_easy, max_recv_speed_large, 0);
|
1477
1477
|
}
|
1478
1478
|
|
@@ -1496,7 +1496,7 @@ static VALUE ruby_curl_easy_username_set(VALUE self, VALUE username) {
|
|
1496
1496
|
*
|
1497
1497
|
* Get the current username
|
1498
1498
|
*/
|
1499
|
-
static VALUE ruby_curl_easy_username_get(VALUE self
|
1499
|
+
static VALUE ruby_curl_easy_username_get(VALUE self) {
|
1500
1500
|
#if HAVE_CURLOPT_USERNAME
|
1501
1501
|
CURB_OBJECT_HGETTER(ruby_curl_easy, username);
|
1502
1502
|
#else
|
@@ -1524,7 +1524,7 @@ static VALUE ruby_curl_easy_password_set(VALUE self, VALUE password) {
|
|
1524
1524
|
*
|
1525
1525
|
* Get the current password
|
1526
1526
|
*/
|
1527
|
-
static VALUE ruby_curl_easy_password_get(VALUE self
|
1527
|
+
static VALUE ruby_curl_easy_password_get(VALUE self) {
|
1528
1528
|
#if HAVE_CURLOPT_PASSWORD
|
1529
1529
|
CURB_OBJECT_HGETTER(ruby_curl_easy, password);
|
1530
1530
|
#else
|
@@ -1558,7 +1558,7 @@ static VALUE ruby_curl_easy_ssl_version_set(VALUE self, VALUE ssl_version) {
|
|
1558
1558
|
*
|
1559
1559
|
* Get the version of SSL/TLS that libcurl will attempt to use.
|
1560
1560
|
*/
|
1561
|
-
static VALUE ruby_curl_easy_ssl_version_get(VALUE self
|
1561
|
+
static VALUE ruby_curl_easy_ssl_version_get(VALUE self) {
|
1562
1562
|
CURB_IMMED_GETTER(ruby_curl_easy, ssl_version, -1);
|
1563
1563
|
}
|
1564
1564
|
|
@@ -1579,7 +1579,7 @@ static VALUE ruby_curl_easy_use_ssl_set(VALUE self, VALUE use_ssl) {
|
|
1579
1579
|
*
|
1580
1580
|
* Get the desired level for using SSL on FTP connections.
|
1581
1581
|
*/
|
1582
|
-
static VALUE ruby_curl_easy_use_ssl_get(VALUE self
|
1582
|
+
static VALUE ruby_curl_easy_use_ssl_get(VALUE self) {
|
1583
1583
|
CURB_IMMED_GETTER(ruby_curl_easy, use_ssl, -1);
|
1584
1584
|
}
|
1585
1585
|
|
@@ -1595,12 +1595,12 @@ static VALUE ruby_curl_easy_ftp_filemethod_set(VALUE self, VALUE ftp_filemethod)
|
|
1595
1595
|
}
|
1596
1596
|
|
1597
1597
|
/*
|
1598
|
-
* call-seq
|
1598
|
+
* call-seq:
|
1599
1599
|
* easy.ftp_filemethod => fixnum
|
1600
1600
|
*
|
1601
1601
|
* Get the configuration for how libcurl will reach files on the server.
|
1602
1602
|
*/
|
1603
|
-
static VALUE ruby_curl_easy_ftp_filemethod_get(VALUE self
|
1603
|
+
static VALUE ruby_curl_easy_ftp_filemethod_get(VALUE self) {
|
1604
1604
|
CURB_IMMED_GETTER(ruby_curl_easy, ftp_filemethod, -1);
|
1605
1605
|
}
|
1606
1606
|
|
@@ -1967,7 +1967,7 @@ static VALUE ruby_curl_easy_resolve_mode_set(VALUE self, VALUE resolve_mode) {
|
|
1967
1967
|
|
1968
1968
|
/*
|
1969
1969
|
* call-seq:
|
1970
|
-
* easy.on_body { |body_data| ... } =>
|
1970
|
+
* easy.on_body { |body_data| ... } => <old handler>
|
1971
1971
|
*
|
1972
1972
|
* Assign or remove the +on_body+ handler for this Curl::Easy instance.
|
1973
1973
|
* To remove a previously-supplied handler, call this method with no
|
@@ -1986,7 +1986,7 @@ static VALUE ruby_curl_easy_on_body_set(int argc, VALUE *argv, VALUE self) {
|
|
1986
1986
|
|
1987
1987
|
/*
|
1988
1988
|
* call-seq:
|
1989
|
-
* easy.on_success { |easy| ... } =>
|
1989
|
+
* easy.on_success { |easy| ... } => <old handler>
|
1990
1990
|
*
|
1991
1991
|
* Assign or remove the +on_success+ handler for this Curl::Easy instance.
|
1992
1992
|
* To remove a previously-supplied handler, call this method with no
|
@@ -2001,7 +2001,7 @@ static VALUE ruby_curl_easy_on_success_set(int argc, VALUE *argv, VALUE self) {
|
|
2001
2001
|
|
2002
2002
|
/*
|
2003
2003
|
* call-seq:
|
2004
|
-
* easy.on_failure {|easy,code| ... } =>
|
2004
|
+
* easy.on_failure {|easy,code| ... } => <old handler>
|
2005
2005
|
*
|
2006
2006
|
* Assign or remove the +on_failure+ handler for this Curl::Easy instance.
|
2007
2007
|
* To remove a previously-supplied handler, call this method with no
|
@@ -2016,7 +2016,7 @@ static VALUE ruby_curl_easy_on_failure_set(int argc, VALUE *argv, VALUE self) {
|
|
2016
2016
|
|
2017
2017
|
/*
|
2018
2018
|
* call-seq:
|
2019
|
-
* easy.on_missing {|easy,code| ... } =>
|
2019
|
+
* easy.on_missing {|easy,code| ... } => <old handler;>
|
2020
2020
|
*
|
2021
2021
|
* Assign or remove the on_missing handler for this Curl::Easy instance.
|
2022
2022
|
* To remove a previously-supplied handler, call this method with no attached
|
@@ -2031,7 +2031,7 @@ static VALUE ruby_curl_easy_on_missing_set(int argc, VALUE *argv, VALUE self) {
|
|
2031
2031
|
|
2032
2032
|
/*
|
2033
2033
|
* call-seq:
|
2034
|
-
* easy.on_redirect {|easy,code| ... } =>
|
2034
|
+
* easy.on_redirect {|easy,code| ... } => <old handler;>
|
2035
2035
|
*
|
2036
2036
|
* Assign or remove the on_redirect handler for this Curl::Easy instance.
|
2037
2037
|
* To remove a previously-supplied handler, call this method with no attached
|
@@ -2046,7 +2046,7 @@ static VALUE ruby_curl_easy_on_redirect_set(int argc, VALUE *argv, VALUE self) {
|
|
2046
2046
|
|
2047
2047
|
/*
|
2048
2048
|
* call-seq:
|
2049
|
-
* easy.on_complete {|easy| ... } =>
|
2049
|
+
* easy.on_complete {|easy| ... } => <old handler>
|
2050
2050
|
*
|
2051
2051
|
* Assign or remove the +on_complete+ handler for this Curl::Easy instance.
|
2052
2052
|
* To remove a previously-supplied handler, call this method with no
|
@@ -2060,7 +2060,7 @@ static VALUE ruby_curl_easy_on_complete_set(int argc, VALUE *argv, VALUE self) {
|
|
2060
2060
|
|
2061
2061
|
/*
|
2062
2062
|
* call-seq:
|
2063
|
-
* easy.on_header { |header_data| ... } =>
|
2063
|
+
* easy.on_header { |header_data| ... } => <old handler>
|
2064
2064
|
*
|
2065
2065
|
* Assign or remove the +on_header+ handler for this Curl::Easy instance.
|
2066
2066
|
* To remove a previously-supplied handler, call this method with no
|
@@ -2076,7 +2076,7 @@ static VALUE ruby_curl_easy_on_header_set(int argc, VALUE *argv, VALUE self) {
|
|
2076
2076
|
|
2077
2077
|
/*
|
2078
2078
|
* call-seq:
|
2079
|
-
* easy.on_progress { |dl_total, dl_now, ul_total, ul_now| ... } =>
|
2079
|
+
* easy.on_progress { |dl_total, dl_now, ul_total, ul_now| ... } => <old handler>
|
2080
2080
|
*
|
2081
2081
|
* Assign or remove the +on_progress+ handler for this Curl::Easy instance.
|
2082
2082
|
* To remove a previously-supplied handler, call this method with no
|
@@ -2097,7 +2097,7 @@ static VALUE ruby_curl_easy_on_progress_set(int argc, VALUE *argv, VALUE self) {
|
|
2097
2097
|
|
2098
2098
|
/*
|
2099
2099
|
* call-seq:
|
2100
|
-
* easy.on_debug { |type, data| ... } =>
|
2100
|
+
* easy.on_debug { |type, data| ... } => <old handler>
|
2101
2101
|
*
|
2102
2102
|
* Assign or remove the +on_debug+ handler for this Curl::Easy instance.
|
2103
2103
|
* To remove a previously-supplied handler, call this method with no
|
@@ -2122,7 +2122,7 @@ static VALUE ruby_curl_easy_on_debug_set(int argc, VALUE *argv, VALUE self) {
|
|
2122
2122
|
/***********************************************
|
2123
2123
|
* This is an rb_iterate callback used to set up http headers.
|
2124
2124
|
*/
|
2125
|
-
static VALUE cb_each_http_header(VALUE header, VALUE wrap) {
|
2125
|
+
static VALUE cb_each_http_header(VALUE header, VALUE wrap, int _c, const VALUE *_ptr, VALUE unused) {
|
2126
2126
|
struct curl_slist **list;
|
2127
2127
|
VALUE header_str = Qnil;
|
2128
2128
|
|
@@ -2136,11 +2136,14 @@ static VALUE cb_each_http_header(VALUE header, VALUE wrap) {
|
|
2136
2136
|
|
2137
2137
|
name = rb_obj_as_string(rb_ary_entry(header, 0));
|
2138
2138
|
value = rb_obj_as_string(rb_ary_entry(header, 1));
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2139
|
+
if (rb_str_strlen(value) == 0) { // removing the header e.g. Accept: with nothing trailing should remove it see: https://curl.se/libcurl/c/CURLOPT_HTTPHEADER.html
|
2140
|
+
header_str = rb_str_plus(name, rb_str_new2(":"));
|
2141
|
+
} else {
|
2142
|
+
// This is a bit inefficient, but we don't want to be modifying
|
2143
|
+
// the actual values in the original hash.
|
2144
|
+
header_str = rb_str_plus(name, rb_str_new2(": "));
|
2145
|
+
header_str = rb_str_plus(header_str, value);
|
2146
|
+
}
|
2144
2147
|
} else {
|
2145
2148
|
header_str = rb_obj_as_string(header);
|
2146
2149
|
}
|
@@ -2154,7 +2157,7 @@ static VALUE cb_each_http_header(VALUE header, VALUE wrap) {
|
|
2154
2157
|
/***********************************************
|
2155
2158
|
* This is an rb_iterate callback used to set up http proxy headers.
|
2156
2159
|
*/
|
2157
|
-
static VALUE cb_each_http_proxy_header(VALUE proxy_header, VALUE wrap) {
|
2160
|
+
static VALUE cb_each_http_proxy_header(VALUE proxy_header, VALUE wrap, int _c, const VALUE *_ptr, VALUE unused) {
|
2158
2161
|
struct curl_slist **list;
|
2159
2162
|
VALUE proxy_header_str = Qnil;
|
2160
2163
|
|
@@ -2186,7 +2189,7 @@ static VALUE cb_each_http_proxy_header(VALUE proxy_header, VALUE wrap) {
|
|
2186
2189
|
/***********************************************
|
2187
2190
|
* This is an rb_iterate callback used to set up ftp commands.
|
2188
2191
|
*/
|
2189
|
-
static VALUE cb_each_ftp_command(VALUE ftp_command, VALUE wrap) {
|
2192
|
+
static VALUE cb_each_ftp_command(VALUE ftp_command, VALUE wrap, int _c, const VALUE *_ptr, VALUE unused) {
|
2190
2193
|
struct curl_slist **list;
|
2191
2194
|
VALUE ftp_command_string;
|
2192
2195
|
Data_Get_Struct(wrap, struct curl_slist *, list);
|
@@ -2200,7 +2203,7 @@ static VALUE cb_each_ftp_command(VALUE ftp_command, VALUE wrap) {
|
|
2200
2203
|
/***********************************************
|
2201
2204
|
* This is an rb_iterate callback used to set up the resolve list.
|
2202
2205
|
*/
|
2203
|
-
static VALUE cb_each_resolve(VALUE resolve, VALUE wrap) {
|
2206
|
+
static VALUE cb_each_resolve(VALUE resolve, VALUE wrap, int _c, const VALUE *_ptr, VALUE unused) {
|
2204
2207
|
struct curl_slist **list;
|
2205
2208
|
VALUE resolve_string;
|
2206
2209
|
Data_Get_Struct(wrap, struct curl_slist *, list);
|
@@ -2599,7 +2602,7 @@ VALUE ruby_curl_easy_cleanup( VALUE self, ruby_curl_easy *rbce ) {
|
|
2599
2602
|
}
|
2600
2603
|
|
2601
2604
|
// set values on cleanup to nil
|
2602
|
-
rb_easy_del("multi");
|
2605
|
+
//rb_easy_del("multi");
|
2603
2606
|
|
2604
2607
|
return Qnil;
|
2605
2608
|
}
|
@@ -2775,6 +2778,10 @@ static VALUE ruby_curl_easy_perform_put(VALUE self, VALUE data) {
|
|
2775
2778
|
* your own body handler, this string will be empty.
|
2776
2779
|
*/
|
2777
2780
|
static VALUE ruby_curl_easy_body_str_get(VALUE self) {
|
2781
|
+
/*
|
2782
|
+
TODO: can we force_encoding on the return here if we see charset=utf-8 in the content-type header?
|
2783
|
+
Content-Type: application/json; charset=utf-8
|
2784
|
+
*/
|
2778
2785
|
CURB_OBJECT_HGETTER(ruby_curl_easy, body_data);
|
2779
2786
|
}
|
2780
2787
|
|
@@ -3646,6 +3653,11 @@ static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
|
|
3646
3653
|
case CURLOPT_SSL_SESSIONID_CACHE:
|
3647
3654
|
curl_easy_setopt(rbce->curl, CURLOPT_SSL_SESSIONID_CACHE, NUM2LONG(val));
|
3648
3655
|
break;
|
3656
|
+
#endif
|
3657
|
+
#if HAVE_CURLOPT_PROXY_SSL_VERIFYHOST
|
3658
|
+
case CURLOPT_PROXY_SSL_VERIFYHOST:
|
3659
|
+
curl_easy_setopt(rbce->curl, CURLOPT_PROXY_SSL_VERIFYHOST, NUM2LONG(val));
|
3660
|
+
break;
|
3649
3661
|
#endif
|
3650
3662
|
default:
|
3651
3663
|
rb_raise(rb_eTypeError, "Curb unsupported option");
|
@@ -3763,6 +3775,7 @@ static VALUE ruby_curl_easy_error_message(VALUE klass, VALUE code) {
|
|
3763
3775
|
}
|
3764
3776
|
|
3765
3777
|
/* =================== INIT LIB =====================*/
|
3778
|
+
// TODO: https://bugs.ruby-lang.org/issues/18007
|
3766
3779
|
void init_curb_easy() {
|
3767
3780
|
idCall = rb_intern("call");
|
3768
3781
|
idJoin = rb_intern("join");
|
@@ -3908,6 +3921,7 @@ void init_curb_easy() {
|
|
3908
3921
|
|
3909
3922
|
rb_define_method(cCurlEasy, "last_effective_url", ruby_curl_easy_last_effective_url_get, 0);
|
3910
3923
|
rb_define_method(cCurlEasy, "response_code", ruby_curl_easy_response_code_get, 0);
|
3924
|
+
rb_define_method(cCurlEasy, "code", ruby_curl_easy_response_code_get, 0);
|
3911
3925
|
#if defined(HAVE_CURLINFO_PRIMARY_IP)
|
3912
3926
|
rb_define_method(cCurlEasy, "primary_ip", ruby_curl_easy_primary_ip_get, 0);
|
3913
3927
|
#endif
|
data/ext/curb_macros.h
CHANGED
@@ -156,4 +156,16 @@
|
|
156
156
|
#define CURB_DEFINE(name) \
|
157
157
|
rb_define_const(mCurl, #name, LONG2NUM(name))
|
158
158
|
|
159
|
+
/* copy and raise exception */
|
160
|
+
#define CURB_CHECK_RB_CALLBACK_RAISE(did_raise) \
|
161
|
+
VALUE exception = rb_hash_aref(did_raise, rb_easy_hkey("error")); \
|
162
|
+
if (FIX2INT(rb_hash_size(did_raise)) > 0 && exception != Qnil) { \
|
163
|
+
rb_hash_clear(did_raise); \
|
164
|
+
VALUE message = rb_funcall(exception, rb_intern("message"), 0); \
|
165
|
+
VALUE aborted_exception = rb_exc_new_str(eCurlErrAbortedByCallback, message); \
|
166
|
+
VALUE backtrace = rb_funcall(exception, rb_intern("backtrace"), 0); \
|
167
|
+
rb_funcall(aborted_exception, rb_intern("set_backtrace"), 1, backtrace); \
|
168
|
+
rb_exc_raise(aborted_exception); \
|
169
|
+
}
|
170
|
+
|
159
171
|
#endif
|