curb 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +42 -6
- data/Rakefile +9 -7
- data/ext/curb.c +9 -1
- data/ext/curb.h +3 -3
- data/ext/curb_easy.c +55 -41
- data/ext/curb_macros.h +12 -0
- data/ext/curb_multi.c +50 -24
- data/ext/curb_postfield.c +9 -7
- data/ext/curb_upload.c +1 -0
- data/ext/extconf.rb +2 -0
- data/lib/curl/easy.rb +5 -5
- data/lib/curl/multi.rb +8 -1
- data/lib/curl.rb +11 -3
- data/tests/bug_crash_on_debug.rb +14 -28
- data/tests/bug_crash_on_progress.rb +7 -31
- data/tests/bug_curb_easy_blocks_ruby_threads.rb +8 -13
- data/tests/bug_curb_easy_post_with_string_no_content_length_header.rb +6 -30
- data/tests/bug_follow_redirect_288.rb +83 -0
- data/tests/bug_instance_post_differs_from_class_post.rb +3 -5
- data/tests/bug_issue277.rb +32 -0
- data/tests/bug_multi_segfault.rb +1 -0
- data/tests/bug_raise_on_callback.rb +29 -0
- data/tests/helper.rb +26 -0
- data/tests/tc_curl_easy.rb +12 -4
- data/tests/tc_curl_multi.rb +47 -7
- metadata +12 -6
data/tests/bug_multi_segfault.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# irb: multi = Curl::Multi.new
|
4
4
|
# irb: exit
|
5
5
|
# <main>:47140: [BUG] Bus Error
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
6
7
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','ext'))
|
7
8
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
8
9
|
require 'curb'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
class BugRaiseOnCallback < Test::Unit::TestCase
|
4
|
+
include BugTestServerSetupTeardown
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@port = 9999
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_on_complte
|
12
|
+
c = Curl::Easy.new('http://127.0.0.1:9999/test')
|
13
|
+
did_raise = false
|
14
|
+
begin
|
15
|
+
c.on_complete do|x|
|
16
|
+
assert_equal 'http://127.0.0.1:9999/test', x.url
|
17
|
+
raise "error complete" # this will get swallowed
|
18
|
+
end
|
19
|
+
c.perform
|
20
|
+
rescue => e
|
21
|
+
did_raise = true
|
22
|
+
end
|
23
|
+
assert did_raise, "we want to raise an exception if the ruby callbacks raise"
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
#test_on_debug
|
data/tests/helper.rb
CHANGED
@@ -135,6 +135,32 @@ class TestServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
135
135
|
|
136
136
|
end
|
137
137
|
|
138
|
+
module BugTestServerSetupTeardown
|
139
|
+
def setup
|
140
|
+
@port ||= 9992
|
141
|
+
@server = WEBrick::HTTPServer.new( :Port => @port )
|
142
|
+
@server.mount_proc("/test") do|req,res|
|
143
|
+
if @response_proc
|
144
|
+
@response_proc.call(res)
|
145
|
+
else
|
146
|
+
res.body = "hi"
|
147
|
+
res['Content-Type'] = "text/html"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
@thread = Thread.new(@server) do|srv|
|
152
|
+
srv.start
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def teardown
|
157
|
+
while @server.status != :Shutdown
|
158
|
+
@server.shutdown
|
159
|
+
end
|
160
|
+
@thread.join
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
138
164
|
module TestServerMethods
|
139
165
|
def locked_file
|
140
166
|
File.join(File.dirname(__FILE__),"server_lock-#{@__port}")
|
data/tests/tc_curl_easy.rb
CHANGED
@@ -10,6 +10,14 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
10
10
|
Curl.reset
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_nested_easy_methods
|
14
|
+
easy = Curl.get(TestServlet.url) {|http|
|
15
|
+
res = Curl.get(TestServlet.url + '/not_here')
|
16
|
+
assert_equal 404, res.code
|
17
|
+
}
|
18
|
+
assert_equal 200, easy.code
|
19
|
+
end
|
20
|
+
|
13
21
|
def test_curlopt_stderr_with_file
|
14
22
|
# does not work with Tempfile directly
|
15
23
|
path = Tempfile.new('curb_test_curlopt_stderr').path
|
@@ -713,9 +721,9 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
713
721
|
on_success_called = false
|
714
722
|
curl.on_success {|c|
|
715
723
|
on_success_called = true
|
716
|
-
assert_not_nil c.
|
717
|
-
|
718
|
-
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.
|
724
|
+
assert_not_nil c.body
|
725
|
+
assert_match(/Content-Length: /, c.head)
|
726
|
+
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
|
719
727
|
}
|
720
728
|
curl.perform
|
721
729
|
assert on_success_called, "Success handler not called"
|
@@ -1139,7 +1147,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
1139
1147
|
c = Curl::Easy.new($TEST_URL)
|
1140
1148
|
c.on_success {|x| raise "error" }
|
1141
1149
|
c.perform
|
1142
|
-
rescue => e
|
1150
|
+
rescue Curl::Err::AbortedByCallbackError => e
|
1143
1151
|
assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
|
1144
1152
|
c.close
|
1145
1153
|
end
|
data/tests/tc_curl_multi.rb
CHANGED
@@ -74,7 +74,9 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
74
74
|
assert did_complete
|
75
75
|
after_open = open_fds.call
|
76
76
|
#puts "after_open: #{after_open} before_open: #{before_open.inspect}"
|
77
|
-
|
77
|
+
# ruby process may keep a connection alive
|
78
|
+
assert (after_open - before_open) < 3, "with max connections set to 1 at this point the connection to google should still be open"
|
79
|
+
assert (after_open - before_open) > 0, "with max connections set to 1 at this point the connection to google should still be open"
|
78
80
|
multi.close
|
79
81
|
|
80
82
|
after_open = open_fds.call
|
@@ -159,6 +161,44 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
159
161
|
|
160
162
|
end
|
161
163
|
|
164
|
+
def test_multi_easy_get
|
165
|
+
n = 1
|
166
|
+
urls = []
|
167
|
+
n.times { urls << $TEST_URL }
|
168
|
+
Curl::Multi.get(urls, {timeout: 5}) {|easy|
|
169
|
+
assert_match(/file:/, easy.last_effective_url)
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_multi_easy_get_with_error
|
174
|
+
begin
|
175
|
+
did_raise = false
|
176
|
+
n = 3
|
177
|
+
urls = []
|
178
|
+
n.times { urls << $TEST_URL }
|
179
|
+
error_line_number_should_be = nil
|
180
|
+
Curl::Multi.get(urls, {timeout: 5}) {|easy|
|
181
|
+
# if we got this right the error will be reported to be on the line below our error_line_number_should_be
|
182
|
+
error_line_number_should_be = __LINE__
|
183
|
+
raise
|
184
|
+
}
|
185
|
+
|
186
|
+
rescue Curl::Err::AbortedByCallbackError => e
|
187
|
+
did_raise = true
|
188
|
+
in_file = e.backtrace.detect {|err| err.match?(File.basename(__FILE__)) }
|
189
|
+
in_file_stack = e.backtrace.select {|err| err.match?(File.basename(__FILE__)) }
|
190
|
+
assert_match(__FILE__, in_file)
|
191
|
+
in_file.gsub!(__FILE__)
|
192
|
+
parts = in_file.split(':')
|
193
|
+
parts.shift
|
194
|
+
line_no = parts.shift.to_i
|
195
|
+
assert_equal error_line_number_should_be+1, line_no.to_i
|
196
|
+
end
|
197
|
+
|
198
|
+
assert did_raise, "we should have raised an exception"
|
199
|
+
|
200
|
+
end
|
201
|
+
|
162
202
|
# NOTE: if this test runs slowly on Mac OSX, it is probably due to the use of a port install curl+ssl+ares install
|
163
203
|
# on my MacBook, this causes curl_easy_init to take nearly 0.01 seconds / * 100 below is 1 second too many!
|
164
204
|
def test_n_requests
|
@@ -480,7 +520,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
480
520
|
{ :url => TestServlet.url, :method => :get }
|
481
521
|
]
|
482
522
|
Curl::Multi.http(urls, {:pipeline => true}) do|easy, code, method|
|
483
|
-
assert_equal
|
523
|
+
assert_equal 200, code
|
484
524
|
case method
|
485
525
|
when :post
|
486
526
|
assert_match(/POST/, easy.body_str)
|
@@ -494,20 +534,20 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
494
534
|
end
|
495
535
|
|
496
536
|
def test_multi_easy_http_with_max_connects
|
497
|
-
|
537
|
+
urls = [
|
498
538
|
{ :url => TestServlet.url + '?q=1', :method => :get },
|
499
539
|
{ :url => TestServlet.url + '?q=2', :method => :get },
|
500
540
|
{ :url => TestServlet.url + '?q=3', :method => :get }
|
501
541
|
]
|
502
542
|
Curl::Multi.http(urls, {:pipeline => true, :max_connects => 1}) do|easy, code, method|
|
503
|
-
assert_equal
|
543
|
+
assert_equal 200, code
|
504
544
|
case method
|
505
545
|
when :post
|
506
|
-
assert_match(/POST/, easy.
|
546
|
+
assert_match(/POST/, easy.body)
|
507
547
|
when :get
|
508
|
-
assert_match(/GET/, easy.
|
548
|
+
assert_match(/GET/, easy.body)
|
509
549
|
when :put
|
510
|
-
assert_match(/PUT/, easy.
|
550
|
+
assert_match(/PUT/, easy.body)
|
511
551
|
end
|
512
552
|
end
|
513
553
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.5
|
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: 2023-01-04 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
|
@@ -50,11 +50,14 @@ files:
|
|
50
50
|
- tests/bug_crash_on_progress.rb
|
51
51
|
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
52
52
|
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
53
|
+
- tests/bug_follow_redirect_288.rb
|
53
54
|
- tests/bug_instance_post_differs_from_class_post.rb
|
54
55
|
- tests/bug_issue102.rb
|
56
|
+
- tests/bug_issue277.rb
|
55
57
|
- tests/bug_multi_segfault.rb
|
56
58
|
- tests/bug_postfields_crash.rb
|
57
59
|
- tests/bug_postfields_crash2.rb
|
60
|
+
- tests/bug_raise_on_callback.rb
|
58
61
|
- tests/bug_require_last_or_segfault.rb
|
59
62
|
- tests/bugtests.rb
|
60
63
|
- tests/helper.rb
|
@@ -77,7 +80,7 @@ homepage: https://github.com/taf2/curb
|
|
77
80
|
licenses:
|
78
81
|
- MIT
|
79
82
|
metadata: {}
|
80
|
-
post_install_message:
|
83
|
+
post_install_message:
|
81
84
|
rdoc_options:
|
82
85
|
- "--main"
|
83
86
|
- README.markdown
|
@@ -95,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
98
|
- !ruby/object:Gem::Version
|
96
99
|
version: '0'
|
97
100
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
101
|
+
rubygems_version: 3.2.33
|
102
|
+
signing_key:
|
100
103
|
specification_version: 4
|
101
104
|
summary: Ruby libcurl bindings
|
102
105
|
test_files:
|
@@ -105,11 +108,14 @@ test_files:
|
|
105
108
|
- tests/bug_crash_on_progress.rb
|
106
109
|
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
107
110
|
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
111
|
+
- tests/bug_follow_redirect_288.rb
|
108
112
|
- tests/bug_instance_post_differs_from_class_post.rb
|
109
113
|
- tests/bug_issue102.rb
|
114
|
+
- tests/bug_issue277.rb
|
110
115
|
- tests/bug_multi_segfault.rb
|
111
116
|
- tests/bug_postfields_crash.rb
|
112
117
|
- tests/bug_postfields_crash2.rb
|
118
|
+
- tests/bug_raise_on_callback.rb
|
113
119
|
- tests/bug_require_last_or_segfault.rb
|
114
120
|
- tests/bugtests.rb
|
115
121
|
- tests/helper.rb
|