curb 0.9.2 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.markdown +45 -19
- data/Rakefile +26 -10
- data/ext/banned.h +32 -0
- data/ext/curb.c +45 -3
- data/ext/curb.h +12 -4
- data/ext/curb_easy.c +421 -61
- data/ext/curb_easy.h +4 -0
- data/ext/curb_errors.c +86 -0
- data/ext/curb_multi.c +131 -208
- data/ext/curb_multi.h +0 -1
- data/ext/extconf.rb +35 -0
- data/lib/curb.rb +1 -0
- data/lib/curl/easy.rb +10 -4
- data/lib/curl/multi.rb +52 -13
- data/lib/curl.rb +9 -9
- data/tests/bug_issue277.rb +32 -0
- data/tests/helper.rb +96 -12
- data/tests/tc_curl.rb +31 -1
- data/tests/tc_curl_download.rb +3 -3
- data/tests/tc_curl_easy.rb +155 -42
- data/tests/tc_curl_easy_resolve.rb +16 -0
- data/tests/tc_curl_maxfilesize.rb +12 -0
- data/tests/tc_curl_multi.rb +77 -15
- data/tests/tc_curl_postfield.rb +29 -29
- metadata +31 -25
data/tests/tc_curl_easy.rb
CHANGED
@@ -5,11 +5,81 @@ end
|
|
5
5
|
|
6
6
|
class TestCurbCurlEasy < Test::Unit::TestCase
|
7
7
|
def test_global_reset
|
8
|
-
|
8
|
+
Curl.get($TEST_URL)
|
9
9
|
# in a Timeout block you should reset the thread current handle
|
10
10
|
Curl.reset
|
11
11
|
end
|
12
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
|
+
|
13
83
|
def test_threads
|
14
84
|
t = []
|
15
85
|
5.times do
|
@@ -18,20 +88,17 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
18
88
|
c = Curl.get($TEST_URL)
|
19
89
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
20
90
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
|
21
|
-
assert_equal "", c.header_str
|
22
|
-
assert_equal "", c.head
|
23
91
|
end
|
24
92
|
end
|
25
93
|
end
|
26
94
|
|
27
|
-
t.each {|
|
95
|
+
t.each {|x| x.join }
|
28
96
|
end
|
29
97
|
|
30
98
|
def test_class_perform_01
|
31
99
|
assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
|
32
100
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
33
101
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
|
34
|
-
assert_equal "", c.header_str
|
35
102
|
end
|
36
103
|
|
37
104
|
def test_class_perform_02
|
@@ -39,12 +106,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
39
106
|
assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL) { |curl| curl.on_body { |d| data << d; d.length } }
|
40
107
|
|
41
108
|
assert_nil c.body_str
|
42
|
-
assert_equal "", c.header_str
|
43
109
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
|
44
110
|
end
|
45
111
|
|
46
112
|
def test_class_perform_03
|
47
|
-
assert_raise(Curl::Err::CouldntReadError) {
|
113
|
+
assert_raise(Curl::Err::CouldntReadError) { Curl::Easy.perform($TEST_URL + "nonexistent") }
|
48
114
|
end
|
49
115
|
|
50
116
|
def test_new_01
|
@@ -134,7 +200,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
134
200
|
c = Curl::Easy.new($TEST_URL)
|
135
201
|
assert_equal true, c.http_get
|
136
202
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
137
|
-
assert_equal "", c.header_str
|
138
203
|
end
|
139
204
|
|
140
205
|
def test_get_02
|
@@ -146,7 +211,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
146
211
|
assert_equal true, c.http_get
|
147
212
|
|
148
213
|
assert_nil c.body_str
|
149
|
-
assert_equal "", c.header_str
|
150
214
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
|
151
215
|
end
|
152
216
|
|
@@ -329,29 +393,69 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
329
393
|
c.max_redirects = nil
|
330
394
|
assert_nil c.max_redirects
|
331
395
|
end
|
332
|
-
|
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
|
+
|
333
417
|
def test_timeout_01
|
334
418
|
c = Curl::Easy.new($TEST_URL)
|
335
|
-
|
336
|
-
|
337
|
-
|
419
|
+
|
420
|
+
assert_equal 0, c.timeout
|
421
|
+
|
338
422
|
c.timeout = 3
|
339
423
|
assert_equal 3, c.timeout
|
340
|
-
|
341
|
-
c.timeout =
|
342
|
-
|
424
|
+
|
425
|
+
c.timeout = 0
|
426
|
+
assert_equal 0, c.timeout
|
343
427
|
end
|
344
428
|
|
345
429
|
def test_timeout_ms_01
|
346
430
|
c = Curl::Easy.new($TEST_URL)
|
347
431
|
|
348
|
-
|
432
|
+
assert_equal 0, c.timeout_ms
|
349
433
|
|
350
434
|
c.timeout_ms = 100
|
351
435
|
assert_equal 100, c.timeout_ms
|
352
436
|
|
353
437
|
c.timeout_ms = nil
|
354
|
-
|
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
|
355
459
|
end
|
356
460
|
|
357
461
|
def test_connect_timeout_01
|
@@ -595,6 +699,15 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
595
699
|
assert_equal "some.file", c.cookiejar
|
596
700
|
end
|
597
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
|
+
|
598
711
|
def test_on_success
|
599
712
|
curl = Curl::Easy.new($TEST_URL)
|
600
713
|
on_success_called = false
|
@@ -657,7 +770,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
657
770
|
retries = 0
|
658
771
|
begin
|
659
772
|
count = 0
|
660
|
-
|
773
|
+
Curl::Easy.send("http_#{method}", TestServlet.url) do|c|
|
661
774
|
count += 1
|
662
775
|
assert_equal Curl::Easy, c.class
|
663
776
|
end
|
@@ -679,8 +792,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
679
792
|
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
680
793
|
]
|
681
794
|
curl.http_post(fields)
|
682
|
-
assert_match
|
683
|
-
assert_match
|
795
|
+
assert_match(/HTTP POST file upload/, curl.body_str)
|
796
|
+
assert_match(/Content-Disposition: form-data/, curl.body_str)
|
684
797
|
end
|
685
798
|
|
686
799
|
def test_post_with_body_remote
|
@@ -706,8 +819,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
706
819
|
curl.multipart_form_post = true
|
707
820
|
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
708
821
|
curl.http_post(pf)
|
709
|
-
assert_match
|
710
|
-
assert_match
|
822
|
+
assert_match(/HTTP POST file upload/, curl.body_str)
|
823
|
+
assert_match(/Content-Disposition: form-data/, curl.body_str)
|
711
824
|
end
|
712
825
|
|
713
826
|
def test_delete_remote
|
@@ -729,7 +842,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
729
842
|
redirect = curl.header_str.match(/Location: (.*)/)
|
730
843
|
|
731
844
|
assert_equal '', curl.body_str
|
732
|
-
assert_match
|
845
|
+
assert_match('/nonexistent', redirect[1])
|
733
846
|
end
|
734
847
|
|
735
848
|
def test_head_accessor
|
@@ -740,7 +853,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
740
853
|
redirect = curl.header_str.match(/Location: (.*)/)
|
741
854
|
|
742
855
|
assert_equal '', curl.body_str
|
743
|
-
assert_match
|
856
|
+
assert_match('/nonexistent', redirect[1])
|
744
857
|
curl.head = false
|
745
858
|
curl.perform
|
746
859
|
assert_equal 'GET', curl.body_str
|
@@ -750,11 +863,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
750
863
|
curl = Curl::Easy.new(TestServlet.url)
|
751
864
|
curl.headers['Content-Type'] = 'application/json'
|
752
865
|
assert curl.http_put("message")
|
753
|
-
assert_match
|
754
|
-
assert_match
|
755
|
-
assert_match
|
756
|
-
assert_match
|
757
|
-
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)
|
758
871
|
end
|
759
872
|
|
760
873
|
def test_put_data
|
@@ -763,8 +876,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
763
876
|
|
764
877
|
curl.perform
|
765
878
|
|
766
|
-
assert_match
|
767
|
-
assert_match
|
879
|
+
assert_match(/^PUT/, curl.body_str)
|
880
|
+
assert_match(/message$/, curl.body_str)
|
768
881
|
end
|
769
882
|
|
770
883
|
# https://github.com/taf2/curb/issues/101
|
@@ -774,8 +887,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
774
887
|
|
775
888
|
curl.perform
|
776
889
|
|
777
|
-
assert_match
|
778
|
-
assert_match
|
890
|
+
assert_match(/^PUT/, curl.body_str)
|
891
|
+
assert_match("a\0b", curl.body_str)
|
779
892
|
end
|
780
893
|
|
781
894
|
def test_put_nil_data_no_crash
|
@@ -790,7 +903,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
790
903
|
File.open(__FILE__,'rb') do|f|
|
791
904
|
assert curl.http_put(f)
|
792
905
|
end
|
793
|
-
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
906
|
+
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
|
794
907
|
end
|
795
908
|
|
796
909
|
def test_put_class_method
|
@@ -800,7 +913,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
800
913
|
assert_equal Curl::Easy, c.class
|
801
914
|
end
|
802
915
|
assert_equal 1, count
|
803
|
-
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
916
|
+
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
|
804
917
|
end
|
805
918
|
|
806
919
|
# Generate a self-signed cert with
|
@@ -809,7 +922,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
809
922
|
def test_cert
|
810
923
|
curl = Curl::Easy.new(TestServlet.url)
|
811
924
|
curl.cert= File.join(File.dirname(__FILE__),"cert.pem")
|
812
|
-
assert_match
|
925
|
+
assert_match(/cert.pem$/,curl.cert)
|
813
926
|
end
|
814
927
|
|
815
928
|
def test_cert_with_password
|
@@ -817,7 +930,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
817
930
|
path = File.join(File.dirname(__FILE__),"cert.pem")
|
818
931
|
curl.certpassword = 'password'
|
819
932
|
curl.cert = path
|
820
|
-
assert_match
|
933
|
+
assert_match(/cert.pem$/,curl.cert)
|
821
934
|
end
|
822
935
|
|
823
936
|
def test_cert_type
|
@@ -838,7 +951,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
838
951
|
def test_ca_cert
|
839
952
|
curl = Curl::Easy.new(TestServlet.url)
|
840
953
|
curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")
|
841
|
-
assert_match
|
954
|
+
assert_match(/cacert.pem$/, curl.cacert)
|
842
955
|
end
|
843
956
|
|
844
957
|
def test_user_agent
|
@@ -896,7 +1009,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
896
1009
|
easy.http_post(pf)
|
897
1010
|
|
898
1011
|
assert_not_equal(0,easy.body_str.size)
|
899
|
-
assert_equal(easy.body_str,File.read(readme))
|
1012
|
+
assert_equal(easy.body_str.tr("\r", ''), File.read(readme))
|
900
1013
|
end
|
901
1014
|
|
902
1015
|
|
@@ -992,8 +1105,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
992
1105
|
curl.headers['Accept'] = '*/*'
|
993
1106
|
curl.headers['Authorization'] = 'Foo Bar Biz Baz'
|
994
1107
|
curl.http_put(rd)
|
995
|
-
assert_match
|
996
|
-
assert_match
|
1108
|
+
assert_match(/^PUT/, curl.body_str)
|
1109
|
+
assert_match(/hello$/, curl.body_str)
|
997
1110
|
curl.header_str
|
998
1111
|
curl.body_str
|
999
1112
|
end
|
@@ -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|
|
@@ -125,7 +189,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
125
189
|
def test_requests
|
126
190
|
m = Curl::Multi.new
|
127
191
|
|
128
|
-
assert_equal(
|
192
|
+
assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests')
|
129
193
|
|
130
194
|
10.times do
|
131
195
|
m.add(Curl::Easy.new($TEST_URL))
|
@@ -135,7 +199,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
135
199
|
|
136
200
|
m.perform
|
137
201
|
|
138
|
-
assert_equal(
|
202
|
+
assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests after a perform')
|
139
203
|
end
|
140
204
|
|
141
205
|
def test_cancel
|
@@ -148,7 +212,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
148
212
|
|
149
213
|
m.cancel!
|
150
214
|
|
151
|
-
assert_equal(
|
215
|
+
assert_equal(0, m.requests.size, 'A new Curl::Multi handle should have no requests after being canceled')
|
152
216
|
end
|
153
217
|
|
154
218
|
def test_with_success
|
@@ -192,7 +256,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
192
256
|
c1.on_success do|c|
|
193
257
|
success_called1 = true
|
194
258
|
#puts "success 1 called: #{c.body_str.inspect}"
|
195
|
-
|
259
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
196
260
|
end
|
197
261
|
|
198
262
|
c1.on_failure do|c,rc|
|
@@ -331,7 +395,6 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
331
395
|
Curl::Multi.download(urls,{},{},downloads) do|curl,download_path|
|
332
396
|
assert_equal 200, curl.response_code
|
333
397
|
assert File.exist?(download_path)
|
334
|
-
store = file_info[File.basename(download_path)]
|
335
398
|
assert_equal file_info[File.basename(download_path)][:size], File.size(download_path), "incomplete download: #{download_path}"
|
336
399
|
end
|
337
400
|
ensure
|
@@ -346,7 +409,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
346
409
|
]
|
347
410
|
Curl::Multi.post(urls, {:follow_location => true, :multipart_form_post => true}, {:pipeline => true}) do|easy|
|
348
411
|
str = easy.body_str
|
349
|
-
assert_match
|
412
|
+
assert_match(/POST/, str)
|
350
413
|
fields = {}
|
351
414
|
str.gsub(/POST\n/,'').split('&').map{|sv| k, v = sv.split('='); fields[k] = v }
|
352
415
|
expected = urls.find{|s| s[:url] == easy.last_effective_url }
|
@@ -361,8 +424,8 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
361
424
|
{ :url => TestServlet.url, :method => :put, :put_data => "message",
|
362
425
|
:headers => {'Content-Type' => 'application/json' } }]
|
363
426
|
Curl::Multi.put(urls, {}, {:pipeline => true}) do|easy|
|
364
|
-
assert_match
|
365
|
-
assert_match
|
427
|
+
assert_match(/PUT/, easy.body_str)
|
428
|
+
assert_match(/message/, easy.body_str)
|
366
429
|
end
|
367
430
|
end
|
368
431
|
|
@@ -379,11 +442,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
379
442
|
assert_equal nil, code
|
380
443
|
case method
|
381
444
|
when :post
|
382
|
-
assert_match
|
445
|
+
assert_match(/POST/, easy.body_str)
|
383
446
|
when :get
|
384
|
-
assert_match
|
447
|
+
assert_match(/GET/, easy.body_str)
|
385
448
|
when :put
|
386
|
-
assert_match
|
449
|
+
assert_match(/PUT/, easy.body_str)
|
387
450
|
end
|
388
451
|
#puts "#{easy.body_str.inspect}, #{method.inspect}, #{code.inspect}"
|
389
452
|
end
|
@@ -399,11 +462,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
399
462
|
assert_equal nil, code
|
400
463
|
case method
|
401
464
|
when :post
|
402
|
-
assert_match
|
465
|
+
assert_match(/POST/, easy.body_str)
|
403
466
|
when :get
|
404
|
-
assert_match
|
467
|
+
assert_match(/GET/, easy.body_str)
|
405
468
|
when :put
|
406
|
-
assert_match
|
469
|
+
assert_match(/PUT/, easy.body_str)
|
407
470
|
end
|
408
471
|
end
|
409
472
|
end
|
@@ -485,5 +548,4 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
485
548
|
def setup
|
486
549
|
server_setup
|
487
550
|
end
|
488
|
-
|
489
551
|
end
|