curb 0.7.18 → 0.8.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.
- data/README +1 -1
- data/ext/curb.h +5 -5
- data/ext/curb_easy.c +49 -7
- data/ext/curb_multi.c +11 -1
- data/tests/bug_crash_on_debug.rb +39 -0
- data/tests/helper.rb +8 -0
- data/tests/tc_curl_easy.rb +36 -2
- metadata +4 -2
data/README
CHANGED
@@ -120,7 +120,7 @@ Same thing, more manual:
|
|
120
120
|
|
121
121
|
c = Curl::Easy.new("http://my.rails.box/files/upload")
|
122
122
|
c.multipart_form_post = true
|
123
|
-
c.http_post(Curl::PostField.file('myfile.rb'))
|
123
|
+
c.http_post(Curl::PostField.file('thing[file]', 'myfile.rb'))
|
124
124
|
|
125
125
|
### Multi Interface (Basic HTTP GET):
|
126
126
|
|
data/ext/curb.h
CHANGED
@@ -20,12 +20,12 @@
|
|
20
20
|
#include "curb_macros.h"
|
21
21
|
|
22
22
|
// These should be managed from the Rake 'release' task.
|
23
|
-
#define CURB_VERSION "0.
|
24
|
-
#define CURB_VER_NUM
|
23
|
+
#define CURB_VERSION "0.8.0"
|
24
|
+
#define CURB_VER_NUM 800
|
25
25
|
#define CURB_VER_MAJ 0
|
26
|
-
#define CURB_VER_MIN
|
27
|
-
#define CURB_VER_MIC
|
28
|
-
#define CURB_VER_PATCH
|
26
|
+
#define CURB_VER_MIN 8
|
27
|
+
#define CURB_VER_MIC 0
|
28
|
+
#define CURB_VER_PATCH 0
|
29
29
|
|
30
30
|
|
31
31
|
// Maybe not yet defined in Ruby
|
data/ext/curb_easy.c
CHANGED
@@ -219,6 +219,7 @@ static void ruby_curl_easy_zero(ruby_curl_easy *rbce) {
|
|
219
219
|
rbce->ssl_version = -1;
|
220
220
|
rbce->use_ssl = -1;
|
221
221
|
rbce->ftp_filemethod = -1;
|
222
|
+
rbce->resolve_mode = CURL_IPRESOLVE_WHATEVER;
|
222
223
|
|
223
224
|
/* bool opts */
|
224
225
|
rbce->proxy_tunnel = 0;
|
@@ -1715,6 +1716,36 @@ static VALUE ruby_curl_easy_on_failure_set(int argc, VALUE *argv, VALUE self) {
|
|
1715
1716
|
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, failure_proc);
|
1716
1717
|
}
|
1717
1718
|
|
1719
|
+
/*
|
1720
|
+
* call-seq:
|
1721
|
+
* easy.on_missing {|easy,code| ... } => <old handler;>
|
1722
|
+
*
|
1723
|
+
* Assign or remove the on_missing handler for this Curl::Easy instance.
|
1724
|
+
* To remove a previously-supplied handler, call this method with no attached
|
1725
|
+
* block.
|
1726
|
+
*
|
1727
|
+
* The +on_missing+ handler is called when request is finished with a
|
1728
|
+
* status of 40x
|
1729
|
+
*/
|
1730
|
+
static VALUE ruby_curl_easy_on_missing_set(int argc, VALUE *argv, VALUE self) {
|
1731
|
+
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, missing_proc);
|
1732
|
+
}
|
1733
|
+
|
1734
|
+
/*
|
1735
|
+
* call-seq:
|
1736
|
+
* easy.on_redirect {|easy,code| ... } => <old handler;>
|
1737
|
+
*
|
1738
|
+
* Assign or remove the on_redirect handler for this Curl::Easy instance.
|
1739
|
+
* To remove a previously-supplied handler, call this method with no attached
|
1740
|
+
* block.
|
1741
|
+
*
|
1742
|
+
* The +on_redirect+ handler is called when request is finished with a
|
1743
|
+
* status of 30x
|
1744
|
+
*/
|
1745
|
+
static VALUE ruby_curl_easy_on_redirect_set(int argc, VALUE *argv, VALUE self) {
|
1746
|
+
CURB_HANDLER_PROC_HSETTER(ruby_curl_easy, redirect_proc);
|
1747
|
+
}
|
1748
|
+
|
1718
1749
|
/*
|
1719
1750
|
* call-seq:
|
1720
1751
|
* easy.on_complete {|easy| ... } => <old handler>
|
@@ -1856,7 +1887,6 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
|
|
1856
1887
|
|
1857
1888
|
url = rb_check_string_type(_url);
|
1858
1889
|
|
1859
|
-
// Need to configure the handler as per settings in rbce
|
1860
1890
|
curl_easy_setopt(curl, CURLOPT_URL, StringValuePtr(url));
|
1861
1891
|
|
1862
1892
|
// network stuff and auth
|
@@ -2291,6 +2321,17 @@ static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
|
|
2291
2321
|
for (i = 0; i < argc; i++) {
|
2292
2322
|
if (rb_obj_is_instance_of(argv[i], cCurlPostField)) {
|
2293
2323
|
append_to_form(argv[i], &first, &last);
|
2324
|
+
} else if (rb_type(argv[i]) == T_ARRAY) {
|
2325
|
+
// see: https://github.com/rvanlieshout/curb/commit/8bcdefddc0162484681ebd1a92d52a642666a445
|
2326
|
+
int c = 0, argv_len = (int)RARRAY_LEN(argv[i]);
|
2327
|
+
for (; c < argv_len; ++c) {
|
2328
|
+
if (rb_obj_is_instance_of(rb_ary_entry(argv[i],c), cCurlPostField)) {
|
2329
|
+
append_to_form(rb_ary_entry(argv[i],c), &first, &last);
|
2330
|
+
} else {
|
2331
|
+
rb_raise(eCurlErrInvalidPostField, "You must use PostFields only with multipart form posts");
|
2332
|
+
return Qnil;
|
2333
|
+
}
|
2334
|
+
}
|
2294
2335
|
} else {
|
2295
2336
|
rb_raise(eCurlErrInvalidPostField, "You must use PostFields only with multipart form posts");
|
2296
2337
|
return Qnil;
|
@@ -2364,10 +2405,9 @@ static VALUE ruby_curl_easy_set_head_option(VALUE self, VALUE onoff) {
|
|
2364
2405
|
|
2365
2406
|
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
2366
2407
|
|
2367
|
-
if(
|
2408
|
+
if (onoff == Qtrue) {
|
2368
2409
|
curl_easy_setopt(rbce->curl, CURLOPT_NOBODY, 1);
|
2369
|
-
}
|
2370
|
-
else {
|
2410
|
+
} else {
|
2371
2411
|
curl_easy_setopt(rbce->curl, CURLOPT_NOBODY, 0);
|
2372
2412
|
}
|
2373
2413
|
|
@@ -2384,13 +2424,13 @@ static VALUE ruby_curl_easy_set_head_option(VALUE self, VALUE onoff) {
|
|
2384
2424
|
static VALUE ruby_curl_easy_perform_put(VALUE self, VALUE data) {
|
2385
2425
|
ruby_curl_easy *rbce;
|
2386
2426
|
CURL *curl;
|
2387
|
-
|
2427
|
+
|
2388
2428
|
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
2389
2429
|
curl = rbce->curl;
|
2390
|
-
|
2430
|
+
|
2391
2431
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
|
2392
2432
|
ruby_curl_easy_put_data_set(self, data);
|
2393
|
-
|
2433
|
+
|
2394
2434
|
return rb_funcall(self, rb_intern("perform"), 0);
|
2395
2435
|
}
|
2396
2436
|
|
@@ -3308,6 +3348,8 @@ void init_curb_easy() {
|
|
3308
3348
|
rb_define_method(cCurlEasy, "on_debug", ruby_curl_easy_on_debug_set, -1);
|
3309
3349
|
rb_define_method(cCurlEasy, "on_success", ruby_curl_easy_on_success_set, -1);
|
3310
3350
|
rb_define_method(cCurlEasy, "on_failure", ruby_curl_easy_on_failure_set, -1);
|
3351
|
+
rb_define_method(cCurlEasy, "on_missing", ruby_curl_easy_on_missing_set, -1);
|
3352
|
+
rb_define_method(cCurlEasy, "on_redirect", ruby_curl_easy_on_redirect_set, -1);
|
3311
3353
|
rb_define_method(cCurlEasy, "on_complete", ruby_curl_easy_on_complete_set, -1);
|
3312
3354
|
|
3313
3355
|
rb_define_method(cCurlEasy, "http", ruby_curl_easy_perform_verb, 1);
|
data/ext/curb_multi.c
CHANGED
@@ -374,8 +374,18 @@ static void rb_curl_mutli_handle_complete(VALUE self, CURL *easy_handle, int res
|
|
374
374
|
val = rb_rescue(call_status_handler1, callargs, callback_exception, Qnil);
|
375
375
|
//rb_funcall( rb_easy_get("success_proc"), idCall, 1, easy );
|
376
376
|
}
|
377
|
+
else if (!rb_easy_nil("redirect_proc") &&
|
378
|
+
(response_code >= 300 && response_code < 400)) {
|
379
|
+
callargs = rb_ary_new3(3, rb_easy_get("redirect_proc"), easy, rb_curl_easy_error(result));
|
380
|
+
val = rb_rescue(call_status_handler2, callargs, callback_exception, Qnil);
|
381
|
+
}
|
382
|
+
else if (!rb_easy_nil("missing_proc") &&
|
383
|
+
(response_code >= 400 && response_code < 500)) {
|
384
|
+
callargs = rb_ary_new3(3, rb_easy_get("missing_proc"), easy, rb_curl_easy_error(result));
|
385
|
+
val = rb_rescue(call_status_handler2, callargs, callback_exception, Qnil);
|
386
|
+
}
|
377
387
|
else if (!rb_easy_nil("failure_proc") &&
|
378
|
-
(response_code >=
|
388
|
+
(response_code >= 500 && response_code <= 999)) {
|
379
389
|
callargs = rb_ary_new3(3, rb_easy_get("failure_proc"), easy, rb_curl_easy_error(result));
|
380
390
|
val = rb_rescue(call_status_handler2, callargs, callback_exception, Qnil);
|
381
391
|
//rb_funcall( rb_easy_get("failure_proc"), idCall, 2, easy, rb_curl_easy_error(result) );
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
require 'webrick'
|
4
|
+
class ::WEBrick::HTTPServer ; def access_log(config, req, res) ; end ; end
|
5
|
+
class ::WEBrick::BasicLog ; def log(level, data) ; end ; end
|
6
|
+
|
7
|
+
require 'curl'
|
8
|
+
|
9
|
+
class BugCrashOnDebug < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_on_debug
|
12
|
+
server = WEBrick::HTTPServer.new( :Port => 9999 )
|
13
|
+
server.mount_proc("/test") do|req,res|
|
14
|
+
res.body = "hi"
|
15
|
+
res['Content-Type'] = "text/html"
|
16
|
+
end
|
17
|
+
puts 'a'
|
18
|
+
thread = Thread.new(server) do|srv|
|
19
|
+
srv.start
|
20
|
+
end
|
21
|
+
puts 'b'
|
22
|
+
c = Curl::Easy.new('http://localhost:9999/test')
|
23
|
+
c.on_debug do|x|
|
24
|
+
puts x.inspect
|
25
|
+
raise "error" # this will get swallowed
|
26
|
+
end
|
27
|
+
c.perform
|
28
|
+
puts 'c'
|
29
|
+
ensure
|
30
|
+
puts 'd'
|
31
|
+
server.shutdown
|
32
|
+
puts 'e'
|
33
|
+
puts thread.exit
|
34
|
+
puts 'f'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
#test_on_debug
|
data/tests/helper.rb
CHANGED
@@ -65,6 +65,14 @@ class TestServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def do_GET(req,res)
|
68
|
+
if req.path.match /redirect$/
|
69
|
+
res.status = 302
|
70
|
+
res['Location'] = '/foo'
|
71
|
+
elsif req.path.match /not_here$/
|
72
|
+
res.status = 404
|
73
|
+
elsif req.path.match /error$/
|
74
|
+
res.status = 500
|
75
|
+
end
|
68
76
|
respond_with(:GET,req,res)
|
69
77
|
end
|
70
78
|
|
data/tests/tc_curl_easy.rb
CHANGED
@@ -561,13 +561,34 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
561
561
|
end
|
562
562
|
|
563
563
|
def test_on_success_with_on_failure
|
564
|
-
curl = Curl::Easy.new(
|
564
|
+
curl = Curl::Easy.new(TestServlet.url + '/error')
|
565
565
|
on_failure_called = false
|
566
566
|
curl.on_success {|c| } # make sure we get the failure call even though this handler is defined
|
567
567
|
curl.on_failure {|c,code| on_failure_called = true }
|
568
568
|
curl.perform
|
569
|
+
assert_equal 500, curl.response_code
|
569
570
|
assert on_failure_called, "Failure handler not called"
|
570
571
|
end
|
572
|
+
|
573
|
+
def test_on_success_with_on_missing
|
574
|
+
curl = Curl::Easy.new(TestServlet.url + '/not_here')
|
575
|
+
on_missing_called = false
|
576
|
+
curl.on_success {|c| } # make sure we get the missing call even though this handler is defined
|
577
|
+
curl.on_missing {|c,code| on_missing_called = true }
|
578
|
+
curl.perform
|
579
|
+
assert_equal 404, curl.response_code
|
580
|
+
assert on_missing_called, "Missing handler not called"
|
581
|
+
end
|
582
|
+
|
583
|
+
def test_on_success_with_on_redirect
|
584
|
+
curl = Curl::Easy.new(TestServlet.url + '/redirect')
|
585
|
+
on_redirect_called = false
|
586
|
+
curl.on_success {|c| } # make sure we get the redirect call even though this handler is defined
|
587
|
+
curl.on_redirect {|c,code| on_redirect_called = true }
|
588
|
+
curl.perform
|
589
|
+
assert_equal 302, curl.response_code
|
590
|
+
assert on_redirect_called, "Redirect handler not called"
|
591
|
+
end
|
571
592
|
|
572
593
|
def test_get_remote
|
573
594
|
curl = Curl::Easy.new(TestServlet.url)
|
@@ -600,6 +621,19 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
600
621
|
end
|
601
622
|
end
|
602
623
|
end
|
624
|
+
|
625
|
+
# see: https://github.com/rvanlieshout/curb/commit/8bcdefddc0162484681ebd1a92d52a642666a445
|
626
|
+
def test_post_multipart_array_remote
|
627
|
+
curl = Curl::Easy.new(TestServlet.url)
|
628
|
+
curl.multipart_form_post = true
|
629
|
+
fields = [
|
630
|
+
Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README'))),
|
631
|
+
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
632
|
+
]
|
633
|
+
curl.http_post(fields)
|
634
|
+
assert_match /HTTP POST file upload/, curl.body_str
|
635
|
+
assert_match /Content-Disposition: form-data/, curl.body_str
|
636
|
+
end
|
603
637
|
|
604
638
|
def test_post_with_body_remote
|
605
639
|
curl = Curl::Easy.new(TestServlet.url)
|
@@ -703,7 +737,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
703
737
|
|
704
738
|
def test_put_remote_file
|
705
739
|
curl = Curl::Easy.new(TestServlet.url)
|
706
|
-
File.open(__FILE__,'
|
740
|
+
File.open(__FILE__,'rb') do|f|
|
707
741
|
assert curl.http_put(f)
|
708
742
|
end
|
709
743
|
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-01-
|
13
|
+
date: 2012-01-19 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings
|
16
16
|
for the libcurl(3), a fully-featured client-side URL transfer library. cURL and
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- ext/curb_postfield.h
|
47
47
|
- ext/curb_upload.h
|
48
48
|
- tests/alltests.rb
|
49
|
+
- tests/bug_crash_on_debug.rb
|
49
50
|
- tests/bug_crash_on_progress.rb
|
50
51
|
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
51
52
|
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
@@ -95,6 +96,7 @@ specification_version: 3
|
|
95
96
|
summary: Ruby libcurl bindings
|
96
97
|
test_files:
|
97
98
|
- tests/alltests.rb
|
99
|
+
- tests/bug_crash_on_debug.rb
|
98
100
|
- tests/bug_crash_on_progress.rb
|
99
101
|
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
100
102
|
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|