ghazel-curb 0.6.2.3 → 0.7.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +8 -1
- data/Rakefile +20 -1
- data/ext/curb.c +34 -0
- data/ext/curb.h +6 -4
- data/ext/curb_easy.c +627 -181
- data/ext/curb_easy.h +28 -2
- data/ext/curb_errors.c +2 -0
- data/ext/curb_errors.h +1 -0
- data/ext/curb_macros.h +1 -1
- data/ext/curb_multi.c +155 -59
- data/ext/curb_postfield.c +61 -49
- data/ext/curb_upload.c +2 -2
- data/ext/extconf.rb +7 -2
- data/lib/curb.rb +94 -5
- data/tests/bug_curb_easy_post_with_string_no_content_length_header.rb +83 -0
- data/tests/bug_multi_segfault.rb +6 -2
- data/tests/bug_postfields_crash.rb +26 -0
- data/tests/bug_postfields_crash2.rb +57 -0
- data/tests/bugtests.rb +9 -0
- data/tests/helper.rb +21 -7
- data/tests/mem_check.rb +65 -0
- data/tests/tc_curl_download.rb +44 -1
- data/tests/tc_curl_easy.rb +181 -11
- data/tests/tc_curl_multi.rb +36 -3
- data/tests/tc_curl_postfield.rb +3 -1
- data/tests/timeout.rb +100 -0
- data/tests/timeout_server.rb +33 -0
- metadata +44 -5
data/tests/tc_curl_easy.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
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
|
4
7
|
def test_class_perform_01
|
@@ -57,8 +60,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
57
60
|
assert_equal nil, c.on_body
|
58
61
|
end
|
59
62
|
|
60
|
-
class Foo < Curl::Easy
|
61
|
-
end
|
63
|
+
class Foo < Curl::Easy ; end
|
62
64
|
def test_new_05
|
63
65
|
# can use Curl::Easy as a base class
|
64
66
|
c = Foo.new
|
@@ -352,6 +354,30 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
352
354
|
assert_equal 30, c.dns_cache_timeout
|
353
355
|
end
|
354
356
|
|
357
|
+
def test_low_speed_limit_01
|
358
|
+
c = Curl::Easy.new($TEST_URL)
|
359
|
+
|
360
|
+
assert_nil c.low_speed_limit
|
361
|
+
|
362
|
+
c.low_speed_limit = 3
|
363
|
+
assert_equal 3, c.low_speed_limit
|
364
|
+
|
365
|
+
c.low_speed_limit = nil
|
366
|
+
assert_nil c.low_speed_limit
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_low_speed_time_01
|
370
|
+
c = Curl::Easy.new($TEST_URL)
|
371
|
+
|
372
|
+
assert_nil c.low_speed_time
|
373
|
+
|
374
|
+
c.low_speed_time = 3
|
375
|
+
assert_equal 3, c.low_speed_time
|
376
|
+
|
377
|
+
c.low_speed_time = nil
|
378
|
+
assert_nil c.low_speed_time
|
379
|
+
end
|
380
|
+
|
355
381
|
def test_on_body
|
356
382
|
blk = lambda { |i| i.length }
|
357
383
|
|
@@ -361,6 +387,25 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
361
387
|
assert_equal blk, c.on_body # sets handler nil, returns old handler
|
362
388
|
assert_equal nil, c.on_body
|
363
389
|
end
|
390
|
+
|
391
|
+
def test_inspect_with_no_url
|
392
|
+
c = Curl::Easy.new
|
393
|
+
assert_equal '#<Curl::Easy>', c.inspect
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_inspect_with_short_url
|
397
|
+
c = Curl::Easy.new('http://www.google.com/')
|
398
|
+
assert_equal "#<Curl::Easy http://www.google.com/>", c.inspect
|
399
|
+
end
|
400
|
+
|
401
|
+
def test_inspect_truncates_to_64_chars
|
402
|
+
base_url = 'http://www.google.com/'
|
403
|
+
truncated_url = base_url + 'x' * (64 - '#<Curl::Easy >'.size - base_url.size)
|
404
|
+
long_url = truncated_url + 'yyyy'
|
405
|
+
c = Curl::Easy.new(long_url)
|
406
|
+
assert_equal 64, c.inspect.size
|
407
|
+
assert_equal "#<Curl::Easy #{truncated_url}>", c.inspect
|
408
|
+
end
|
364
409
|
|
365
410
|
def test_on_header
|
366
411
|
blk = lambda { |i| i.length }
|
@@ -455,6 +500,13 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
455
500
|
assert c.multipart_form_post?
|
456
501
|
end
|
457
502
|
|
503
|
+
def test_ignore_content_length
|
504
|
+
c = Curl::Easy.new
|
505
|
+
assert !c.ignore_content_length?
|
506
|
+
assert c.ignore_content_length = true
|
507
|
+
assert c.ignore_content_length?
|
508
|
+
end
|
509
|
+
|
458
510
|
def test_enable_cookies
|
459
511
|
c = Curl::Easy.new
|
460
512
|
assert !c.enable_cookies?
|
@@ -513,8 +565,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
513
565
|
|
514
566
|
def test_post_remote
|
515
567
|
curl = Curl::Easy.new(TestServlet.url)
|
516
|
-
curl.http_post
|
517
|
-
assert_equal "POST\
|
568
|
+
curl.http_post([Curl::PostField.content('document_id', 5)])
|
569
|
+
assert_equal "POST\ndocument%5Fid=5", curl.body_str
|
518
570
|
end
|
519
571
|
|
520
572
|
def test_post_remote_is_easy_handle
|
@@ -548,12 +600,27 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
548
600
|
assert_equal 'foo=bar&encoded%20string=val', curl.post_body
|
549
601
|
end
|
550
602
|
|
603
|
+
def test_post_multipart_file_remote
|
604
|
+
curl = Curl::Easy.new(TestServlet.url)
|
605
|
+
curl.multipart_form_post = true
|
606
|
+
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
607
|
+
curl.http_post(pf)
|
608
|
+
assert_match /HTTP POST file upload/, curl.body_str
|
609
|
+
assert_match /Content-Disposition: form-data/, curl.body_str
|
610
|
+
end
|
611
|
+
|
551
612
|
def test_delete_remote
|
552
613
|
curl = Curl::Easy.new(TestServlet.url)
|
553
614
|
curl.http_delete
|
554
615
|
assert_equal 'DELETE', curl.body_str
|
555
616
|
end
|
556
617
|
|
618
|
+
def test_arbitrary_http_verb
|
619
|
+
curl = Curl::Easy.new(TestServlet.url)
|
620
|
+
curl.http('PURGE')
|
621
|
+
assert_equal 'PURGE', curl.body_str
|
622
|
+
end
|
623
|
+
|
557
624
|
def test_head_remote
|
558
625
|
curl = Curl::Easy.new(TestServlet.url)
|
559
626
|
curl.http_head
|
@@ -597,6 +664,13 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
597
664
|
assert_match /message$/, curl.body_str
|
598
665
|
end
|
599
666
|
|
667
|
+
def test_put_nil_data_no_crash
|
668
|
+
curl = Curl::Easy.new(TestServlet.url)
|
669
|
+
curl.put_data = nil
|
670
|
+
|
671
|
+
curl.perform
|
672
|
+
end
|
673
|
+
|
600
674
|
def test_put_remote_file
|
601
675
|
curl = Curl::Easy.new(TestServlet.url)
|
602
676
|
File.open(__FILE__,'r') do|f|
|
@@ -621,24 +695,26 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
621
695
|
def test_cert
|
622
696
|
curl = Curl::Easy.new(TestServlet.url)
|
623
697
|
curl.cert= File.join(File.dirname(__FILE__),"cert.pem")
|
624
|
-
|
698
|
+
assert_match /cert.pem$/,curl.cert
|
625
699
|
end
|
626
700
|
|
627
701
|
def test_cert_with_password
|
628
702
|
curl = Curl::Easy.new(TestServlet.url)
|
629
703
|
curl.cert= File.join(File.dirname(__FILE__),"cert.pem:password")
|
630
|
-
|
704
|
+
assert_match /cert.pem$/,curl.cert
|
631
705
|
end
|
632
706
|
|
633
707
|
def test_cert_type
|
634
708
|
curl = Curl::Easy.new(TestServlet.url)
|
635
709
|
curl.certtype= "DER"
|
636
|
-
|
710
|
+
assert_equal "DER", curl.certtype
|
637
711
|
end
|
638
712
|
|
639
713
|
def test_default_certtype
|
640
714
|
curl = Curl::Easy.new(TestServlet.url)
|
641
|
-
|
715
|
+
assert_nil curl.certtype
|
716
|
+
curl.certtype = "PEM"
|
717
|
+
assert_equal "PEM", curl.certtype
|
642
718
|
end
|
643
719
|
|
644
720
|
# Generate a CA cert with instructions at
|
@@ -646,13 +722,13 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
646
722
|
def test_ca_cert
|
647
723
|
curl = Curl::Easy.new(TestServlet.url)
|
648
724
|
curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")
|
649
|
-
|
725
|
+
assert_match /cacert.pem$/, curl.cacert
|
650
726
|
end
|
651
727
|
|
652
728
|
def test_user_agent
|
653
729
|
curl = Curl::Easy.new(TestServlet.url)
|
654
730
|
curl.useragent= "Curb-Easy/Ruby"
|
655
|
-
|
731
|
+
assert_equal "Curb-Easy/Ruby",curl.useragent
|
656
732
|
end
|
657
733
|
|
658
734
|
def test_username_password
|
@@ -669,7 +745,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
669
745
|
#curl.verbose = true
|
670
746
|
curl.perform
|
671
747
|
assert_equal 'Basic Zm9vOmJhcg==', $auth_header
|
672
|
-
|
748
|
+
$auth_header = nil
|
673
749
|
# curl checks the auth type supported by the server, so we have to create a
|
674
750
|
# new easy handle if we're going to change the auth type...
|
675
751
|
|
@@ -684,6 +760,100 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
684
760
|
assert_equal 'NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=', $auth_header
|
685
761
|
end
|
686
762
|
|
763
|
+
def test_primary_ip
|
764
|
+
curl = Curl::Easy.new(TestServlet.url)
|
765
|
+
if curl.respond_to?(:primary_ip)
|
766
|
+
curl.perform
|
767
|
+
assert_equal '127.0.0.1', curl.primary_ip
|
768
|
+
end
|
769
|
+
end
|
770
|
+
|
771
|
+
def test_post_streaming
|
772
|
+
readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README'))
|
773
|
+
|
774
|
+
pf = Curl::PostField.file("filename", readme)
|
775
|
+
|
776
|
+
easy = Curl::Easy.new
|
777
|
+
|
778
|
+
easy.url = TestServlet.url
|
779
|
+
easy.multipart_form_post = true
|
780
|
+
easy.http_post(pf)
|
781
|
+
|
782
|
+
assert_not_equal(0,easy.body_str.size)
|
783
|
+
assert_equal(easy.body_str,File.read(readme))
|
784
|
+
end
|
785
|
+
|
786
|
+
|
787
|
+
def test_easy_close
|
788
|
+
easy = Curl::Easy.new
|
789
|
+
easy.close
|
790
|
+
easy.url = TestServlet.url
|
791
|
+
easy.http_get
|
792
|
+
end
|
793
|
+
|
794
|
+
def test_easy_reset
|
795
|
+
easy = Curl::Easy.new
|
796
|
+
easy.url = TestServlet.url + "?query=foo"
|
797
|
+
easy.http_get
|
798
|
+
settings = easy.reset
|
799
|
+
assert settings.key?(:url)
|
800
|
+
assert settings.key?(:body_data)
|
801
|
+
assert settings.key?(:header_data)
|
802
|
+
easy.url = TestServlet.url
|
803
|
+
easy.http_get
|
804
|
+
end
|
805
|
+
|
806
|
+
def test_easy_use_http_versions
|
807
|
+
easy = Curl::Easy.new
|
808
|
+
easy.url = TestServlet.url + "?query=foo"
|
809
|
+
#puts "http none: #{Curl::HTTP_NONE.inspect}"
|
810
|
+
#puts "http1.0: #{Curl::HTTP_1_0.inspect}"
|
811
|
+
#puts "http1.1: #{Curl::HTTP_1_1.inspect}"
|
812
|
+
easy.version = Curl::HTTP_1_1
|
813
|
+
#easy.verbose = true
|
814
|
+
easy.http_get
|
815
|
+
end
|
816
|
+
|
817
|
+
def test_easy_http_verbs
|
818
|
+
curl = Curl::Easy.new(TestServlet.url)
|
819
|
+
curl.http_delete
|
820
|
+
assert_equal 'DELETE', curl.body_str
|
821
|
+
curl.http_get
|
822
|
+
assert_equal 'GET', curl.body_str
|
823
|
+
curl.http_post
|
824
|
+
assert_equal "POST\n", curl.body_str
|
825
|
+
curl.http('PURGE')
|
826
|
+
assert_equal 'PURGE', curl.body_str
|
827
|
+
curl.http_put('hello')
|
828
|
+
assert_equal "PUT\nhello", curl.body_str
|
829
|
+
curl.http('COPY')
|
830
|
+
assert_equal 'COPY', curl.body_str
|
831
|
+
end
|
832
|
+
|
833
|
+
def test_easy_http_verbs_must_respond_to_str
|
834
|
+
# issue http://github.com/taf2/curb/issues#issue/45
|
835
|
+
assert_nothing_raised do
|
836
|
+
c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(:get)
|
837
|
+
end
|
838
|
+
|
839
|
+
assert_raise RuntimeError do
|
840
|
+
c = Curl::Easy.new ; c.url = 'http://example.com' ; c.http(FooNoToS.new)
|
841
|
+
end
|
842
|
+
|
843
|
+
end
|
844
|
+
|
845
|
+
# http://github.com/taf2/curb/issues/#issue/33
|
846
|
+
def test_easy_http_verbs_with_errors
|
847
|
+
curl = Curl::Easy.new("http://127.0.0.1:9012/") # test will fail if http server on port 9012
|
848
|
+
assert_raise Curl::Err::ConnectionFailedError do
|
849
|
+
curl.http_delete
|
850
|
+
end
|
851
|
+
curl.url = TestServlet.url
|
852
|
+
curl.http_get
|
853
|
+
assert_equal 'GET', curl.body_str
|
854
|
+
end
|
855
|
+
|
856
|
+
|
687
857
|
include TestServerMethods
|
688
858
|
|
689
859
|
def setup
|
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'}},
|
@@ -424,6 +450,13 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
424
450
|
assert_equal Curl::Err::MultiBadEasyHandle, e.class
|
425
451
|
end
|
426
452
|
|
453
|
+
def test_multi_default_timeout
|
454
|
+
assert_equal 100, Curl::Multi.default_timeout
|
455
|
+
Curl::Multi.default_timeout = 12
|
456
|
+
assert_equal 12, Curl::Multi.default_timeout
|
457
|
+
assert_equal 100, (Curl::Multi.default_timeout = 100)
|
458
|
+
end
|
459
|
+
|
427
460
|
include TestServerMethods
|
428
461
|
|
429
462
|
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
|
data/tests/timeout.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
# Run server with: ruby -rubygems timeout_server.rb -p 9128
|
4
|
+
|
5
|
+
# Note that curl requires all timeouts to be integers -
|
6
|
+
# curl_easy_setopt does not have a provision for floating-point values
|
7
|
+
|
8
|
+
class TestCurbTimeouts < Test::Unit::TestCase
|
9
|
+
def test_no_timeout_by_default
|
10
|
+
curl = Curl::Easy.new(wait_url(2))
|
11
|
+
start = Time.now
|
12
|
+
assert_equal true, curl.http_get
|
13
|
+
elapsed = Time.now - start
|
14
|
+
assert elapsed > 2
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_overall_timeout_on_dead_transfer
|
18
|
+
curl = Curl::Easy.new(wait_url(2))
|
19
|
+
curl.timeout = 1
|
20
|
+
assert_raise(Curl::Err::TimeoutError) do
|
21
|
+
curl.http_get
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_clearing_timeout
|
26
|
+
curl = Curl::Easy.new(wait_url(2))
|
27
|
+
curl.timeout = 1
|
28
|
+
curl.timeout = nil
|
29
|
+
start = Time.now
|
30
|
+
assert_equal true, curl.http_get
|
31
|
+
elapsed = Time.now - start
|
32
|
+
assert elapsed > 2
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_overall_timeout_on_slow_transfer
|
36
|
+
curl = Curl::Easy.new(serve_url(100, 2, 3))
|
37
|
+
curl.timeout = 1
|
38
|
+
# transfer is aborted despite data being exchanged
|
39
|
+
assert_raise(Curl::Err::TimeoutError) do
|
40
|
+
curl.http_get
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_low_speed_time_on_slow_transfer
|
45
|
+
curl = Curl::Easy.new(serve_url(100, 1, 3))
|
46
|
+
curl.low_speed_time = 2
|
47
|
+
# use default low_speed_limit of 1
|
48
|
+
assert true, curl.http_get
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_low_speed_time_on_very_slow_transfer
|
52
|
+
# send data slower than required
|
53
|
+
curl = Curl::Easy.new(serve_url(10, 2, 3))
|
54
|
+
curl.low_speed_time = 1
|
55
|
+
# XXX for some reason this test fails if low speed limit is not specified
|
56
|
+
curl.low_speed_limit = 1
|
57
|
+
# use default low_speed_limit of 1
|
58
|
+
assert_raise(Curl::Err::TimeoutError) do
|
59
|
+
curl.http_get
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_low_speed_limit_on_slow_transfer
|
64
|
+
curl = Curl::Easy.new(serve_url(10, 1, 3))
|
65
|
+
curl.low_speed_time = 2
|
66
|
+
curl.low_speed_limit = 1000
|
67
|
+
assert_raise(Curl::Err::TimeoutError) do
|
68
|
+
curl.http_get
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_clearing_low_speed_time
|
73
|
+
curl = Curl::Easy.new(serve_url(100, 2, 3))
|
74
|
+
curl.low_speed_time = 1
|
75
|
+
curl.low_speed_time = nil
|
76
|
+
assert_equal true, curl.http_get
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_clearing_low_speed_limit
|
80
|
+
curl = Curl::Easy.new(serve_url(10, 1, 3))
|
81
|
+
curl.low_speed_time = 2
|
82
|
+
curl.low_speed_limit = 1000
|
83
|
+
curl.low_speed_limit = nil
|
84
|
+
assert_equal true, curl.http_get
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def wait_url(time)
|
90
|
+
"#{server_base}/wait/#{time}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def serve_url(chunk_size, time, count)
|
94
|
+
"#{server_base}/serve/#{chunk_size}/every/#{time}/for/#{count}"
|
95
|
+
end
|
96
|
+
|
97
|
+
def server_base
|
98
|
+
'http://127.0.0.1:9128'
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This Sinatra application must be run with mongrel
|
2
|
+
# or possibly with unicorn for the serve action to work properly.
|
3
|
+
# See http://efreedom.com/Question/1-3669674/Streaming-Data-Sinatra-Rack-Application
|
4
|
+
|
5
|
+
require 'sinatra'
|
6
|
+
|
7
|
+
get '/wait/:time' do |time|
|
8
|
+
time = time.to_i
|
9
|
+
sleep(time)
|
10
|
+
"Slept #{time} at #{Time.now}"
|
11
|
+
end
|
12
|
+
|
13
|
+
# http://efreedom.com/Question/1-3027435/Way-Flush-Html-Wire-Sinatra
|
14
|
+
class Streamer
|
15
|
+
def initialize(time, chunks)
|
16
|
+
@time = time
|
17
|
+
@chunks = chunks
|
18
|
+
end
|
19
|
+
|
20
|
+
def each
|
21
|
+
@chunks.each do |chunk|
|
22
|
+
sleep(@time)
|
23
|
+
yield chunk
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
get '/serve/:chunk_size/every/:time/for/:count' do |chunk_size, time, count|
|
29
|
+
chunk_size, time, count = chunk_size.to_i, time.to_i, count.to_i
|
30
|
+
chunk = 'x' * chunk_size
|
31
|
+
chunks = [chunk] * count
|
32
|
+
Streamer.new(time, chunks)
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghazel-curb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 81
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 7
|
9
|
+
- 9
|
10
|
+
- 1
|
11
|
+
version: 0.7.9.1
|
5
12
|
platform: ruby
|
6
13
|
authors:
|
7
14
|
- Ross Bamford
|
@@ -10,7 +17,7 @@ autorequire:
|
|
10
17
|
bindir: bin
|
11
18
|
cert_chain: []
|
12
19
|
|
13
|
-
date:
|
20
|
+
date: 2010-12-22 00:00:00 -08:00
|
14
21
|
default_executable:
|
15
22
|
dependencies: []
|
16
23
|
|
@@ -44,6 +51,25 @@ files:
|
|
44
51
|
- ext/curb_multi.h
|
45
52
|
- ext/curb_postfield.h
|
46
53
|
- ext/curb_upload.h
|
54
|
+
- tests/alltests.rb
|
55
|
+
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
56
|
+
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
57
|
+
- tests/bug_instance_post_differs_from_class_post.rb
|
58
|
+
- tests/bug_multi_segfault.rb
|
59
|
+
- tests/bug_postfields_crash.rb
|
60
|
+
- tests/bug_postfields_crash2.rb
|
61
|
+
- tests/bug_require_last_or_segfault.rb
|
62
|
+
- tests/bugtests.rb
|
63
|
+
- tests/helper.rb
|
64
|
+
- tests/mem_check.rb
|
65
|
+
- tests/require_last_or_segfault_script.rb
|
66
|
+
- tests/tc_curl_download.rb
|
67
|
+
- tests/tc_curl_easy.rb
|
68
|
+
- tests/tc_curl_multi.rb
|
69
|
+
- tests/tc_curl_postfield.rb
|
70
|
+
- tests/timeout.rb
|
71
|
+
- tests/timeout_server.rb
|
72
|
+
- tests/unittests.rb
|
47
73
|
has_rdoc: true
|
48
74
|
homepage: http://curb.rubyforge.org/
|
49
75
|
licenses: []
|
@@ -56,34 +82,47 @@ require_paths:
|
|
56
82
|
- lib
|
57
83
|
- ext
|
58
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
59
86
|
requirements:
|
60
87
|
- - ">="
|
61
88
|
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
62
92
|
version: "0"
|
63
|
-
version:
|
64
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
65
95
|
requirements:
|
66
96
|
- - ">="
|
67
97
|
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
68
101
|
version: "0"
|
69
|
-
version:
|
70
102
|
requirements: []
|
71
103
|
|
72
104
|
rubyforge_project: curb
|
73
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.4.2
|
74
106
|
signing_key:
|
75
107
|
specification_version: 3
|
76
108
|
summary: Ruby libcurl bindings
|
77
109
|
test_files:
|
78
110
|
- tests/alltests.rb
|
79
111
|
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
112
|
+
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
80
113
|
- tests/bug_instance_post_differs_from_class_post.rb
|
81
114
|
- tests/bug_multi_segfault.rb
|
115
|
+
- tests/bug_postfields_crash.rb
|
116
|
+
- tests/bug_postfields_crash2.rb
|
82
117
|
- tests/bug_require_last_or_segfault.rb
|
118
|
+
- tests/bugtests.rb
|
83
119
|
- tests/helper.rb
|
120
|
+
- tests/mem_check.rb
|
84
121
|
- tests/require_last_or_segfault_script.rb
|
85
122
|
- tests/tc_curl_download.rb
|
86
123
|
- tests/tc_curl_easy.rb
|
87
124
|
- tests/tc_curl_multi.rb
|
88
125
|
- tests/tc_curl_postfield.rb
|
126
|
+
- tests/timeout.rb
|
127
|
+
- tests/timeout_server.rb
|
89
128
|
- tests/unittests.rb
|