curb 0.7.15 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.markdown +283 -0
- data/Rakefile +38 -26
- data/ext/banned.h +32 -0
- data/ext/curb.c +903 -46
- data/ext/curb.h +20 -11
- data/ext/curb_easy.c +1039 -565
- data/ext/curb_easy.h +12 -0
- data/ext/curb_errors.c +127 -18
- data/ext/curb_errors.h +8 -5
- data/ext/curb_macros.h +10 -6
- data/ext/curb_multi.c +245 -167
- data/ext/curb_multi.h +0 -1
- data/ext/curb_upload.c +2 -2
- data/ext/extconf.rb +314 -20
- data/lib/curb.rb +2 -308
- data/lib/curl/easy.rb +489 -0
- data/lib/curl/multi.rb +287 -0
- data/lib/curl.rb +68 -1
- data/tests/bug_crash_on_debug.rb +39 -0
- data/tests/bug_crash_on_progress.rb +73 -0
- data/tests/bug_curb_easy_blocks_ruby_threads.rb +2 -2
- data/tests/bug_issue102.rb +17 -0
- data/tests/bug_require_last_or_segfault.rb +1 -1
- data/tests/helper.rb +120 -16
- data/tests/signals.rb +33 -0
- data/tests/tc_curl.rb +69 -0
- data/tests/tc_curl_download.rb +4 -4
- data/tests/tc_curl_easy.rb +327 -43
- data/tests/tc_curl_easy_resolve.rb +16 -0
- data/tests/tc_curl_easy_setopt.rb +31 -0
- data/tests/tc_curl_maxfilesize.rb +12 -0
- data/tests/tc_curl_multi.rb +141 -15
- data/tests/tc_curl_postfield.rb +29 -29
- data/tests/tc_curl_protocols.rb +37 -0
- data/tests/timeout.rb +30 -6
- metadata +61 -58
- data/README +0 -177
data/tests/tc_curl_multi.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
2
|
+
require 'set'
|
|
2
3
|
|
|
3
4
|
class TestCurbCurlMulti < Test::Unit::TestCase
|
|
4
5
|
def teardown
|
|
@@ -6,6 +7,110 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
6
7
|
ObjectSpace.garbage_collect
|
|
7
8
|
end
|
|
8
9
|
|
|
10
|
+
# for https://github.com/taf2/curb/issues/277
|
|
11
|
+
# must connect to an external
|
|
12
|
+
def test_connection_keepalive
|
|
13
|
+
# this test fails with libcurl 7.22.0. I didn't investigate, but it may be related
|
|
14
|
+
# to CURLOPT_MAXCONNECTS bug fixed in 7.30.0:
|
|
15
|
+
# https://github.com/curl/curl/commit/e87e76e2dc108efb1cae87df496416f49c55fca0
|
|
16
|
+
omit("Skip, libcurl too old (< 7.22.0)") if Curl::CURL_VERSION.split('.')[1].to_i <= 22
|
|
17
|
+
|
|
18
|
+
@server.shutdown if @server
|
|
19
|
+
@test_thread.kill if @test_thread
|
|
20
|
+
@server = nil
|
|
21
|
+
File.unlink(locked_file)
|
|
22
|
+
Curl::Multi.autoclose = true
|
|
23
|
+
assert Curl::Multi.autoclose
|
|
24
|
+
# XXX: thought maybe we can clean house here to have the full suite pass in osx... but for now running this test in isolate does pass
|
|
25
|
+
# additionally, if ss allows this to pass on linux without requesting google i think this is a good trade off... leaving some of the thoughts below
|
|
26
|
+
# in hopes that coming back to this later will find it and remember how to fix it
|
|
27
|
+
# types = Set.new
|
|
28
|
+
# close_types = Set.new([TCPServer,TCPSocket,Socket,Curl::Multi, Curl::Easy,WEBrick::Log])
|
|
29
|
+
# ObjectSpace.each_object {|o|
|
|
30
|
+
# if o.respond_to?(:close)
|
|
31
|
+
# types << o.class
|
|
32
|
+
# end
|
|
33
|
+
# if close_types.include?(o.class)
|
|
34
|
+
# o.close
|
|
35
|
+
# end
|
|
36
|
+
# }
|
|
37
|
+
#puts "unique types: #{types.to_a.join("\n")}"
|
|
38
|
+
GC.start # cleanup FDs left over from other tests
|
|
39
|
+
server_setup
|
|
40
|
+
GC.start # cleanup FDs left over from other tests
|
|
41
|
+
|
|
42
|
+
if `which ss`.strip.size == 0
|
|
43
|
+
# osx need lsof still :(
|
|
44
|
+
open_fds = lambda do
|
|
45
|
+
out = `/usr/sbin/lsof -p #{Process.pid} | egrep "TCP|UDP"`# | egrep ':#{TestServlet.port} ' | egrep ESTABLISHED`# | wc -l`.strip.to_i
|
|
46
|
+
#puts out.lines.join("\n")
|
|
47
|
+
out.lines.size
|
|
48
|
+
end
|
|
49
|
+
else
|
|
50
|
+
ss = `which ss`.strip
|
|
51
|
+
open_fds = lambda do
|
|
52
|
+
`#{ss} -n4 state established dport = :#{TestServlet.port} | wc -l`.strip.to_i
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
Curl::Multi.autoclose = false
|
|
56
|
+
before_open = open_fds.call
|
|
57
|
+
#puts "before_open: #{before_open.inspect}"
|
|
58
|
+
assert !Curl::Multi.autoclose
|
|
59
|
+
multi = Curl::Multi.new
|
|
60
|
+
multi.max_connects = 1 # limit to 1 connection within the multi handle
|
|
61
|
+
|
|
62
|
+
did_complete = false
|
|
63
|
+
5.times do |n|
|
|
64
|
+
easy = Curl::Easy.new(TestServlet.url) do |curl|
|
|
65
|
+
curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
|
|
66
|
+
curl.on_complete {
|
|
67
|
+
did_complete = true
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
multi.add(easy)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
multi.perform
|
|
74
|
+
assert did_complete
|
|
75
|
+
after_open = open_fds.call
|
|
76
|
+
#puts "after_open: #{after_open} before_open: #{before_open.inspect}"
|
|
77
|
+
assert_equal 1, (after_open - before_open), "with max connections set to 1 at this point the connection to google should still be open"
|
|
78
|
+
multi.close
|
|
79
|
+
|
|
80
|
+
after_open = open_fds.call
|
|
81
|
+
#puts "after_open: #{after_open} before_open: #{before_open.inspect}"
|
|
82
|
+
assert_equal 0, (after_open - before_open), "after closing the multi handle all connections should be closed"
|
|
83
|
+
|
|
84
|
+
Curl::Multi.autoclose = true
|
|
85
|
+
multi = Curl::Multi.new
|
|
86
|
+
did_complete = false
|
|
87
|
+
5.times do |n|
|
|
88
|
+
easy = Curl::Easy.new(TestServlet.url) do |curl|
|
|
89
|
+
curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
|
|
90
|
+
curl.on_complete {
|
|
91
|
+
did_complete = true
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
multi.add(easy)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
multi.perform
|
|
98
|
+
assert did_complete
|
|
99
|
+
after_open = open_fds.call
|
|
100
|
+
#puts "after_open: #{after_open} before_open: #{before_open.inspect}"
|
|
101
|
+
assert_equal 0, (after_open - before_open), "auto close the connections"
|
|
102
|
+
ensure
|
|
103
|
+
Curl::Multi.autoclose = false # restore default
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_connection_autoclose
|
|
107
|
+
assert !Curl::Multi.autoclose
|
|
108
|
+
Curl::Multi.autoclose = true
|
|
109
|
+
assert Curl::Multi.autoclose
|
|
110
|
+
ensure
|
|
111
|
+
Curl::Multi.autoclose = false # restore default
|
|
112
|
+
end
|
|
113
|
+
|
|
9
114
|
def test_new_multi_01
|
|
10
115
|
d1 = ""
|
|
11
116
|
c1 = Curl::Easy.new($TEST_URL) do |curl|
|
|
@@ -109,8 +214,12 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
109
214
|
|
|
110
215
|
assert(m.idle?, 'A new Curl::Multi handle should be idle')
|
|
111
216
|
|
|
217
|
+
assert_nil e.multi
|
|
218
|
+
|
|
112
219
|
m.add(e)
|
|
113
220
|
|
|
221
|
+
assert_not_nil e.multi
|
|
222
|
+
|
|
114
223
|
assert((not m.idle?), 'A Curl::Multi handle with a request should not be idle')
|
|
115
224
|
|
|
116
225
|
m.perform
|
|
@@ -121,7 +230,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
121
230
|
def test_requests
|
|
122
231
|
m = Curl::Multi.new
|
|
123
232
|
|
|
124
|
-
assert_equal(
|
|
233
|
+
assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests')
|
|
125
234
|
|
|
126
235
|
10.times do
|
|
127
236
|
m.add(Curl::Easy.new($TEST_URL))
|
|
@@ -131,7 +240,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
131
240
|
|
|
132
241
|
m.perform
|
|
133
242
|
|
|
134
|
-
assert_equal(
|
|
243
|
+
assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests after a perform')
|
|
135
244
|
end
|
|
136
245
|
|
|
137
246
|
def test_cancel
|
|
@@ -144,7 +253,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
144
253
|
|
|
145
254
|
m.cancel!
|
|
146
255
|
|
|
147
|
-
assert_equal(
|
|
256
|
+
assert_equal(0, m.requests.size, 'A new Curl::Multi handle should have no requests after being canceled')
|
|
148
257
|
end
|
|
149
258
|
|
|
150
259
|
def test_with_success
|
|
@@ -188,7 +297,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
188
297
|
c1.on_success do|c|
|
|
189
298
|
success_called1 = true
|
|
190
299
|
#puts "success 1 called: #{c.body_str.inspect}"
|
|
191
|
-
|
|
300
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
|
192
301
|
end
|
|
193
302
|
|
|
194
303
|
c1.on_failure do|c,rc|
|
|
@@ -327,7 +436,6 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
327
436
|
Curl::Multi.download(urls,{},{},downloads) do|curl,download_path|
|
|
328
437
|
assert_equal 200, curl.response_code
|
|
329
438
|
assert File.exist?(download_path)
|
|
330
|
-
store = file_info[File.basename(download_path)]
|
|
331
439
|
assert_equal file_info[File.basename(download_path)][:size], File.size(download_path), "incomplete download: #{download_path}"
|
|
332
440
|
end
|
|
333
441
|
ensure
|
|
@@ -342,7 +450,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
342
450
|
]
|
|
343
451
|
Curl::Multi.post(urls, {:follow_location => true, :multipart_form_post => true}, {:pipeline => true}) do|easy|
|
|
344
452
|
str = easy.body_str
|
|
345
|
-
assert_match
|
|
453
|
+
assert_match(/POST/, str)
|
|
346
454
|
fields = {}
|
|
347
455
|
str.gsub(/POST\n/,'').split('&').map{|sv| k, v = sv.split('='); fields[k] = v }
|
|
348
456
|
expected = urls.find{|s| s[:url] == easy.last_effective_url }
|
|
@@ -357,8 +465,8 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
357
465
|
{ :url => TestServlet.url, :method => :put, :put_data => "message",
|
|
358
466
|
:headers => {'Content-Type' => 'application/json' } }]
|
|
359
467
|
Curl::Multi.put(urls, {}, {:pipeline => true}) do|easy|
|
|
360
|
-
assert_match
|
|
361
|
-
assert_match
|
|
468
|
+
assert_match(/PUT/, easy.body_str)
|
|
469
|
+
assert_match(/message/, easy.body_str)
|
|
362
470
|
end
|
|
363
471
|
end
|
|
364
472
|
|
|
@@ -375,17 +483,36 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
375
483
|
assert_equal nil, code
|
|
376
484
|
case method
|
|
377
485
|
when :post
|
|
378
|
-
assert_match
|
|
486
|
+
assert_match(/POST/, easy.body_str)
|
|
379
487
|
when :get
|
|
380
|
-
assert_match
|
|
488
|
+
assert_match(/GET/, easy.body_str)
|
|
381
489
|
when :put
|
|
382
|
-
assert_match
|
|
490
|
+
assert_match(/PUT/, easy.body_str)
|
|
383
491
|
end
|
|
384
492
|
#puts "#{easy.body_str.inspect}, #{method.inspect}, #{code.inspect}"
|
|
385
493
|
end
|
|
386
494
|
end
|
|
387
495
|
|
|
388
|
-
def
|
|
496
|
+
def test_multi_easy_http_with_max_connects
|
|
497
|
+
urls = [
|
|
498
|
+
{ :url => TestServlet.url + '?q=1', :method => :get },
|
|
499
|
+
{ :url => TestServlet.url + '?q=2', :method => :get },
|
|
500
|
+
{ :url => TestServlet.url + '?q=3', :method => :get }
|
|
501
|
+
]
|
|
502
|
+
Curl::Multi.http(urls, {:pipeline => true, :max_connects => 1}) do|easy, code, method|
|
|
503
|
+
assert_equal nil, code
|
|
504
|
+
case method
|
|
505
|
+
when :post
|
|
506
|
+
assert_match(/POST/, easy.body_str)
|
|
507
|
+
when :get
|
|
508
|
+
assert_match(/GET/, easy.body_str)
|
|
509
|
+
when :put
|
|
510
|
+
assert_match(/PUT/, easy.body_str)
|
|
511
|
+
end
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
def test_multi_recieves_500
|
|
389
516
|
m = Curl::Multi.new
|
|
390
517
|
e = Curl::Easy.new("http://127.0.0.1:9129/methods")
|
|
391
518
|
failure = false
|
|
@@ -410,7 +537,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
410
537
|
c = Curl::Easy.new("http://127.9.9.9:999110")
|
|
411
538
|
m.remove(c)
|
|
412
539
|
rescue => e
|
|
413
|
-
assert_equal 'Invalid easy handle', e.message
|
|
540
|
+
assert_equal 'CURLError: Invalid easy handle', e.message
|
|
414
541
|
assert_equal 0, m.requests.size
|
|
415
542
|
end
|
|
416
543
|
|
|
@@ -447,7 +574,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
447
574
|
m.add(c)
|
|
448
575
|
m.add(c)
|
|
449
576
|
rescue => e
|
|
450
|
-
|
|
577
|
+
assert Curl::Err::MultiBadEasyHandle == e.class || Curl::Err::MultiAddedAlready == e.class
|
|
451
578
|
end
|
|
452
579
|
|
|
453
580
|
def test_multi_default_timeout
|
|
@@ -462,5 +589,4 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
|
462
589
|
def setup
|
|
463
590
|
server_setup
|
|
464
591
|
end
|
|
465
|
-
|
|
466
592
|
end
|
data/tests/tc_curl_postfield.rb
CHANGED
|
@@ -2,63 +2,63 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
|
2
2
|
|
|
3
3
|
class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
4
4
|
def test_private_new
|
|
5
|
-
assert_raise(NoMethodError) { Curl::PostField.new }
|
|
5
|
+
assert_raise(NoMethodError) { Curl::PostField.new }
|
|
6
6
|
end
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
def test_new_content_01
|
|
9
9
|
pf = Curl::PostField.content('foo', 'bar')
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
assert_equal 'foo', pf.name
|
|
12
12
|
assert_equal 'bar', pf.content
|
|
13
13
|
assert_nil pf.content_type
|
|
14
14
|
assert_nil pf.local_file
|
|
15
|
-
assert_nil pf.remote_file
|
|
15
|
+
assert_nil pf.remote_file
|
|
16
16
|
assert_nil pf.set_content_proc
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def test_new_content_02
|
|
20
20
|
pf = Curl::PostField.content('foo', 'bar', 'text/html')
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
assert_equal 'foo', pf.name
|
|
23
23
|
assert_equal 'bar', pf.content
|
|
24
24
|
assert_equal 'text/html', pf.content_type
|
|
25
25
|
assert_nil pf.local_file
|
|
26
26
|
assert_nil pf.remote_file
|
|
27
|
-
assert_nil pf.set_content_proc
|
|
28
|
-
end
|
|
29
|
-
|
|
27
|
+
assert_nil pf.set_content_proc
|
|
28
|
+
end
|
|
29
|
+
|
|
30
30
|
def test_new_content_03
|
|
31
31
|
l = lambda { |field| "never gets run" }
|
|
32
32
|
pf = Curl::PostField.content('foo', &l)
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
assert_equal 'foo', pf.name
|
|
35
35
|
assert_nil pf.content
|
|
36
36
|
assert_nil pf.content_type
|
|
37
37
|
assert_nil pf.local_file
|
|
38
38
|
assert_nil pf.remote_file
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
# N.B. This doesn't just get the proc, but also removes it.
|
|
41
41
|
assert_equal l, pf.set_content_proc
|
|
42
|
-
end
|
|
42
|
+
end
|
|
43
43
|
|
|
44
44
|
def test_new_content_04
|
|
45
45
|
l = lambda { |field| "never gets run" }
|
|
46
46
|
pf = Curl::PostField.content('foo', 'text/html', &l)
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
assert_equal 'foo', pf.name
|
|
49
49
|
assert_nil pf.content
|
|
50
50
|
assert_equal 'text/html', pf.content_type
|
|
51
51
|
assert_nil pf.local_file
|
|
52
52
|
assert_nil pf.remote_file
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
# N.B. This doesn't just get the proc, but also removes it.
|
|
55
55
|
assert_equal l, pf.set_content_proc
|
|
56
|
-
end
|
|
56
|
+
end
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def test_new_file_01
|
|
60
60
|
pf = Curl::PostField.file('foo', 'localname')
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
assert_equal 'foo', pf.name
|
|
63
63
|
assert_equal 'localname', pf.local_file
|
|
64
64
|
assert_equal 'localname', pf.remote_file
|
|
@@ -67,44 +67,44 @@ class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
|
67
67
|
assert_nil pf.content
|
|
68
68
|
assert_nil pf.set_content_proc
|
|
69
69
|
end
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
def test_new_file_02
|
|
72
72
|
pf = Curl::PostField.file('foo', 'localname', 'remotename')
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
assert_equal 'foo', pf.name
|
|
75
75
|
assert_equal 'localname', pf.local_file
|
|
76
76
|
assert_equal 'remotename', pf.remote_file
|
|
77
77
|
assert_nil pf.content_type
|
|
78
78
|
assert_nil pf.content
|
|
79
79
|
assert_nil pf.set_content_proc
|
|
80
|
-
end
|
|
81
|
-
|
|
80
|
+
end
|
|
81
|
+
|
|
82
82
|
def test_new_file_03
|
|
83
83
|
l = lambda { |field| "never gets run" }
|
|
84
84
|
pf = Curl::PostField.file('foo', 'remotename', &l)
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
assert_equal 'foo', pf.name
|
|
87
87
|
assert_equal 'remotename', pf.remote_file
|
|
88
88
|
assert_nil pf.local_file
|
|
89
89
|
assert_nil pf.content_type
|
|
90
90
|
assert_nil pf.content
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
# N.B. This doesn't just get the proc, but also removes it.
|
|
93
93
|
assert_equal l, pf.set_content_proc
|
|
94
|
-
end
|
|
94
|
+
end
|
|
95
95
|
|
|
96
96
|
def test_new_file_04
|
|
97
97
|
assert_raise(ArgumentError) do
|
|
98
98
|
# no local name, no block
|
|
99
99
|
Curl::PostField.file('foo')
|
|
100
100
|
end
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
assert_raise(ArgumentError) do
|
|
103
103
|
# no remote name with block
|
|
104
104
|
Curl::PostField.file('foo') { |field| "never runs" }
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
def test_new_file_05
|
|
109
109
|
# local gets ignored when supplying a block, but remote
|
|
110
110
|
# is still set up properly.
|
|
@@ -118,15 +118,15 @@ class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
|
118
118
|
assert_nil pf.content
|
|
119
119
|
|
|
120
120
|
assert_equal l, pf.set_content_proc
|
|
121
|
-
end
|
|
122
|
-
|
|
121
|
+
end
|
|
122
|
+
|
|
123
123
|
def test_to_s_01
|
|
124
|
-
pf = Curl::PostField.content('foo', 'bar')
|
|
124
|
+
pf = Curl::PostField.content('foo', 'bar')
|
|
125
125
|
assert_equal "foo=bar", pf.to_s
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
def test_to_s_02
|
|
129
|
-
pf = Curl::PostField.content('foo', 'bar ton')
|
|
129
|
+
pf = Curl::PostField.content('foo', 'bar ton')
|
|
130
130
|
assert_equal "foo=bar%20ton", pf.to_s
|
|
131
131
|
end
|
|
132
132
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class TestCurbCurlProtocols < Test::Unit::TestCase
|
|
2
|
+
include TestServerMethods
|
|
3
|
+
|
|
4
|
+
def setup
|
|
5
|
+
@easy = Curl::Easy.new
|
|
6
|
+
@easy.set :protocols, Curl::CURLPROTO_HTTP | Curl::CURLPROTO_HTTPS
|
|
7
|
+
@easy.follow_location = true
|
|
8
|
+
server_setup
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_protocol_allowed
|
|
12
|
+
@easy.set :url, "http://127.0.0.1:9129/this_file_does_not_exist.html"
|
|
13
|
+
@easy.perform
|
|
14
|
+
assert_equal 404, @easy.response_code
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_protocol_denied
|
|
18
|
+
@easy.set :url, "gopher://google.com/"
|
|
19
|
+
assert_raises Curl::Err::UnsupportedProtocolError do
|
|
20
|
+
@easy.perform
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_redir_protocol_allowed
|
|
25
|
+
@easy.set :url, TestServlet.url + "/redirect"
|
|
26
|
+
@easy.set :redir_protocols, Curl::CURLPROTO_HTTP
|
|
27
|
+
@easy.perform
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_redir_protocol_denied
|
|
31
|
+
@easy.set :url, TestServlet.url + "/redirect"
|
|
32
|
+
@easy.set :redir_protocols, Curl::CURLPROTO_HTTPS
|
|
33
|
+
assert_raises Curl::Err::UnsupportedProtocolError do
|
|
34
|
+
@easy.perform
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/tests/timeout.rb
CHANGED
|
@@ -13,15 +13,27 @@ class TestCurbTimeouts < Test::Unit::TestCase
|
|
|
13
13
|
elapsed = Time.now - start
|
|
14
14
|
assert elapsed > 2
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
def test_overall_timeout_on_dead_transfer
|
|
18
18
|
curl = Curl::Easy.new(wait_url(2))
|
|
19
19
|
curl.timeout = 1
|
|
20
|
+
exception = assert_raise(Curl::Err::TimeoutError) do
|
|
21
|
+
curl.http_get
|
|
22
|
+
end
|
|
23
|
+
assert_match(
|
|
24
|
+
/^Timeout was reached: Operation timed out after/,
|
|
25
|
+
exception.message
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_overall_timeout_ms_on_dead_transfer
|
|
30
|
+
curl = Curl::Easy.new(wait_url(2))
|
|
31
|
+
curl.timeout_ms = 1000
|
|
20
32
|
assert_raise(Curl::Err::TimeoutError) do
|
|
21
33
|
curl.http_get
|
|
22
34
|
end
|
|
23
35
|
end
|
|
24
|
-
|
|
36
|
+
|
|
25
37
|
def test_clearing_timeout
|
|
26
38
|
curl = Curl::Easy.new(wait_url(2))
|
|
27
39
|
curl.timeout = 1
|
|
@@ -36,16 +48,20 @@ class TestCurbTimeouts < Test::Unit::TestCase
|
|
|
36
48
|
curl = Curl::Easy.new(serve_url(100, 2, 3))
|
|
37
49
|
curl.timeout = 1
|
|
38
50
|
# transfer is aborted despite data being exchanged
|
|
39
|
-
assert_raise(Curl::Err::TimeoutError) do
|
|
51
|
+
exception = assert_raise(Curl::Err::TimeoutError) do
|
|
40
52
|
curl.http_get
|
|
41
53
|
end
|
|
54
|
+
assert_match(
|
|
55
|
+
/^Timeout was reached: Operation timed out after/,
|
|
56
|
+
exception.message
|
|
57
|
+
)
|
|
42
58
|
end
|
|
43
59
|
|
|
44
60
|
def test_low_speed_time_on_slow_transfer
|
|
45
61
|
curl = Curl::Easy.new(serve_url(100, 1, 3))
|
|
46
62
|
curl.low_speed_time = 2
|
|
47
63
|
# use default low_speed_limit of 1
|
|
48
|
-
|
|
64
|
+
assert_equal true, curl.http_get
|
|
49
65
|
end
|
|
50
66
|
|
|
51
67
|
def test_low_speed_time_on_very_slow_transfer
|
|
@@ -55,18 +71,26 @@ class TestCurbTimeouts < Test::Unit::TestCase
|
|
|
55
71
|
# XXX for some reason this test fails if low speed limit is not specified
|
|
56
72
|
curl.low_speed_limit = 1
|
|
57
73
|
# use default low_speed_limit of 1
|
|
58
|
-
assert_raise(Curl::Err::TimeoutError) do
|
|
74
|
+
exception = assert_raise(Curl::Err::TimeoutError) do
|
|
59
75
|
curl.http_get
|
|
60
76
|
end
|
|
77
|
+
assert_match(
|
|
78
|
+
/^Timeout was reached: Operation too slow/,
|
|
79
|
+
exception.message
|
|
80
|
+
)
|
|
61
81
|
end
|
|
62
82
|
|
|
63
83
|
def test_low_speed_limit_on_slow_transfer
|
|
64
84
|
curl = Curl::Easy.new(serve_url(10, 1, 3))
|
|
65
85
|
curl.low_speed_time = 2
|
|
66
86
|
curl.low_speed_limit = 1000
|
|
67
|
-
assert_raise(Curl::Err::TimeoutError) do
|
|
87
|
+
exception = assert_raise(Curl::Err::TimeoutError) do
|
|
68
88
|
curl.http_get
|
|
69
89
|
end
|
|
90
|
+
assert_match(
|
|
91
|
+
/^Timeout was reached: Operation too slow/,
|
|
92
|
+
exception.message
|
|
93
|
+
)
|
|
70
94
|
end
|
|
71
95
|
|
|
72
96
|
def test_clearing_low_speed_time
|