curb 0.9.6 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.markdown +27 -7
- data/Rakefile +26 -10
- data/ext/banned.h +32 -0
- data/ext/curb.c +20 -0
- data/ext/curb.h +12 -4
- data/ext/curb_easy.c +250 -19
- data/ext/curb_easy.h +3 -0
- data/ext/curb_errors.c +7 -0
- data/ext/curb_multi.c +126 -161
- data/ext/curb_multi.h +0 -1
- data/ext/extconf.rb +12 -0
- data/lib/curb.rb +1 -0
- data/lib/curl.rb +5 -6
- data/lib/curl/easy.rb +7 -1
- data/lib/curl/multi.rb +42 -3
- data/tests/bug_issue277.rb +32 -0
- data/tests/helper.rb +80 -1
- data/tests/tc_curl.rb +30 -0
- data/tests/tc_curl_easy.rb +110 -16
- data/tests/tc_curl_maxfilesize.rb +12 -0
- data/tests/tc_curl_multi.rb +68 -5
- data/tests/tc_curl_postfield.rb +29 -29
- metadata +12 -8
@@ -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|
|
@@ -484,5 +548,4 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
484
548
|
def setup
|
485
549
|
server_setup
|
486
550
|
end
|
487
|
-
|
488
551
|
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
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ross Bamford
|
8
8
|
- Todd A. Fisher
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings
|
15
15
|
for the libcurl(3), a fully-featured client-side URL transfer library. cURL and
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- README.markdown
|
27
27
|
- Rakefile
|
28
28
|
- doc.rb
|
29
|
+
- ext/banned.h
|
29
30
|
- ext/curb.c
|
30
31
|
- ext/curb.h
|
31
32
|
- ext/curb_easy.c
|
@@ -51,6 +52,7 @@ files:
|
|
51
52
|
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
52
53
|
- tests/bug_instance_post_differs_from_class_post.rb
|
53
54
|
- tests/bug_issue102.rb
|
55
|
+
- tests/bug_issue277.rb
|
54
56
|
- tests/bug_multi_segfault.rb
|
55
57
|
- tests/bug_postfields_crash.rb
|
56
58
|
- tests/bug_postfields_crash2.rb
|
@@ -65,16 +67,17 @@ files:
|
|
65
67
|
- tests/tc_curl_easy.rb
|
66
68
|
- tests/tc_curl_easy_resolve.rb
|
67
69
|
- tests/tc_curl_easy_setopt.rb
|
70
|
+
- tests/tc_curl_maxfilesize.rb
|
68
71
|
- tests/tc_curl_multi.rb
|
69
72
|
- tests/tc_curl_postfield.rb
|
70
73
|
- tests/timeout.rb
|
71
74
|
- tests/timeout_server.rb
|
72
75
|
- tests/unittests.rb
|
73
|
-
homepage:
|
76
|
+
homepage: https://github.com/taf2/curb
|
74
77
|
licenses:
|
75
78
|
- MIT
|
76
79
|
metadata: {}
|
77
|
-
post_install_message:
|
80
|
+
post_install_message:
|
78
81
|
rdoc_options:
|
79
82
|
- "--main"
|
80
83
|
- README.markdown
|
@@ -92,9 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: '0'
|
94
97
|
requirements: []
|
95
|
-
|
96
|
-
|
97
|
-
signing_key:
|
98
|
+
rubygems_version: 3.0.8
|
99
|
+
signing_key:
|
98
100
|
specification_version: 4
|
99
101
|
summary: Ruby libcurl bindings
|
100
102
|
test_files:
|
@@ -105,6 +107,7 @@ test_files:
|
|
105
107
|
- tests/bug_postfields_crash.rb
|
106
108
|
- tests/bug_crash_on_progress.rb
|
107
109
|
- tests/helper.rb
|
110
|
+
- tests/bug_issue277.rb
|
108
111
|
- tests/bug_postfields_crash2.rb
|
109
112
|
- tests/bug_require_last_or_segfault.rb
|
110
113
|
- tests/timeout.rb
|
@@ -120,6 +123,7 @@ test_files:
|
|
120
123
|
- tests/tc_curl_easy.rb
|
121
124
|
- tests/mem_check.rb
|
122
125
|
- tests/tc_curl_postfield.rb
|
126
|
+
- tests/tc_curl_maxfilesize.rb
|
123
127
|
- tests/bugtests.rb
|
124
128
|
- tests/tc_curl_easy_resolve.rb
|
125
129
|
- tests/signals.rb
|