curb 0.6.5.0 → 0.8.4
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 +42 -5
- data/Rakefile +27 -4
- data/ext/curb.c +638 -0
- data/ext/curb.h +6 -4
- data/ext/curb_easy.c +954 -573
- data/ext/curb_easy.h +31 -2
- data/ext/curb_errors.c +16 -2
- data/ext/curb_errors.h +1 -0
- data/ext/curb_macros.h +4 -0
- data/ext/curb_multi.c +229 -67
- data/ext/curb_postfield.c +61 -49
- data/ext/curb_upload.c +2 -2
- data/ext/extconf.rb +232 -4
- data/lib/curb.rb +1 -186
- data/lib/curl/easy.rb +468 -0
- data/lib/curl/multi.rb +248 -0
- data/lib/curl.rb +61 -1
- data/tests/bug_crash_on_debug.rb +39 -0
- data/tests/bug_crash_on_progress.rb +33 -0
- data/tests/bug_curb_easy_blocks_ruby_threads.rb +2 -2
- data/tests/bug_issue102.rb +17 -0
- data/tests/bug_multi_segfault.rb +6 -2
- data/tests/bug_postfields_crash2.rb +57 -0
- data/tests/bug_require_last_or_segfault.rb +1 -1
- data/tests/bugtests.rb +9 -0
- data/tests/helper.rb +40 -10
- data/tests/signals.rb +33 -0
- data/tests/tc_curl.rb +39 -0
- data/tests/tc_curl_download.rb +44 -1
- data/tests/tc_curl_easy.rb +355 -22
- data/tests/tc_curl_easy_setopt.rb +31 -0
- data/tests/tc_curl_multi.rb +57 -5
- data/tests/tc_curl_postfield.rb +3 -1
- data/tests/timeout.rb +100 -0
- data/tests/timeout_server.rb +33 -0
- metadata +87 -48
data/tests/tc_curl_easy.rb
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
2
|
+
class FooNoToS
|
|
3
|
+
undef to_s
|
|
4
|
+
end
|
|
2
5
|
|
|
3
6
|
class TestCurbCurlEasy < Test::Unit::TestCase
|
|
7
|
+
def test_threads
|
|
8
|
+
t = []
|
|
9
|
+
5.times do
|
|
10
|
+
t << Thread.new do
|
|
11
|
+
5.times do
|
|
12
|
+
c = Curl.get($TEST_URL)
|
|
13
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
|
14
|
+
assert_equal "", c.header_str
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
t.each {|t| t.join }
|
|
20
|
+
end
|
|
21
|
+
|
|
4
22
|
def test_class_perform_01
|
|
5
23
|
assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
|
|
6
24
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
|
@@ -57,8 +75,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
57
75
|
assert_equal nil, c.on_body
|
|
58
76
|
end
|
|
59
77
|
|
|
60
|
-
class Foo < Curl::Easy
|
|
61
|
-
end
|
|
78
|
+
class Foo < Curl::Easy ; end
|
|
62
79
|
def test_new_05
|
|
63
80
|
# can use Curl::Easy as a base class
|
|
64
81
|
c = Foo.new
|
|
@@ -222,7 +239,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
222
239
|
|
|
223
240
|
assert_equal $TEST_URL, c.url
|
|
224
241
|
assert_equal "http://some.proxy", c.proxy_url
|
|
225
|
-
|
|
242
|
+
|
|
226
243
|
c.proxy_url = nil
|
|
227
244
|
assert_equal $TEST_URL, c.url
|
|
228
245
|
assert_nil c.proxy_url
|
|
@@ -352,6 +369,30 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
352
369
|
assert_equal 30, c.dns_cache_timeout
|
|
353
370
|
end
|
|
354
371
|
|
|
372
|
+
def test_low_speed_limit_01
|
|
373
|
+
c = Curl::Easy.new($TEST_URL)
|
|
374
|
+
|
|
375
|
+
assert_nil c.low_speed_limit
|
|
376
|
+
|
|
377
|
+
c.low_speed_limit = 3
|
|
378
|
+
assert_equal 3, c.low_speed_limit
|
|
379
|
+
|
|
380
|
+
c.low_speed_limit = nil
|
|
381
|
+
assert_nil c.low_speed_limit
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def test_low_speed_time_01
|
|
385
|
+
c = Curl::Easy.new($TEST_URL)
|
|
386
|
+
|
|
387
|
+
assert_nil c.low_speed_time
|
|
388
|
+
|
|
389
|
+
c.low_speed_time = 3
|
|
390
|
+
assert_equal 3, c.low_speed_time
|
|
391
|
+
|
|
392
|
+
c.low_speed_time = nil
|
|
393
|
+
assert_nil c.low_speed_time
|
|
394
|
+
end
|
|
395
|
+
|
|
355
396
|
def test_on_body
|
|
356
397
|
blk = lambda { |i| i.length }
|
|
357
398
|
|
|
@@ -361,6 +402,25 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
361
402
|
assert_equal blk, c.on_body # sets handler nil, returns old handler
|
|
362
403
|
assert_equal nil, c.on_body
|
|
363
404
|
end
|
|
405
|
+
|
|
406
|
+
def test_inspect_with_no_url
|
|
407
|
+
c = Curl::Easy.new
|
|
408
|
+
assert_equal '#<Curl::Easy>', c.inspect
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
def test_inspect_with_short_url
|
|
412
|
+
c = Curl::Easy.new('http://www.google.com/')
|
|
413
|
+
assert_equal "#<Curl::Easy http://www.google.com/>", c.inspect
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
def test_inspect_truncates_to_64_chars
|
|
417
|
+
base_url = 'http://www.google.com/'
|
|
418
|
+
truncated_url = base_url + 'x' * (64 - '#<Curl::Easy >'.size - base_url.size)
|
|
419
|
+
long_url = truncated_url + 'yyyy'
|
|
420
|
+
c = Curl::Easy.new(long_url)
|
|
421
|
+
assert_equal 64, c.inspect.size
|
|
422
|
+
assert_equal "#<Curl::Easy #{truncated_url}>", c.inspect
|
|
423
|
+
end
|
|
364
424
|
|
|
365
425
|
def test_on_header
|
|
366
426
|
blk = lambda { |i| i.length }
|
|
@@ -416,7 +476,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
416
476
|
def test_ssl_verify_host
|
|
417
477
|
c = Curl::Easy.new
|
|
418
478
|
assert c.ssl_verify_host?
|
|
419
|
-
|
|
479
|
+
c.ssl_verify_host = 0
|
|
480
|
+
c.ssl_verify_host = false
|
|
420
481
|
assert !c.ssl_verify_host?
|
|
421
482
|
end
|
|
422
483
|
|
|
@@ -455,6 +516,24 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
455
516
|
assert c.multipart_form_post?
|
|
456
517
|
end
|
|
457
518
|
|
|
519
|
+
def test_ignore_content_length
|
|
520
|
+
c = Curl::Easy.new
|
|
521
|
+
assert !c.ignore_content_length?
|
|
522
|
+
assert c.ignore_content_length = true
|
|
523
|
+
assert c.ignore_content_length?
|
|
524
|
+
end
|
|
525
|
+
|
|
526
|
+
def test_resolve_mode
|
|
527
|
+
c = Curl::Easy.new
|
|
528
|
+
assert_equal :auto, c.resolve_mode
|
|
529
|
+
c.resolve_mode = :ipv4
|
|
530
|
+
assert_equal :ipv4, c.resolve_mode
|
|
531
|
+
c.resolve_mode = :ipv6
|
|
532
|
+
assert_equal :ipv6, c.resolve_mode
|
|
533
|
+
|
|
534
|
+
assert_raises(ArgumentError) { c.resolve_mode = :bad }
|
|
535
|
+
end
|
|
536
|
+
|
|
458
537
|
def test_enable_cookies
|
|
459
538
|
c = Curl::Easy.new
|
|
460
539
|
assert !c.enable_cookies?
|
|
@@ -497,13 +576,34 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
497
576
|
end
|
|
498
577
|
|
|
499
578
|
def test_on_success_with_on_failure
|
|
500
|
-
curl = Curl::Easy.new(
|
|
579
|
+
curl = Curl::Easy.new(TestServlet.url + '/error')
|
|
501
580
|
on_failure_called = false
|
|
502
581
|
curl.on_success {|c| } # make sure we get the failure call even though this handler is defined
|
|
503
582
|
curl.on_failure {|c,code| on_failure_called = true }
|
|
504
583
|
curl.perform
|
|
584
|
+
assert_equal 500, curl.response_code
|
|
505
585
|
assert on_failure_called, "Failure handler not called"
|
|
506
586
|
end
|
|
587
|
+
|
|
588
|
+
def test_on_success_with_on_missing
|
|
589
|
+
curl = Curl::Easy.new(TestServlet.url + '/not_here')
|
|
590
|
+
on_missing_called = false
|
|
591
|
+
curl.on_success {|c| } # make sure we get the missing call even though this handler is defined
|
|
592
|
+
curl.on_missing {|c,code| on_missing_called = true }
|
|
593
|
+
curl.perform
|
|
594
|
+
assert_equal 404, curl.response_code
|
|
595
|
+
assert on_missing_called, "Missing handler not called"
|
|
596
|
+
end
|
|
597
|
+
|
|
598
|
+
def test_on_success_with_on_redirect
|
|
599
|
+
curl = Curl::Easy.new(TestServlet.url + '/redirect')
|
|
600
|
+
on_redirect_called = false
|
|
601
|
+
curl.on_success {|c| } # make sure we get the redirect call even though this handler is defined
|
|
602
|
+
curl.on_redirect {|c,code| on_redirect_called = true }
|
|
603
|
+
curl.perform
|
|
604
|
+
assert_equal 302, curl.response_code
|
|
605
|
+
assert on_redirect_called, "Redirect handler not called"
|
|
606
|
+
end
|
|
507
607
|
|
|
508
608
|
def test_get_remote
|
|
509
609
|
curl = Curl::Easy.new(TestServlet.url)
|
|
@@ -513,22 +613,42 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
513
613
|
|
|
514
614
|
def test_post_remote
|
|
515
615
|
curl = Curl::Easy.new(TestServlet.url)
|
|
516
|
-
curl.http_post
|
|
517
|
-
assert_equal "POST\
|
|
616
|
+
curl.http_post([Curl::PostField.content('document_id', 5)])
|
|
617
|
+
assert_equal "POST\ndocument_id=5", curl.unescape(curl.body_str)
|
|
518
618
|
end
|
|
519
619
|
|
|
520
620
|
def test_post_remote_is_easy_handle
|
|
521
621
|
# see: http://pastie.org/560852 and
|
|
522
622
|
# http://groups.google.com/group/curb---ruby-libcurl-bindings/browse_thread/thread/216bb2d9b037f347?hl=en
|
|
523
|
-
[:post, :get
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
count
|
|
527
|
-
|
|
623
|
+
[:post, :get, :head, :delete].each do |method|
|
|
624
|
+
retries = 0
|
|
625
|
+
begin
|
|
626
|
+
count = 0
|
|
627
|
+
curl = Curl::Easy.send("http_#{method}", TestServlet.url) do|c|
|
|
628
|
+
count += 1
|
|
629
|
+
assert_equal Curl::Easy, c.class
|
|
630
|
+
end
|
|
631
|
+
assert_equal 1, count, "For request method: #{method.to_s.upcase}"
|
|
632
|
+
rescue Curl::Err::HostResolutionError => e # travis-ci.org fails to resolve... try again?
|
|
633
|
+
retries+=1
|
|
634
|
+
retry if retries < 3
|
|
635
|
+
raise e
|
|
528
636
|
end
|
|
529
|
-
assert_equal 1, count, "For request method: #{method.to_s.upcase}"
|
|
530
637
|
end
|
|
531
638
|
end
|
|
639
|
+
|
|
640
|
+
# see: https://github.com/rvanlieshout/curb/commit/8bcdefddc0162484681ebd1a92d52a642666a445
|
|
641
|
+
def test_post_multipart_array_remote
|
|
642
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
643
|
+
curl.multipart_form_post = true
|
|
644
|
+
fields = [
|
|
645
|
+
Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README'))),
|
|
646
|
+
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
|
647
|
+
]
|
|
648
|
+
curl.http_post(fields)
|
|
649
|
+
assert_match /HTTP POST file upload/, curl.body_str
|
|
650
|
+
assert_match /Content-Disposition: form-data/, curl.body_str
|
|
651
|
+
end
|
|
532
652
|
|
|
533
653
|
def test_post_with_body_remote
|
|
534
654
|
curl = Curl::Easy.new(TestServlet.url)
|
|
@@ -548,12 +668,27 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
548
668
|
assert_equal 'foo=bar&encoded%20string=val', curl.post_body
|
|
549
669
|
end
|
|
550
670
|
|
|
671
|
+
def test_post_multipart_file_remote
|
|
672
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
673
|
+
curl.multipart_form_post = true
|
|
674
|
+
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
|
675
|
+
curl.http_post(pf)
|
|
676
|
+
assert_match /HTTP POST file upload/, curl.body_str
|
|
677
|
+
assert_match /Content-Disposition: form-data/, curl.body_str
|
|
678
|
+
end
|
|
679
|
+
|
|
551
680
|
def test_delete_remote
|
|
552
681
|
curl = Curl::Easy.new(TestServlet.url)
|
|
553
682
|
curl.http_delete
|
|
554
683
|
assert_equal 'DELETE', curl.body_str
|
|
555
684
|
end
|
|
556
685
|
|
|
686
|
+
def test_arbitrary_http_verb
|
|
687
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
688
|
+
curl.http('PURGE')
|
|
689
|
+
assert_equal 'PURGE', curl.body_str
|
|
690
|
+
end
|
|
691
|
+
|
|
557
692
|
def test_head_remote
|
|
558
693
|
curl = Curl::Easy.new(TestServlet.url)
|
|
559
694
|
curl.http_head
|
|
@@ -597,9 +732,27 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
597
732
|
assert_match /message$/, curl.body_str
|
|
598
733
|
end
|
|
599
734
|
|
|
735
|
+
# https://github.com/taf2/curb/issues/101
|
|
736
|
+
def test_put_data_null_bytes
|
|
737
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
738
|
+
curl.put_data = "a\0b"
|
|
739
|
+
|
|
740
|
+
curl.perform
|
|
741
|
+
|
|
742
|
+
assert_match /^PUT/, curl.body_str
|
|
743
|
+
assert_match "a\0b", curl.body_str
|
|
744
|
+
end
|
|
745
|
+
|
|
746
|
+
def test_put_nil_data_no_crash
|
|
747
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
748
|
+
curl.put_data = nil
|
|
749
|
+
|
|
750
|
+
curl.perform
|
|
751
|
+
end
|
|
752
|
+
|
|
600
753
|
def test_put_remote_file
|
|
601
754
|
curl = Curl::Easy.new(TestServlet.url)
|
|
602
|
-
File.open(__FILE__,'
|
|
755
|
+
File.open(__FILE__,'rb') do|f|
|
|
603
756
|
assert curl.http_put(f)
|
|
604
757
|
end
|
|
605
758
|
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
|
@@ -621,24 +774,28 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
621
774
|
def test_cert
|
|
622
775
|
curl = Curl::Easy.new(TestServlet.url)
|
|
623
776
|
curl.cert= File.join(File.dirname(__FILE__),"cert.pem")
|
|
624
|
-
|
|
777
|
+
assert_match /cert.pem$/,curl.cert
|
|
625
778
|
end
|
|
626
779
|
|
|
627
780
|
def test_cert_with_password
|
|
628
781
|
curl = Curl::Easy.new(TestServlet.url)
|
|
629
|
-
|
|
630
|
-
|
|
782
|
+
path = File.join(File.dirname(__FILE__),"cert.pem")
|
|
783
|
+
curl.certpassword = 'password'
|
|
784
|
+
curl.cert = path
|
|
785
|
+
assert_match /cert.pem$/,curl.cert
|
|
631
786
|
end
|
|
632
787
|
|
|
633
788
|
def test_cert_type
|
|
634
789
|
curl = Curl::Easy.new(TestServlet.url)
|
|
635
790
|
curl.certtype= "DER"
|
|
636
|
-
|
|
791
|
+
assert_equal "DER", curl.certtype
|
|
637
792
|
end
|
|
638
793
|
|
|
639
794
|
def test_default_certtype
|
|
640
795
|
curl = Curl::Easy.new(TestServlet.url)
|
|
641
|
-
|
|
796
|
+
assert_nil curl.certtype
|
|
797
|
+
curl.certtype = "PEM"
|
|
798
|
+
assert_equal "PEM", curl.certtype
|
|
642
799
|
end
|
|
643
800
|
|
|
644
801
|
# Generate a CA cert with instructions at
|
|
@@ -646,13 +803,13 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
646
803
|
def test_ca_cert
|
|
647
804
|
curl = Curl::Easy.new(TestServlet.url)
|
|
648
805
|
curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")
|
|
649
|
-
|
|
806
|
+
assert_match /cacert.pem$/, curl.cacert
|
|
650
807
|
end
|
|
651
808
|
|
|
652
809
|
def test_user_agent
|
|
653
810
|
curl = Curl::Easy.new(TestServlet.url)
|
|
654
811
|
curl.useragent= "Curb-Easy/Ruby"
|
|
655
|
-
|
|
812
|
+
assert_equal "Curb-Easy/Ruby",curl.useragent
|
|
656
813
|
end
|
|
657
814
|
|
|
658
815
|
def test_username_password
|
|
@@ -669,7 +826,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
669
826
|
#curl.verbose = true
|
|
670
827
|
curl.perform
|
|
671
828
|
assert_equal 'Basic Zm9vOmJhcg==', $auth_header
|
|
672
|
-
|
|
829
|
+
$auth_header = nil
|
|
673
830
|
# curl checks the auth type supported by the server, so we have to create a
|
|
674
831
|
# new easy handle if we're going to change the auth type...
|
|
675
832
|
|
|
@@ -684,6 +841,182 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
|
684
841
|
assert_equal 'NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=', $auth_header
|
|
685
842
|
end
|
|
686
843
|
|
|
844
|
+
def test_primary_ip
|
|
845
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
846
|
+
if curl.respond_to?(:primary_ip)
|
|
847
|
+
curl.perform
|
|
848
|
+
assert_equal '127.0.0.1', curl.primary_ip
|
|
849
|
+
end
|
|
850
|
+
end
|
|
851
|
+
|
|
852
|
+
def test_post_streaming
|
|
853
|
+
readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README'))
|
|
854
|
+
|
|
855
|
+
pf = Curl::PostField.file("filename", readme)
|
|
856
|
+
|
|
857
|
+
easy = Curl::Easy.new
|
|
858
|
+
|
|
859
|
+
easy.url = TestServlet.url
|
|
860
|
+
easy.multipart_form_post = true
|
|
861
|
+
easy.http_post(pf)
|
|
862
|
+
|
|
863
|
+
assert_not_equal(0,easy.body_str.size)
|
|
864
|
+
assert_equal(easy.body_str,File.read(readme))
|
|
865
|
+
end
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
def test_easy_close
|
|
869
|
+
easy = Curl::Easy.new
|
|
870
|
+
easy.close
|
|
871
|
+
easy.url = TestServlet.url
|
|
872
|
+
easy.http_get
|
|
873
|
+
end
|
|
874
|
+
|
|
875
|
+
def test_easy_reset
|
|
876
|
+
easy = Curl::Easy.new
|
|
877
|
+
easy.url = TestServlet.url + "?query=foo"
|
|
878
|
+
easy.http_get
|
|
879
|
+
settings = easy.reset
|
|
880
|
+
assert settings.key?(:url)
|
|
881
|
+
assert settings.key?(:body_data)
|
|
882
|
+
assert settings.key?(:header_data)
|
|
883
|
+
easy.url = TestServlet.url
|
|
884
|
+
easy.http_get
|
|
885
|
+
end
|
|
886
|
+
|
|
887
|
+
def test_easy_use_http_versions
|
|
888
|
+
easy = Curl::Easy.new
|
|
889
|
+
easy.url = TestServlet.url + "?query=foo"
|
|
890
|
+
#puts "http none: #{Curl::HTTP_NONE.inspect}"
|
|
891
|
+
#puts "http1.0: #{Curl::HTTP_1_0.inspect}"
|
|
892
|
+
#puts "http1.1: #{Curl::HTTP_1_1.inspect}"
|
|
893
|
+
easy.version = Curl::HTTP_1_1
|
|
894
|
+
#easy.verbose = true
|
|
895
|
+
easy.http_get
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
def test_easy_http_verbs
|
|
899
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
900
|
+
curl.http_delete
|
|
901
|
+
assert_equal 'DELETE', curl.body_str
|
|
902
|
+
curl.http_get
|
|
903
|
+
assert_equal 'GET', curl.body_str
|
|
904
|
+
curl.http_post
|
|
905
|
+
assert_equal "POST\n", curl.body_str
|
|
906
|
+
curl.http('PURGE')
|
|
907
|
+
assert_equal 'PURGE', curl.body_str
|
|
908
|
+
curl.http_put('hello')
|
|
909
|
+
assert_equal "PUT\nhello", curl.body_str
|
|
910
|
+
curl.http('COPY')
|
|
911
|
+
assert_equal 'COPY', curl.body_str
|
|
912
|
+
end
|
|
913
|
+
|
|
914
|
+
def test_easy_http_verbs_must_respond_to_str
|
|
915
|
+
# issue http://github.com/taf2/curb/issues#issue/45
|
|
916
|
+
assert_nothing_raised do
|
|
917
|
+
c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(:get)
|
|
918
|
+
end
|
|
919
|
+
|
|
920
|
+
assert_raise RuntimeError do
|
|
921
|
+
c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(FooNoToS.new)
|
|
922
|
+
end
|
|
923
|
+
|
|
924
|
+
end
|
|
925
|
+
|
|
926
|
+
# http://github.com/taf2/curb/issues/#issue/33
|
|
927
|
+
def test_easy_http_verbs_with_errors
|
|
928
|
+
curl = Curl::Easy.new("http://127.0.0.1:9012/") # test will fail if http server on port 9012
|
|
929
|
+
assert_raise Curl::Err::ConnectionFailedError do
|
|
930
|
+
curl.http_delete
|
|
931
|
+
end
|
|
932
|
+
curl.url = TestServlet.url
|
|
933
|
+
curl.http_get
|
|
934
|
+
assert_equal 'GET', curl.body_str
|
|
935
|
+
end
|
|
936
|
+
|
|
937
|
+
def test_easy_can_put_with_content_length
|
|
938
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
939
|
+
rd, wr = IO.pipe
|
|
940
|
+
buf = (("hello")* (1000 / 5))
|
|
941
|
+
|
|
942
|
+
producer = Thread.new do
|
|
943
|
+
5.times do
|
|
944
|
+
wr << buf
|
|
945
|
+
sleep 0.1 # act as a slow producer
|
|
946
|
+
end
|
|
947
|
+
end
|
|
948
|
+
|
|
949
|
+
consumer = Thread.new do
|
|
950
|
+
|
|
951
|
+
#curl.verbose = true
|
|
952
|
+
curl.headers['Content-Length'] = buf.size * 5
|
|
953
|
+
curl.headers['User-Agent'] = "Something else"
|
|
954
|
+
curl.headers['Content-Type'] = "text/javascript"
|
|
955
|
+
curl.headers['Date'] = Time.now.httpdate
|
|
956
|
+
curl.headers['Host'] = 's3.amazonaws.com'
|
|
957
|
+
curl.headers['Accept'] = '*/*'
|
|
958
|
+
curl.headers['Authorization'] = 'Foo Bar Biz Baz'
|
|
959
|
+
curl.http_put(rd)
|
|
960
|
+
assert_match /^PUT/, curl.body_str
|
|
961
|
+
assert_match /hello$/, curl.body_str
|
|
962
|
+
curl.header_str
|
|
963
|
+
curl.body_str
|
|
964
|
+
end
|
|
965
|
+
|
|
966
|
+
producer.join
|
|
967
|
+
wr.close
|
|
968
|
+
consumer.join
|
|
969
|
+
|
|
970
|
+
end
|
|
971
|
+
|
|
972
|
+
def test_get_set_multi_on_easy
|
|
973
|
+
easy = Curl::Easy.new
|
|
974
|
+
assert_nil easy.multi
|
|
975
|
+
multi = Curl::Multi.new
|
|
976
|
+
easy.multi = multi
|
|
977
|
+
assert_not_nil easy.multi
|
|
978
|
+
assert_equal multi, easy.multi
|
|
979
|
+
end
|
|
980
|
+
|
|
981
|
+
def test_raise_on_progress
|
|
982
|
+
c = Curl::Easy.new($TEST_URL)
|
|
983
|
+
c.on_progress {|w,x,y,z| raise "error" }
|
|
984
|
+
c.perform
|
|
985
|
+
rescue => e
|
|
986
|
+
assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
|
|
987
|
+
c.close
|
|
988
|
+
end
|
|
989
|
+
|
|
990
|
+
def test_raise_on_success
|
|
991
|
+
c = Curl::Easy.new($TEST_URL)
|
|
992
|
+
c.on_success {|x| raise "error" }
|
|
993
|
+
c.perform
|
|
994
|
+
rescue => e
|
|
995
|
+
assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
|
|
996
|
+
c.close
|
|
997
|
+
end
|
|
998
|
+
|
|
999
|
+
def test_raise_on_debug
|
|
1000
|
+
c = Curl::Easy.new($TEST_URL)
|
|
1001
|
+
c.on_debug { raise "error" }
|
|
1002
|
+
c.perform
|
|
1003
|
+
assert true, "raise in on debug has no effect"
|
|
1004
|
+
end
|
|
1005
|
+
|
|
1006
|
+
def test_status_codes
|
|
1007
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
1008
|
+
curl.perform
|
|
1009
|
+
assert_equal '200 OK', curl.status
|
|
1010
|
+
end
|
|
1011
|
+
|
|
1012
|
+
def test_close_in_on_callbacks
|
|
1013
|
+
curl = Curl::Easy.new(TestServlet.url)
|
|
1014
|
+
curl.on_body {|d| curl.close; d.size }
|
|
1015
|
+
assert_raises RuntimeError do
|
|
1016
|
+
curl.perform
|
|
1017
|
+
end
|
|
1018
|
+
end
|
|
1019
|
+
|
|
687
1020
|
include TestServerMethods
|
|
688
1021
|
|
|
689
1022
|
def setup
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
2
|
+
|
|
3
|
+
class TestCurbCurlEasySetOpt < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@easy = Curl::Easy.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_opt_verbose
|
|
9
|
+
@easy.set :verbose, true
|
|
10
|
+
assert @easy.verbose?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_opt_header
|
|
14
|
+
@easy.set :header, true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_opt_noprogress
|
|
18
|
+
@easy.set :noprogress, true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_opt_nosignal
|
|
22
|
+
@easy.set :nosignal, true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_opt_url
|
|
26
|
+
url = "http://google.com/"
|
|
27
|
+
@easy.set :url, url
|
|
28
|
+
assert_equal url, @easy.url
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
data/tests/tc_curl_multi.rb
CHANGED
|
@@ -70,7 +70,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
70
70
|
|
|
71
71
|
m.perform
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
assert_equal n, responses.size
|
|
74
74
|
n.times do|i|
|
|
75
75
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, responses[i], "response #{i}")
|
|
76
76
|
end
|
|
@@ -93,7 +93,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
93
93
|
end
|
|
94
94
|
m.perform
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
assert_equal n, responses.size
|
|
97
97
|
n.times do|i|
|
|
98
98
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, responses[i], "response #{i}")
|
|
99
99
|
end
|
|
@@ -170,7 +170,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
170
170
|
|
|
171
171
|
m.perform do
|
|
172
172
|
# idle
|
|
173
|
-
puts "idling..."
|
|
173
|
+
#puts "idling..."
|
|
174
174
|
end
|
|
175
175
|
|
|
176
176
|
assert success_called2
|
|
@@ -308,6 +308,32 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
308
308
|
end
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
+
def test_multi_easy_download_01
|
|
312
|
+
# test collecting response buffers to file e.g. on_body
|
|
313
|
+
root_uri = 'http://127.0.0.1:9129/ext/'
|
|
314
|
+
urls = []
|
|
315
|
+
downloads = []
|
|
316
|
+
file_info = {}
|
|
317
|
+
FileUtils.mkdir("tmp/")
|
|
318
|
+
|
|
319
|
+
# for each file store the size by file name
|
|
320
|
+
Dir[File.dirname(__FILE__) + "/../ext/*.c"].each do|path|
|
|
321
|
+
urls << (root_uri + File.basename(path))
|
|
322
|
+
downloads << "tmp/" + File.basename(path)
|
|
323
|
+
file_info[File.basename(path)] = {:size => File.size(path), :path => path}
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# start downloads
|
|
327
|
+
Curl::Multi.download(urls,{},{},downloads) do|curl,download_path|
|
|
328
|
+
assert_equal 200, curl.response_code
|
|
329
|
+
assert File.exist?(download_path)
|
|
330
|
+
store = file_info[File.basename(download_path)]
|
|
331
|
+
assert_equal file_info[File.basename(download_path)][:size], File.size(download_path), "incomplete download: #{download_path}"
|
|
332
|
+
end
|
|
333
|
+
ensure
|
|
334
|
+
FileUtils.rm_rf("tmp/")
|
|
335
|
+
end
|
|
336
|
+
|
|
311
337
|
def test_multi_easy_post_01
|
|
312
338
|
urls = [
|
|
313
339
|
{ :url => TestServlet.url + '?q=1', :post_fields => {'field1' => 'value1', 'k' => 'j'}},
|
|
@@ -359,7 +385,26 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
359
385
|
end
|
|
360
386
|
end
|
|
361
387
|
|
|
362
|
-
def
|
|
388
|
+
def test_multi_easy_http_with_max_connects
|
|
389
|
+
urls = [
|
|
390
|
+
{ :url => TestServlet.url + '?q=1', :method => :get },
|
|
391
|
+
{ :url => TestServlet.url + '?q=2', :method => :get },
|
|
392
|
+
{ :url => TestServlet.url + '?q=3', :method => :get }
|
|
393
|
+
]
|
|
394
|
+
Curl::Multi.http(urls, {:pipeline => true, :max_connects => 1}) do|easy, code, method|
|
|
395
|
+
assert_equal nil, code
|
|
396
|
+
case method
|
|
397
|
+
when :post
|
|
398
|
+
assert_match /POST/, easy.body_str
|
|
399
|
+
when :get
|
|
400
|
+
assert_match /GET/, easy.body_str
|
|
401
|
+
when :put
|
|
402
|
+
assert_match /PUT/, easy.body_str
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
def test_multi_recieves_500
|
|
363
408
|
m = Curl::Multi.new
|
|
364
409
|
e = Curl::Easy.new("http://127.0.0.1:9129/methods")
|
|
365
410
|
failure = false
|
|
@@ -384,7 +429,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
384
429
|
c = Curl::Easy.new("http://127.9.9.9:999110")
|
|
385
430
|
m.remove(c)
|
|
386
431
|
rescue => e
|
|
387
|
-
assert_equal 'Invalid easy handle', e.message
|
|
432
|
+
assert_equal 'CURLError: Invalid easy handle', e.message
|
|
388
433
|
assert_equal 0, m.requests.size
|
|
389
434
|
end
|
|
390
435
|
|
|
@@ -424,6 +469,13 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
424
469
|
assert_equal Curl::Err::MultiBadEasyHandle, e.class
|
|
425
470
|
end
|
|
426
471
|
|
|
472
|
+
def test_multi_default_timeout
|
|
473
|
+
assert_equal 100, Curl::Multi.default_timeout
|
|
474
|
+
Curl::Multi.default_timeout = 12
|
|
475
|
+
assert_equal 12, Curl::Multi.default_timeout
|
|
476
|
+
assert_equal 100, (Curl::Multi.default_timeout = 100)
|
|
477
|
+
end
|
|
478
|
+
|
|
427
479
|
include TestServerMethods
|
|
428
480
|
|
|
429
481
|
def setup
|
data/tests/tc_curl_postfield.rb
CHANGED
|
@@ -62,6 +62,7 @@ class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
|
62
62
|
assert_equal 'foo', pf.name
|
|
63
63
|
assert_equal 'localname', pf.local_file
|
|
64
64
|
assert_equal 'localname', pf.remote_file
|
|
65
|
+
assert_nothing_raised { pf.to_s }
|
|
65
66
|
assert_nil pf.content_type
|
|
66
67
|
assert_nil pf.content
|
|
67
68
|
assert_nil pf.set_content_proc
|
|
@@ -136,6 +137,7 @@ class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
|
136
137
|
|
|
137
138
|
def test_to_s_04
|
|
138
139
|
pf = Curl::PostField.file('foo.file', 'bar.file')
|
|
139
|
-
|
|
140
|
+
assert_nothing_raised { pf.to_s }
|
|
141
|
+
#assert_raise(Curl::Err::InvalidPostFieldError) { pf.to_s }
|
|
140
142
|
end
|
|
141
143
|
end
|