curb 0.8.5 → 0.9.11
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.
- checksums.yaml +7 -0
- data/README.markdown +277 -0
- data/Rakefile +29 -18
- data/ext/banned.h +32 -0
- data/ext/curb.c +148 -46
- data/ext/curb.h +14 -10
- data/ext/curb_easy.c +582 -98
- data/ext/curb_easy.h +6 -0
- data/ext/curb_errors.c +113 -16
- data/ext/curb_errors.h +8 -5
- data/ext/curb_macros.h +7 -7
- data/ext/curb_multi.c +175 -167
- data/ext/curb_multi.h +0 -1
- data/ext/curb_upload.c +2 -2
- data/ext/extconf.rb +46 -17
- data/lib/curb.rb +1 -0
- data/lib/curl/easy.rb +77 -59
- data/lib/curl/multi.rb +59 -20
- data/lib/curl.rb +14 -9
- data/tests/bug_crash_on_progress.rb +41 -1
- data/tests/bug_issue102.rb +17 -0
- data/tests/bug_issue277.rb +32 -0
- data/tests/helper.rb +102 -13
- data/tests/tc_curl.rb +31 -1
- data/tests/tc_curl_download.rb +4 -4
- data/tests/tc_curl_easy.rb +195 -45
- data/tests/tc_curl_easy_resolve.rb +16 -0
- data/tests/tc_curl_maxfilesize.rb +12 -0
- data/tests/tc_curl_multi.rb +82 -16
- data/tests/tc_curl_postfield.rb +29 -29
- data/tests/timeout.rb +10 -2
- metadata +52 -46
- data/README +0 -194
data/tests/tc_curl_easy.rb
CHANGED
|
@@ -4,6 +4,82 @@ class FooNoToS
|
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
class TestCurbCurlEasy < Test::Unit::TestCase
|
|
7
|
+
def test_global_reset
|
|
8
|
+
Curl.get($TEST_URL)
|
|
9
|
+
# in a Timeout block you should reset the thread current handle
|
|
10
|
+
Curl.reset
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_curlopt_stderr_with_file
|
|
14
|
+
# does not work with Tempfile directly
|
|
15
|
+
path = Tempfile.new('curb_test_curlopt_stderr').path
|
|
16
|
+
File.open(path, 'w') do |file|
|
|
17
|
+
easy = Curl::Easy.new(TestServlet.url)
|
|
18
|
+
easy.verbose = true
|
|
19
|
+
easy.setopt(Curl::CURLOPT_STDERR, file)
|
|
20
|
+
easy.perform
|
|
21
|
+
end
|
|
22
|
+
output = File.read(path)
|
|
23
|
+
|
|
24
|
+
assert_match('HTTP/1.1 200 OK ', output)
|
|
25
|
+
assert_match('Host: 127.0.0.1:9129', output)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_curlopt_stderr_with_io
|
|
29
|
+
path = Tempfile.new('curb_test_curlopt_stderr').path
|
|
30
|
+
fd = IO.sysopen(path, 'w')
|
|
31
|
+
io = IO.for_fd(fd)
|
|
32
|
+
|
|
33
|
+
easy = Curl::Easy.new(TestServlet.url)
|
|
34
|
+
easy.verbose = true
|
|
35
|
+
easy.setopt(Curl::CURLOPT_STDERR, io)
|
|
36
|
+
easy.perform
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
output = File.read(path)
|
|
40
|
+
|
|
41
|
+
assert_match(output, 'HTTP/1.1 200 OK')
|
|
42
|
+
assert_match(output, 'Host: 127.0.0.1:9129')
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_curlopt_stderr_fails_with_tempdir
|
|
46
|
+
Tempfile.open('curb_test_curlopt_stderr') do |tempfile|
|
|
47
|
+
easy = Curl::Easy.new(TestServlet.url)
|
|
48
|
+
|
|
49
|
+
assert_raise(TypeError) do
|
|
50
|
+
easy.setopt(Curl::CURLOPT_STDERR, tempfile)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_curlopt_stderr_fails_with_stringio
|
|
56
|
+
stringio = StringIO.new
|
|
57
|
+
easy = Curl::Easy.new(TestServlet.url)
|
|
58
|
+
|
|
59
|
+
assert_raise(TypeError) do
|
|
60
|
+
easy.setopt(Curl::CURLOPT_STDERR, stringio)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_curlopt_stderr_fails_with_string
|
|
65
|
+
string = String.new
|
|
66
|
+
easy = Curl::Easy.new(TestServlet.url)
|
|
67
|
+
|
|
68
|
+
assert_raise(TypeError) do
|
|
69
|
+
easy.setopt(Curl::CURLOPT_STDERR, string)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_exception
|
|
74
|
+
begin
|
|
75
|
+
Curl.get('NOT_FOUND_URL')
|
|
76
|
+
rescue
|
|
77
|
+
assert true
|
|
78
|
+
rescue Exception
|
|
79
|
+
assert false, "We should raise StandardError"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
7
83
|
def test_threads
|
|
8
84
|
t = []
|
|
9
85
|
5.times do
|
|
@@ -12,20 +88,17 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
12
88
|
c = Curl.get($TEST_URL)
|
|
13
89
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
|
14
90
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
|
|
15
|
-
assert_equal "", c.header_str
|
|
16
|
-
assert_equal "", c.head
|
|
17
91
|
end
|
|
18
92
|
end
|
|
19
93
|
end
|
|
20
94
|
|
|
21
|
-
t.each {|
|
|
95
|
+
t.each {|x| x.join }
|
|
22
96
|
end
|
|
23
97
|
|
|
24
98
|
def test_class_perform_01
|
|
25
99
|
assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
|
|
26
100
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
|
27
101
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
|
|
28
|
-
assert_equal "", c.header_str
|
|
29
102
|
end
|
|
30
103
|
|
|
31
104
|
def test_class_perform_02
|
|
@@ -33,12 +106,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
33
106
|
assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL) { |curl| curl.on_body { |d| data << d; d.length } }
|
|
34
107
|
|
|
35
108
|
assert_nil c.body_str
|
|
36
|
-
assert_equal "", c.header_str
|
|
37
109
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
|
|
38
110
|
end
|
|
39
111
|
|
|
40
112
|
def test_class_perform_03
|
|
41
|
-
assert_raise(Curl::Err::CouldntReadError) {
|
|
113
|
+
assert_raise(Curl::Err::CouldntReadError) { Curl::Easy.perform($TEST_URL + "nonexistent") }
|
|
42
114
|
end
|
|
43
115
|
|
|
44
116
|
def test_new_01
|
|
@@ -128,7 +200,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
128
200
|
c = Curl::Easy.new($TEST_URL)
|
|
129
201
|
assert_equal true, c.http_get
|
|
130
202
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
|
131
|
-
assert_equal "", c.header_str
|
|
132
203
|
end
|
|
133
204
|
|
|
134
205
|
def test_get_02
|
|
@@ -140,7 +211,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
140
211
|
assert_equal true, c.http_get
|
|
141
212
|
|
|
142
213
|
assert_nil c.body_str
|
|
143
|
-
assert_equal "", c.header_str
|
|
144
214
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
|
|
145
215
|
end
|
|
146
216
|
|
|
@@ -323,19 +393,71 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
323
393
|
c.max_redirects = nil
|
|
324
394
|
assert_nil c.max_redirects
|
|
325
395
|
end
|
|
326
|
-
|
|
396
|
+
|
|
397
|
+
def test_timeout_with_floats
|
|
398
|
+
c = Curl::Easy.new($TEST_URL)
|
|
399
|
+
|
|
400
|
+
c.timeout = 1.5
|
|
401
|
+
assert_equal 1500, c.timeout_ms
|
|
402
|
+
assert_equal 1.5, c.timeout
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
def test_timeout_with_negative
|
|
406
|
+
c = Curl::Easy.new($TEST_URL)
|
|
407
|
+
|
|
408
|
+
c.timeout = -1.5
|
|
409
|
+
assert_equal 0, c.timeout
|
|
410
|
+
assert_equal 0, c.timeout_ms
|
|
411
|
+
|
|
412
|
+
c.timeout = -4.8
|
|
413
|
+
assert_equal 0, c.timeout
|
|
414
|
+
assert_equal 0, c.timeout_ms
|
|
415
|
+
end
|
|
416
|
+
|
|
327
417
|
def test_timeout_01
|
|
328
418
|
c = Curl::Easy.new($TEST_URL)
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
419
|
+
|
|
420
|
+
assert_equal 0, c.timeout
|
|
421
|
+
|
|
332
422
|
c.timeout = 3
|
|
333
423
|
assert_equal 3, c.timeout
|
|
334
|
-
|
|
335
|
-
c.timeout =
|
|
336
|
-
|
|
424
|
+
|
|
425
|
+
c.timeout = 0
|
|
426
|
+
assert_equal 0, c.timeout
|
|
337
427
|
end
|
|
338
|
-
|
|
428
|
+
|
|
429
|
+
def test_timeout_ms_01
|
|
430
|
+
c = Curl::Easy.new($TEST_URL)
|
|
431
|
+
|
|
432
|
+
assert_equal 0, c.timeout_ms
|
|
433
|
+
|
|
434
|
+
c.timeout_ms = 100
|
|
435
|
+
assert_equal 100, c.timeout_ms
|
|
436
|
+
|
|
437
|
+
c.timeout_ms = nil
|
|
438
|
+
assert_equal 0, c.timeout_ms
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def test_timeout_ms_with_floats
|
|
442
|
+
c = Curl::Easy.new($TEST_URL)
|
|
443
|
+
|
|
444
|
+
c.timeout_ms = 55.5
|
|
445
|
+
assert_equal 55, c.timeout_ms
|
|
446
|
+
assert_equal 0.055, c.timeout
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
def test_timeout_ms_with_negative
|
|
450
|
+
c = Curl::Easy.new($TEST_URL)
|
|
451
|
+
|
|
452
|
+
c.timeout_ms = -1.5
|
|
453
|
+
assert_equal 0, c.timeout
|
|
454
|
+
assert_equal 0, c.timeout_ms
|
|
455
|
+
|
|
456
|
+
c.timeout_ms = -4.8
|
|
457
|
+
assert_equal 0, c.timeout
|
|
458
|
+
assert_equal 0, c.timeout_ms
|
|
459
|
+
end
|
|
460
|
+
|
|
339
461
|
def test_connect_timeout_01
|
|
340
462
|
c = Curl::Easy.new($TEST_URL)
|
|
341
463
|
|
|
@@ -347,7 +469,19 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
347
469
|
c.connect_timeout = nil
|
|
348
470
|
assert_nil c.connect_timeout
|
|
349
471
|
end
|
|
350
|
-
|
|
472
|
+
|
|
473
|
+
def test_connect_timeout_ms_01
|
|
474
|
+
c = Curl::Easy.new($TEST_URL)
|
|
475
|
+
|
|
476
|
+
assert_nil c.connect_timeout_ms
|
|
477
|
+
|
|
478
|
+
c.connect_timeout_ms = 100
|
|
479
|
+
assert_equal 100, c.connect_timeout_ms
|
|
480
|
+
|
|
481
|
+
c.connect_timeout_ms = nil
|
|
482
|
+
assert_nil c.connect_timeout_ms
|
|
483
|
+
end
|
|
484
|
+
|
|
351
485
|
def test_ftp_response_timeout_01
|
|
352
486
|
c = Curl::Easy.new($TEST_URL)
|
|
353
487
|
|
|
@@ -565,6 +699,15 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
565
699
|
assert_equal "some.file", c.cookiejar
|
|
566
700
|
end
|
|
567
701
|
|
|
702
|
+
def test_cookielist
|
|
703
|
+
c = Curl::Easy.new TestServlet.url
|
|
704
|
+
c.enable_cookies = true
|
|
705
|
+
c.post_body = URI.encode_www_form('c' => 'somename=somevalue')
|
|
706
|
+
assert_nil c.cookielist
|
|
707
|
+
c.perform
|
|
708
|
+
assert_match(/somevalue/, c.cookielist.join(''))
|
|
709
|
+
end
|
|
710
|
+
|
|
568
711
|
def test_on_success
|
|
569
712
|
curl = Curl::Easy.new($TEST_URL)
|
|
570
713
|
on_success_called = false
|
|
@@ -627,7 +770,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
627
770
|
retries = 0
|
|
628
771
|
begin
|
|
629
772
|
count = 0
|
|
630
|
-
|
|
773
|
+
Curl::Easy.send("http_#{method}", TestServlet.url) do|c|
|
|
631
774
|
count += 1
|
|
632
775
|
assert_equal Curl::Easy, c.class
|
|
633
776
|
end
|
|
@@ -645,12 +788,12 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
645
788
|
curl = Curl::Easy.new(TestServlet.url)
|
|
646
789
|
curl.multipart_form_post = true
|
|
647
790
|
fields = [
|
|
648
|
-
Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README'))),
|
|
649
|
-
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
|
791
|
+
Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))),
|
|
792
|
+
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
|
650
793
|
]
|
|
651
794
|
curl.http_post(fields)
|
|
652
|
-
assert_match
|
|
653
|
-
assert_match
|
|
795
|
+
assert_match(/HTTP POST file upload/, curl.body_str)
|
|
796
|
+
assert_match(/Content-Disposition: form-data/, curl.body_str)
|
|
654
797
|
end
|
|
655
798
|
|
|
656
799
|
def test_post_with_body_remote
|
|
@@ -674,10 +817,10 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
674
817
|
def test_post_multipart_file_remote
|
|
675
818
|
curl = Curl::Easy.new(TestServlet.url)
|
|
676
819
|
curl.multipart_form_post = true
|
|
677
|
-
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
|
820
|
+
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
|
678
821
|
curl.http_post(pf)
|
|
679
|
-
assert_match
|
|
680
|
-
assert_match
|
|
822
|
+
assert_match(/HTTP POST file upload/, curl.body_str)
|
|
823
|
+
assert_match(/Content-Disposition: form-data/, curl.body_str)
|
|
681
824
|
end
|
|
682
825
|
|
|
683
826
|
def test_delete_remote
|
|
@@ -699,7 +842,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
699
842
|
redirect = curl.header_str.match(/Location: (.*)/)
|
|
700
843
|
|
|
701
844
|
assert_equal '', curl.body_str
|
|
702
|
-
assert_match
|
|
845
|
+
assert_match('/nonexistent', redirect[1])
|
|
703
846
|
end
|
|
704
847
|
|
|
705
848
|
def test_head_accessor
|
|
@@ -710,7 +853,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
710
853
|
redirect = curl.header_str.match(/Location: (.*)/)
|
|
711
854
|
|
|
712
855
|
assert_equal '', curl.body_str
|
|
713
|
-
assert_match
|
|
856
|
+
assert_match('/nonexistent', redirect[1])
|
|
714
857
|
curl.head = false
|
|
715
858
|
curl.perform
|
|
716
859
|
assert_equal 'GET', curl.body_str
|
|
@@ -720,11 +863,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
720
863
|
curl = Curl::Easy.new(TestServlet.url)
|
|
721
864
|
curl.headers['Content-Type'] = 'application/json'
|
|
722
865
|
assert curl.http_put("message")
|
|
723
|
-
assert_match
|
|
724
|
-
assert_match
|
|
725
|
-
assert_match
|
|
726
|
-
assert_match
|
|
727
|
-
assert_match
|
|
866
|
+
assert_match(/^PUT/, curl.body_str)
|
|
867
|
+
assert_match(/message$/, curl.body_str)
|
|
868
|
+
assert_match(/message$/, curl.body)
|
|
869
|
+
assert_match(/application\/json/, curl.header_str)
|
|
870
|
+
assert_match(/application\/json/, curl.head)
|
|
728
871
|
end
|
|
729
872
|
|
|
730
873
|
def test_put_data
|
|
@@ -733,8 +876,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
733
876
|
|
|
734
877
|
curl.perform
|
|
735
878
|
|
|
736
|
-
assert_match
|
|
737
|
-
assert_match
|
|
879
|
+
assert_match(/^PUT/, curl.body_str)
|
|
880
|
+
assert_match(/message$/, curl.body_str)
|
|
738
881
|
end
|
|
739
882
|
|
|
740
883
|
# https://github.com/taf2/curb/issues/101
|
|
@@ -744,8 +887,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
744
887
|
|
|
745
888
|
curl.perform
|
|
746
889
|
|
|
747
|
-
assert_match
|
|
748
|
-
assert_match
|
|
890
|
+
assert_match(/^PUT/, curl.body_str)
|
|
891
|
+
assert_match("a\0b", curl.body_str)
|
|
749
892
|
end
|
|
750
893
|
|
|
751
894
|
def test_put_nil_data_no_crash
|
|
@@ -760,7 +903,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
760
903
|
File.open(__FILE__,'rb') do|f|
|
|
761
904
|
assert curl.http_put(f)
|
|
762
905
|
end
|
|
763
|
-
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
|
906
|
+
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
|
|
764
907
|
end
|
|
765
908
|
|
|
766
909
|
def test_put_class_method
|
|
@@ -770,7 +913,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
770
913
|
assert_equal Curl::Easy, c.class
|
|
771
914
|
end
|
|
772
915
|
assert_equal 1, count
|
|
773
|
-
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
|
916
|
+
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
|
|
774
917
|
end
|
|
775
918
|
|
|
776
919
|
# Generate a self-signed cert with
|
|
@@ -779,7 +922,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
779
922
|
def test_cert
|
|
780
923
|
curl = Curl::Easy.new(TestServlet.url)
|
|
781
924
|
curl.cert= File.join(File.dirname(__FILE__),"cert.pem")
|
|
782
|
-
assert_match
|
|
925
|
+
assert_match(/cert.pem$/,curl.cert)
|
|
783
926
|
end
|
|
784
927
|
|
|
785
928
|
def test_cert_with_password
|
|
@@ -787,7 +930,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
787
930
|
path = File.join(File.dirname(__FILE__),"cert.pem")
|
|
788
931
|
curl.certpassword = 'password'
|
|
789
932
|
curl.cert = path
|
|
790
|
-
assert_match
|
|
933
|
+
assert_match(/cert.pem$/,curl.cert)
|
|
791
934
|
end
|
|
792
935
|
|
|
793
936
|
def test_cert_type
|
|
@@ -808,7 +951,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
808
951
|
def test_ca_cert
|
|
809
952
|
curl = Curl::Easy.new(TestServlet.url)
|
|
810
953
|
curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")
|
|
811
|
-
assert_match
|
|
954
|
+
assert_match(/cacert.pem$/, curl.cacert)
|
|
812
955
|
end
|
|
813
956
|
|
|
814
957
|
def test_user_agent
|
|
@@ -855,7 +998,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
855
998
|
end
|
|
856
999
|
|
|
857
1000
|
def test_post_streaming
|
|
858
|
-
readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README'))
|
|
1001
|
+
readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))
|
|
859
1002
|
|
|
860
1003
|
pf = Curl::PostField.file("filename", readme)
|
|
861
1004
|
|
|
@@ -866,7 +1009,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
866
1009
|
easy.http_post(pf)
|
|
867
1010
|
|
|
868
1011
|
assert_not_equal(0,easy.body_str.size)
|
|
869
|
-
assert_equal(easy.body_str,File.read(readme))
|
|
1012
|
+
assert_equal(easy.body_str.tr("\r", ''), File.read(readme))
|
|
870
1013
|
end
|
|
871
1014
|
|
|
872
1015
|
|
|
@@ -962,8 +1105,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
962
1105
|
curl.headers['Accept'] = '*/*'
|
|
963
1106
|
curl.headers['Authorization'] = 'Foo Bar Biz Baz'
|
|
964
1107
|
curl.http_put(rd)
|
|
965
|
-
assert_match
|
|
966
|
-
assert_match
|
|
1108
|
+
assert_match(/^PUT/, curl.body_str)
|
|
1109
|
+
assert_match(/hello$/, curl.body_str)
|
|
967
1110
|
curl.header_str
|
|
968
1111
|
curl.body_str
|
|
969
1112
|
end
|
|
@@ -1022,6 +1165,13 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
1022
1165
|
end
|
|
1023
1166
|
end
|
|
1024
1167
|
|
|
1168
|
+
def test_set_unsupported_options
|
|
1169
|
+
curl = Curl::Easy.new
|
|
1170
|
+
assert_raises TypeError do
|
|
1171
|
+
curl.set(99999, 1)
|
|
1172
|
+
end
|
|
1173
|
+
end
|
|
1174
|
+
|
|
1025
1175
|
include TestServerMethods
|
|
1026
1176
|
|
|
1027
1177
|
def setup
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
2
|
+
|
|
3
|
+
class TestCurbCurlEasyResolve < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@easy = Curl::Easy.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_resolve
|
|
9
|
+
@easy.resolve = [ "example.com:80:127.0.0.1" ]
|
|
10
|
+
assert_equal @easy.resolve, [ "example.com:80:127.0.0.1" ]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_empty_resolve
|
|
14
|
+
assert_equal @easy.resolve, nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
2
|
+
|
|
3
|
+
class TestCurbCurlMaxFileSize < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@easy = Curl::Easy.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_maxfilesize
|
|
9
|
+
@easy.set(Curl::CURLOPT_MAXFILESIZE, 5000000)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
data/tests/tc_curl_multi.rb
CHANGED
|
@@ -6,6 +6,70 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
6
6
|
ObjectSpace.garbage_collect
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
# for https://github.com/taf2/curb/issues/277
|
|
10
|
+
# must connect to an external
|
|
11
|
+
def test_connection_keepalive
|
|
12
|
+
# 0123456 default & reserved RubyVM. It will probably include 7 from Dir.glob
|
|
13
|
+
lsof=`/usr/bin/which lsof`.strip
|
|
14
|
+
open_fds = lambda do
|
|
15
|
+
`#{lsof} -p #{Process.pid} | egrep "TCP|UDP" | wc -l`.strip.to_i
|
|
16
|
+
end
|
|
17
|
+
before_open = open_fds.call
|
|
18
|
+
assert !Curl::Multi.autoclose
|
|
19
|
+
multi = Curl::Multi.new
|
|
20
|
+
multi.max_connects = 1 # limit to 1 connection within the multi handle
|
|
21
|
+
|
|
22
|
+
did_complete = false
|
|
23
|
+
5.times do |n|
|
|
24
|
+
# NOTE: we use google here because connecting to our TEST_URL as a local host address appears to not register correctly with lsof as a socket... if anyone knows a better way would be great to not have an external dependency here in the test
|
|
25
|
+
easy = Curl::Easy.new("http://google.com/") do |curl|
|
|
26
|
+
curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
|
|
27
|
+
curl.on_complete {
|
|
28
|
+
did_complete = true
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
multi.add(easy)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
multi.perform
|
|
35
|
+
assert did_complete
|
|
36
|
+
after_open = open_fds.call
|
|
37
|
+
assert_equal (after_open - before_open), 1, "with max connections set to 1 at this point the connection to google should still be open"
|
|
38
|
+
multi.close
|
|
39
|
+
|
|
40
|
+
after_open = open_fds.call
|
|
41
|
+
assert_equal (after_open - before_open), 0, "after closing the multi handle all connections should be closed"
|
|
42
|
+
|
|
43
|
+
Curl::Multi.autoclose = true
|
|
44
|
+
multi = Curl::Multi.new
|
|
45
|
+
did_complete = false
|
|
46
|
+
5.times do |n|
|
|
47
|
+
# NOTE: we use google here because connecting to our TEST_URL as a local host address appears to not register correctly with lsof as a socket... if anyone knows a better way would be great to not have an external dependency here in the test
|
|
48
|
+
easy = Curl::Easy.new("http://google.com/") do |curl|
|
|
49
|
+
curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
|
|
50
|
+
curl.on_complete {
|
|
51
|
+
did_complete = true
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
multi.add(easy)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
multi.perform
|
|
58
|
+
assert did_complete
|
|
59
|
+
after_open = open_fds.call
|
|
60
|
+
assert_equal (after_open - before_open), 0, "auto close the connections"
|
|
61
|
+
ensure
|
|
62
|
+
Curl::Multi.autoclose = false # restore default
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_connection_autoclose
|
|
66
|
+
assert !Curl::Multi.autoclose
|
|
67
|
+
Curl::Multi.autoclose = true
|
|
68
|
+
assert Curl::Multi.autoclose
|
|
69
|
+
ensure
|
|
70
|
+
Curl::Multi.autoclose = false # restore default
|
|
71
|
+
end
|
|
72
|
+
|
|
9
73
|
def test_new_multi_01
|
|
10
74
|
d1 = ""
|
|
11
75
|
c1 = Curl::Easy.new($TEST_URL) do |curl|
|
|
@@ -109,8 +173,12 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
109
173
|
|
|
110
174
|
assert(m.idle?, 'A new Curl::Multi handle should be idle')
|
|
111
175
|
|
|
176
|
+
assert_nil e.multi
|
|
177
|
+
|
|
112
178
|
m.add(e)
|
|
113
179
|
|
|
180
|
+
assert_not_nil e.multi
|
|
181
|
+
|
|
114
182
|
assert((not m.idle?), 'A Curl::Multi handle with a request should not be idle')
|
|
115
183
|
|
|
116
184
|
m.perform
|
|
@@ -121,7 +189,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
121
189
|
def test_requests
|
|
122
190
|
m = Curl::Multi.new
|
|
123
191
|
|
|
124
|
-
assert_equal(
|
|
192
|
+
assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests')
|
|
125
193
|
|
|
126
194
|
10.times do
|
|
127
195
|
m.add(Curl::Easy.new($TEST_URL))
|
|
@@ -131,7 +199,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
131
199
|
|
|
132
200
|
m.perform
|
|
133
201
|
|
|
134
|
-
assert_equal(
|
|
202
|
+
assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests after a perform')
|
|
135
203
|
end
|
|
136
204
|
|
|
137
205
|
def test_cancel
|
|
@@ -144,7 +212,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
144
212
|
|
|
145
213
|
m.cancel!
|
|
146
214
|
|
|
147
|
-
assert_equal(
|
|
215
|
+
assert_equal(0, m.requests.size, 'A new Curl::Multi handle should have no requests after being canceled')
|
|
148
216
|
end
|
|
149
217
|
|
|
150
218
|
def test_with_success
|
|
@@ -188,7 +256,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
188
256
|
c1.on_success do|c|
|
|
189
257
|
success_called1 = true
|
|
190
258
|
#puts "success 1 called: #{c.body_str.inspect}"
|
|
191
|
-
|
|
259
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
|
192
260
|
end
|
|
193
261
|
|
|
194
262
|
c1.on_failure do|c,rc|
|
|
@@ -327,7 +395,6 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
327
395
|
Curl::Multi.download(urls,{},{},downloads) do|curl,download_path|
|
|
328
396
|
assert_equal 200, curl.response_code
|
|
329
397
|
assert File.exist?(download_path)
|
|
330
|
-
store = file_info[File.basename(download_path)]
|
|
331
398
|
assert_equal file_info[File.basename(download_path)][:size], File.size(download_path), "incomplete download: #{download_path}"
|
|
332
399
|
end
|
|
333
400
|
ensure
|
|
@@ -342,7 +409,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
342
409
|
]
|
|
343
410
|
Curl::Multi.post(urls, {:follow_location => true, :multipart_form_post => true}, {:pipeline => true}) do|easy|
|
|
344
411
|
str = easy.body_str
|
|
345
|
-
assert_match
|
|
412
|
+
assert_match(/POST/, str)
|
|
346
413
|
fields = {}
|
|
347
414
|
str.gsub(/POST\n/,'').split('&').map{|sv| k, v = sv.split('='); fields[k] = v }
|
|
348
415
|
expected = urls.find{|s| s[:url] == easy.last_effective_url }
|
|
@@ -357,8 +424,8 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
357
424
|
{ :url => TestServlet.url, :method => :put, :put_data => "message",
|
|
358
425
|
:headers => {'Content-Type' => 'application/json' } }]
|
|
359
426
|
Curl::Multi.put(urls, {}, {:pipeline => true}) do|easy|
|
|
360
|
-
assert_match
|
|
361
|
-
assert_match
|
|
427
|
+
assert_match(/PUT/, easy.body_str)
|
|
428
|
+
assert_match(/message/, easy.body_str)
|
|
362
429
|
end
|
|
363
430
|
end
|
|
364
431
|
|
|
@@ -375,11 +442,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
375
442
|
assert_equal nil, code
|
|
376
443
|
case method
|
|
377
444
|
when :post
|
|
378
|
-
assert_match
|
|
445
|
+
assert_match(/POST/, easy.body_str)
|
|
379
446
|
when :get
|
|
380
|
-
assert_match
|
|
447
|
+
assert_match(/GET/, easy.body_str)
|
|
381
448
|
when :put
|
|
382
|
-
assert_match
|
|
449
|
+
assert_match(/PUT/, easy.body_str)
|
|
383
450
|
end
|
|
384
451
|
#puts "#{easy.body_str.inspect}, #{method.inspect}, #{code.inspect}"
|
|
385
452
|
end
|
|
@@ -395,11 +462,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
395
462
|
assert_equal nil, code
|
|
396
463
|
case method
|
|
397
464
|
when :post
|
|
398
|
-
assert_match
|
|
465
|
+
assert_match(/POST/, easy.body_str)
|
|
399
466
|
when :get
|
|
400
|
-
assert_match
|
|
467
|
+
assert_match(/GET/, easy.body_str)
|
|
401
468
|
when :put
|
|
402
|
-
assert_match
|
|
469
|
+
assert_match(/PUT/, easy.body_str)
|
|
403
470
|
end
|
|
404
471
|
end
|
|
405
472
|
end
|
|
@@ -466,7 +533,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
466
533
|
m.add(c)
|
|
467
534
|
m.add(c)
|
|
468
535
|
rescue => e
|
|
469
|
-
|
|
536
|
+
assert Curl::Err::MultiBadEasyHandle == e.class || Curl::Err::MultiAddedAlready == e.class
|
|
470
537
|
end
|
|
471
538
|
|
|
472
539
|
def test_multi_default_timeout
|
|
@@ -481,5 +548,4 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
481
548
|
def setup
|
|
482
549
|
server_setup
|
|
483
550
|
end
|
|
484
|
-
|
|
485
551
|
end
|