curb 0.9.11 → 1.0.5
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 +4 -4
- data/README.markdown +48 -6
- data/Rakefile +17 -18
- data/ext/curb.c +154 -8
- data/ext/curb.h +10 -5
- data/ext/curb_easy.c +100 -44
- data/ext/curb_easy.h +3 -0
- 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 +38 -0
- data/lib/curl/easy.rb +8 -7
- 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_multi_segfault.rb +1 -0
- data/tests/bug_raise_on_callback.rb +29 -0
- data/tests/helper.rb +26 -1
- data/tests/tc_curl_easy.rb +13 -5
- data/tests/tc_curl_multi.rb +98 -17
- data/tests/tc_curl_protocols.rb +37 -0
- data/tests/timeout.rb +21 -5
- metadata +28 -22
data/ext/curb_postfield.c
CHANGED
@@ -195,9 +195,9 @@ void curl_postfield_free(ruby_curl_postfield *rbcpf) {
|
|
195
195
|
|
196
196
|
/*
|
197
197
|
* call-seq:
|
198
|
-
* Curl::PostField.content(name, content) =>
|
199
|
-
* Curl::PostField.content(name, content, content_type = nil) =>
|
200
|
-
* Curl::PostField.content(name, content_type = nil) { |field| ... } =>
|
198
|
+
* Curl::PostField.content(name, content) => #<Curl::PostField...>
|
199
|
+
* Curl::PostField.content(name, content, content_type = nil) => #<Curl::PostField...>
|
200
|
+
* Curl::PostField.content(name, content_type = nil) { |field| ... } => #<Curl::PostField...>
|
201
201
|
*
|
202
202
|
* Create a new Curl::PostField, supplying the field name, content,
|
203
203
|
* and, optionally, Content-type (curl will attempt to determine this if
|
@@ -241,9 +241,9 @@ static VALUE ruby_curl_postfield_new_content(int argc, VALUE *argv, VALUE klass)
|
|
241
241
|
|
242
242
|
/*
|
243
243
|
* call-seq:
|
244
|
-
* Curl::PostField.file(name, local_file_name) =>
|
245
|
-
* Curl::PostField.file(name, local_file_name, remote_file_name = local_file_name) =>
|
246
|
-
* Curl::PostField.file(name, remote_file_name) { |field| ... } =>
|
244
|
+
* Curl::PostField.file(name, local_file_name) => #<Curl::PostField...>
|
245
|
+
* Curl::PostField.file(name, local_file_name, remote_file_name = local_file_name) => #<Curl::PostField...>
|
246
|
+
* Curl::PostField.file(name, remote_file_name) { |field| ... } => #<Curl::PostField...>
|
247
247
|
*
|
248
248
|
* Create a new Curl::PostField for a file upload field, supplying the local filename
|
249
249
|
* to read from, and optionally the remote filename (defaults to the local name).
|
@@ -399,7 +399,7 @@ static VALUE ruby_curl_postfield_remote_file_get(VALUE self) {
|
|
399
399
|
|
400
400
|
/*
|
401
401
|
* call-seq:
|
402
|
-
* field.set_content_proc { |field| ... } =>
|
402
|
+
* field.set_content_proc { |field| ... } => <old proc>
|
403
403
|
*
|
404
404
|
* Set a content proc for this field. This proc will be called during the
|
405
405
|
* perform to supply the content for this field, overriding any setting
|
@@ -498,6 +498,8 @@ void init_curb_postfield() {
|
|
498
498
|
|
499
499
|
cCurlPostField = rb_define_class_under(mCurl, "PostField", rb_cObject);
|
500
500
|
|
501
|
+
rb_undef_alloc_func(cCurlPostField);
|
502
|
+
|
501
503
|
/* Class methods */
|
502
504
|
rb_define_singleton_method(cCurlPostField, "content", ruby_curl_postfield_new_content, -1);
|
503
505
|
rb_define_singleton_method(cCurlPostField, "file", ruby_curl_postfield_new_file, -1);
|
data/ext/curb_upload.c
CHANGED
@@ -72,6 +72,7 @@ VALUE ruby_curl_upload_offset_get(VALUE self) {
|
|
72
72
|
/* =================== INIT LIB =====================*/
|
73
73
|
void init_curb_upload() {
|
74
74
|
cCurlUpload = rb_define_class_under(mCurl, "Upload", rb_cObject);
|
75
|
+
rb_undef_alloc_func(cCurlUpload);
|
75
76
|
rb_define_singleton_method(cCurlUpload, "new", ruby_curl_upload_new, 0);
|
76
77
|
rb_define_method(cCurlUpload, "stream=", ruby_curl_upload_stream_set, 1);
|
77
78
|
rb_define_method(cCurlUpload, "stream", ruby_curl_upload_stream_get, 0);
|
data/ext/extconf.rb
CHANGED
@@ -18,6 +18,8 @@ elsif !have_library('curl') or !have_header('curl/curl.h')
|
|
18
18
|
fail <<-EOM
|
19
19
|
Can't find libcurl or curl/curl.h
|
20
20
|
|
21
|
+
Make sure development libs (ie libcurl4-openssl-dev) are installed on the system.
|
22
|
+
|
21
23
|
Try passing --with-curl-dir or --with-curl-lib and --with-curl-include
|
22
24
|
options to extconf.
|
23
25
|
EOM
|
@@ -341,6 +343,9 @@ have_constant :CURL_SSLVERSION_TLSv1_0
|
|
341
343
|
have_constant :CURL_SSLVERSION_TLSv1_1
|
342
344
|
have_constant :CURL_SSLVERSION_TLSv1_2
|
343
345
|
|
346
|
+
# Added in 7.52.0
|
347
|
+
have_constant :CURL_SSLVERSION_TLSv1_3
|
348
|
+
|
344
349
|
have_constant "curlopt_ssl_verifypeer"
|
345
350
|
have_constant "curlopt_cainfo"
|
346
351
|
have_constant "curlopt_issuercert"
|
@@ -400,6 +405,39 @@ have_constant "curlopt_path_as_is"
|
|
400
405
|
# added in 7.43.0
|
401
406
|
have_constant "curlopt_pipewait"
|
402
407
|
|
408
|
+
have_constant "curlopt_proxy_ssl_verifyhost"
|
409
|
+
|
410
|
+
# protocol constants
|
411
|
+
have_constant "curlproto_all"
|
412
|
+
have_constant "curlproto_dict"
|
413
|
+
have_constant "curlproto_file"
|
414
|
+
have_constant "curlproto_ftp"
|
415
|
+
have_constant "curlproto_ftps"
|
416
|
+
have_constant "curlproto_gopher"
|
417
|
+
have_constant "curlproto_http"
|
418
|
+
have_constant "curlproto_https"
|
419
|
+
have_constant "curlproto_imap"
|
420
|
+
have_constant "curlproto_imaps"
|
421
|
+
have_constant "curlproto_ldap"
|
422
|
+
have_constant "curlproto_ldaps"
|
423
|
+
have_constant "curlproto_pop3"
|
424
|
+
have_constant "curlproto_pop3s"
|
425
|
+
have_constant "curlproto_rtmp"
|
426
|
+
have_constant "curlproto_rtmpe"
|
427
|
+
have_constant "curlproto_rtmps"
|
428
|
+
have_constant "curlproto_rtmpt"
|
429
|
+
have_constant "curlproto_rtmpte"
|
430
|
+
have_constant "curlproto_rtmpts"
|
431
|
+
have_constant "curlproto_rtsp"
|
432
|
+
have_constant "curlproto_scp"
|
433
|
+
have_constant "curlproto_sftp"
|
434
|
+
have_constant "curlproto_smb"
|
435
|
+
have_constant "curlproto_smbs"
|
436
|
+
have_constant "curlproto_smtp"
|
437
|
+
have_constant "curlproto_smtps"
|
438
|
+
have_constant "curlproto_telnet"
|
439
|
+
have_constant "curlproto_tftp"
|
440
|
+
|
403
441
|
if try_compile('int main() { return 0; }','-Wall')
|
404
442
|
$CFLAGS << ' -Wall'
|
405
443
|
end
|
data/lib/curl/easy.rb
CHANGED
@@ -21,7 +21,7 @@ module Curl
|
|
21
21
|
#
|
22
22
|
def status
|
23
23
|
# Matches the last HTTP Status - following the HTTP protocol specification 'Status-Line = HTTP-Version SP Status-Code SP (Opt:)Reason-Phrase CRLF'
|
24
|
-
statuses = self.header_str.scan(/HTTP\/\d(\.\d)?\s(\d+\s.*)\r\n/).map{
|
24
|
+
statuses = self.header_str.to_s.scan(/HTTP\/\d(\.\d)?\s(\d+\s.*)\r\n/).map {|match| match[1] }
|
25
25
|
statuses.last.strip if statuses.length > 0
|
26
26
|
end
|
27
27
|
|
@@ -75,8 +75,9 @@ module Curl
|
|
75
75
|
end
|
76
76
|
|
77
77
|
if self.last_result != 0 && self.on_failure.nil?
|
78
|
-
|
79
|
-
|
78
|
+
(err_class, err_summary) = Curl::Easy.error(self.last_result)
|
79
|
+
err_detail = self.last_error
|
80
|
+
raise err_class.new([err_summary, err_detail].compact.join(": "))
|
80
81
|
end
|
81
82
|
|
82
83
|
ret
|
@@ -320,7 +321,7 @@ module Curl
|
|
320
321
|
|
321
322
|
#
|
322
323
|
# call-seq:
|
323
|
-
# Curl::Easy.perform(url) { |easy| ... } =>
|
324
|
+
# Curl::Easy.perform(url) { |easy| ... } => #<Curl::Easy...>
|
324
325
|
#
|
325
326
|
# Convenience method that creates a new Curl::Easy instance with
|
326
327
|
# the specified URL and calls the general +perform+ method, before returning
|
@@ -338,7 +339,7 @@ module Curl
|
|
338
339
|
|
339
340
|
#
|
340
341
|
# call-seq:
|
341
|
-
# Curl::Easy.http_get(url) { |easy| ... } =>
|
342
|
+
# Curl::Easy.http_get(url) { |easy| ... } => #<Curl::Easy...>
|
342
343
|
#
|
343
344
|
# Convenience method that creates a new Curl::Easy instance with
|
344
345
|
# the specified URL and calls +http_get+, before returning the new instance.
|
@@ -355,7 +356,7 @@ module Curl
|
|
355
356
|
|
356
357
|
#
|
357
358
|
# call-seq:
|
358
|
-
# Curl::Easy.http_head(url) { |easy| ... } =>
|
359
|
+
# Curl::Easy.http_head(url) { |easy| ... } => #<Curl::Easy...>
|
359
360
|
#
|
360
361
|
# Convenience method that creates a new Curl::Easy instance with
|
361
362
|
# the specified URL and calls +http_head+, before returning the new instance.
|
@@ -409,7 +410,7 @@ module Curl
|
|
409
410
|
|
410
411
|
#
|
411
412
|
# call-seq:
|
412
|
-
# Curl::Easy.http_delete(url) { |easy| ... } =>
|
413
|
+
# Curl::Easy.http_delete(url) { |easy| ... } => #<Curl::Easy...>
|
413
414
|
#
|
414
415
|
# Convenience method that creates a new Curl::Easy instance with
|
415
416
|
# the specified URL and calls +http_delete+, before returning the new instance.
|
data/lib/curl/multi.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Curl
|
3
3
|
class Multi
|
4
|
+
class DownloadError < RuntimeError
|
5
|
+
attr_accessor :errors
|
6
|
+
end
|
4
7
|
class << self
|
5
8
|
# call-seq:
|
6
9
|
# Curl::Multi.get(['url1','url2','url3','url4','url5'], :follow_location => true) do|easy|
|
@@ -241,7 +244,11 @@ module Curl
|
|
241
244
|
errors << e
|
242
245
|
end
|
243
246
|
}
|
244
|
-
|
247
|
+
if errors.any?
|
248
|
+
de = Curl::Multi::DownloadError.new
|
249
|
+
de.errors = errors
|
250
|
+
raise de
|
251
|
+
end
|
245
252
|
end
|
246
253
|
end
|
247
254
|
|
data/lib/curl.rb
CHANGED
@@ -9,12 +9,20 @@ require 'cgi'
|
|
9
9
|
module Curl
|
10
10
|
|
11
11
|
def self.http(verb, url, post_body=nil, put_data=nil, &block)
|
12
|
-
|
13
|
-
|
12
|
+
if Thread.current[:curb_curl_yielding]
|
13
|
+
handle = Curl::Easy.new # we can't reuse this
|
14
|
+
else
|
15
|
+
handle = Thread.current[:curb_curl] ||= Curl::Easy.new
|
16
|
+
handle.reset
|
17
|
+
end
|
14
18
|
handle.url = url
|
15
19
|
handle.post_body = post_body if post_body
|
16
20
|
handle.put_data = put_data if put_data
|
17
|
-
|
21
|
+
if block_given?
|
22
|
+
Thread.current[:curb_curl_yielding] = true
|
23
|
+
yield handle
|
24
|
+
Thread.current[:curb_curl_yielding] = false
|
25
|
+
end
|
18
26
|
handle.http(verb)
|
19
27
|
handle
|
20
28
|
end
|
data/tests/bug_crash_on_debug.rb
CHANGED
@@ -1,37 +1,23 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
2
|
|
3
|
-
require 'webrick'
|
4
|
-
class ::WEBrick::HTTPServer ; def access_log(config, req, res) ; end ; end
|
5
|
-
class ::WEBrick::BasicLog ; def log(level, data) ; end ; end
|
6
|
-
|
7
|
-
require 'curl'
|
8
|
-
|
9
3
|
class BugCrashOnDebug < Test::Unit::TestCase
|
4
|
+
include BugTestServerSetupTeardown
|
10
5
|
|
11
6
|
def test_on_debug
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
c.on_debug do|x|
|
24
|
-
puts x.inspect
|
25
|
-
raise "error" # this will get swallowed
|
7
|
+
c = Curl::Easy.new("http://127.0.0.1:#{@port}/test")
|
8
|
+
did_raise = false
|
9
|
+
did_call = false
|
10
|
+
begin
|
11
|
+
c.on_success do|x|
|
12
|
+
did_call = true
|
13
|
+
raise "error" # this will get swallowed
|
14
|
+
end
|
15
|
+
c.perform
|
16
|
+
rescue => e
|
17
|
+
did_raise = true
|
26
18
|
end
|
27
|
-
|
28
|
-
|
29
|
-
ensure
|
30
|
-
puts 'd'
|
31
|
-
server.shutdown
|
32
|
-
puts 'e'
|
33
|
-
puts thread.exit
|
34
|
-
puts 'f'
|
19
|
+
assert did_raise
|
20
|
+
assert did_call
|
35
21
|
end
|
36
22
|
|
37
23
|
end
|
@@ -1,22 +1,10 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
-
require 'webrick'
|
3
|
-
class ::WEBrick::HTTPServer ; def access_log(config, req, res) ; end ; end
|
4
|
-
class ::WEBrick::BasicLog ; def log(level, data) ; end ; end
|
5
2
|
|
6
3
|
class BugCrashOnDebug < Test::Unit::TestCase
|
7
|
-
|
8
|
-
def test_on_progress_raise
|
9
|
-
server = WEBrick::HTTPServer.new( :Port => 9999 )
|
10
|
-
server.mount_proc("/test") do|req,res|
|
11
|
-
res.body = "hi"
|
12
|
-
res['Content-Type'] = "text/html"
|
13
|
-
end
|
4
|
+
include BugTestServerSetupTeardown
|
14
5
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
c = Curl::Easy.new('http://127.0.0.1:9999/test')
|
6
|
+
def test_on_progress_raise
|
7
|
+
c = Curl::Easy.new("http://127.0.0.1:#{@port}/test")
|
20
8
|
c.on_progress do|x|
|
21
9
|
raise "error"
|
22
10
|
end
|
@@ -27,21 +15,9 @@ class BugCrashOnDebug < Test::Unit::TestCase
|
|
27
15
|
rescue => e
|
28
16
|
assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
|
29
17
|
c.close
|
30
|
-
ensure
|
31
|
-
server.shutdown
|
32
18
|
end
|
33
19
|
|
34
20
|
def test_on_progress_abort
|
35
|
-
server = WEBrick::HTTPServer.new( :Port => 9999 )
|
36
|
-
server.mount_proc("/test") do|req,res|
|
37
|
-
res.body = "hi"
|
38
|
-
res['Content-Type'] = "text/html"
|
39
|
-
end
|
40
|
-
|
41
|
-
thread = Thread.new(server) do|srv|
|
42
|
-
srv.start
|
43
|
-
end
|
44
|
-
|
45
21
|
# see: https://github.com/taf2/curb/issues/192,
|
46
22
|
# to pass:
|
47
23
|
#
|
@@ -54,20 +30,20 @@ class BugCrashOnDebug < Test::Unit::TestCase
|
|
54
30
|
#
|
55
31
|
# notice no return keyword
|
56
32
|
#
|
57
|
-
c = Curl::Easy.new(
|
33
|
+
c = Curl::Easy.new("http://127.0.0.1:#{@port}/test")
|
34
|
+
did_progress = false
|
58
35
|
c.on_progress do|x|
|
59
|
-
|
36
|
+
did_progress = true
|
60
37
|
return false
|
61
38
|
end
|
62
39
|
c.perform
|
40
|
+
assert did_progress
|
63
41
|
|
64
42
|
assert false, "should not reach this point"
|
65
43
|
|
66
44
|
rescue => e
|
67
45
|
assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
|
68
46
|
c.close
|
69
|
-
ensure
|
70
|
-
server.shutdown
|
71
47
|
end
|
72
48
|
|
73
49
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
-
require 'webrick'
|
3
|
-
class ::WEBrick::HTTPServer ; def access_log(config, req, res) ; end ; end
|
4
|
-
class ::WEBrick::BasicLog ; def log(level, data) ; end ; end
|
5
2
|
|
6
3
|
class BugTestInstancePostDiffersFromClassPost < Test::Unit::TestCase
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
include BugTestServerSetupTeardown
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@port = 9999
|
8
|
+
@response_proc = lambda do|res|
|
10
9
|
sleep 0.5
|
11
10
|
res.body = "hi"
|
12
11
|
res['Content-Type'] = "text/html"
|
13
12
|
end
|
13
|
+
super
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
srv.start
|
17
|
-
end
|
18
|
-
|
16
|
+
def test_bug
|
19
17
|
threads = []
|
20
18
|
timer = Time.now
|
21
19
|
|
@@ -45,8 +43,5 @@ class BugTestInstancePostDiffersFromClassPost < Test::Unit::TestCase
|
|
45
43
|
puts "requested in #{single_time}"
|
46
44
|
|
47
45
|
assert single_time > multi_time
|
48
|
-
|
49
|
-
server.shutdown
|
50
|
-
thread.join
|
51
46
|
end
|
52
47
|
end
|
@@ -22,26 +22,15 @@ end
|
|
22
22
|
Any insight you care to share would be helpful. Thanks.
|
23
23
|
=end
|
24
24
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
25
|
-
require 'webrick'
|
26
|
-
class ::WEBrick::HTTPServer ; def access_log(config, req, res) ; end ; end
|
27
|
-
class ::WEBrick::BasicLog ; def log(level, data) ; end ; end
|
28
25
|
|
29
26
|
class BugCurbEasyPostWithStringNoContentLengthHeader < Test::Unit::TestCase
|
30
|
-
|
31
|
-
server = WEBrick::HTTPServer.new( :Port => 9999 )
|
32
|
-
server.mount_proc("/test") do|req,res|
|
33
|
-
assert_equal '15', req['Content-Length']
|
34
|
-
res.body = "hi"
|
35
|
-
res['Content-Type'] = "text/html"
|
36
|
-
end
|
27
|
+
include BugTestServerSetupTeardown
|
37
28
|
|
38
|
-
|
39
|
-
srv.start
|
40
|
-
end
|
29
|
+
def test_bug_workaround
|
41
30
|
params = {:cat => "hat", :foo => "bar"}
|
42
31
|
|
43
32
|
post_body = params.map{|f,k| "#{Curl::Easy.new.escape(f)}=#{Curl::Easy.new.escape(k)}"}.join('&')
|
44
|
-
c = Curl::Easy.http_post("http://127.0.0.1
|
33
|
+
c = Curl::Easy.http_post("http://127.0.0.1:#{@port}/test",post_body) do |curl|
|
45
34
|
curl.headers["User-Agent"] = "Curl/Ruby"
|
46
35
|
curl.headers["X-Tender-Auth"] = "A Token"
|
47
36
|
curl.headers["Accept"] = "application/vnd.tender-v1+json"
|
@@ -50,23 +39,12 @@ class BugCurbEasyPostWithStringNoContentLengthHeader < Test::Unit::TestCase
|
|
50
39
|
curl.enable_cookies = true
|
51
40
|
end
|
52
41
|
|
53
|
-
server.shutdown
|
54
|
-
thread.join
|
55
42
|
end
|
56
|
-
def test_bug
|
57
|
-
server = WEBrick::HTTPServer.new( :Port => 9999 )
|
58
|
-
server.mount_proc("/test") do|req,res|
|
59
|
-
assert_equal '15', req['Content-Length']
|
60
|
-
res.body = "hi"
|
61
|
-
res['Content-Type'] = "text/html"
|
62
|
-
end
|
63
43
|
|
64
|
-
|
65
|
-
srv.start
|
66
|
-
end
|
44
|
+
def test_bug
|
67
45
|
params = {:cat => "hat", :foo => "bar"}
|
68
46
|
|
69
|
-
c = Curl::Easy.http_post("http://127.0.0.1
|
47
|
+
c = Curl::Easy.http_post("http://127.0.0.1:#{@port}/test") do |curl|
|
70
48
|
curl.headers["User-Agent"] = "Curl/Ruby"
|
71
49
|
curl.headers["X-Tender-Auth"] = "A Token"
|
72
50
|
curl.headers["Accept"] = "application/vnd.tender-v1+json"
|
@@ -76,8 +54,6 @@ class BugCurbEasyPostWithStringNoContentLengthHeader < Test::Unit::TestCase
|
|
76
54
|
curl.follow_location = true
|
77
55
|
curl.enable_cookies = true
|
78
56
|
end
|
79
|
-
|
80
|
-
server.shutdown
|
81
|
-
thread.join
|
82
57
|
end
|
58
|
+
|
83
59
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
class BugFollowRedirect288 < Test::Unit::TestCase
|
4
|
+
include BugTestServerSetupTeardown
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@port = 9999
|
8
|
+
super
|
9
|
+
@server.mount_proc("/redirect_to_test") do|req,res|
|
10
|
+
res.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect, "/test")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_follow_redirect_with_no_redirect
|
15
|
+
|
16
|
+
c = Curl::Easy.new('http://127.0.0.1:9999/test')
|
17
|
+
did_call_redirect = false
|
18
|
+
c.on_redirect do|x|
|
19
|
+
did_call_redirect = true
|
20
|
+
end
|
21
|
+
c.perform
|
22
|
+
|
23
|
+
assert !did_call_redirect, "should reach this point redirect should not have been called"
|
24
|
+
|
25
|
+
c = Curl::Easy.new('http://127.0.0.1:9999/test')
|
26
|
+
did_call_redirect = false
|
27
|
+
c.on_redirect do|x|
|
28
|
+
did_call_redirect = true
|
29
|
+
end
|
30
|
+
c.follow_location = true
|
31
|
+
c.perform
|
32
|
+
|
33
|
+
assert_equal 0, c.redirect_count
|
34
|
+
assert !did_call_redirect, "should reach this point redirect should not have been called"
|
35
|
+
|
36
|
+
c = Curl::Easy.new('http://127.0.0.1:9999/redirect_to_test')
|
37
|
+
did_call_redirect = false
|
38
|
+
c.on_redirect do|x|
|
39
|
+
did_call_redirect = true
|
40
|
+
end
|
41
|
+
c.perform
|
42
|
+
assert_equal 307, c.response_code
|
43
|
+
|
44
|
+
assert did_call_redirect, "we should have called on_redirect"
|
45
|
+
|
46
|
+
c = Curl::Easy.new('http://127.0.0.1:9999/redirect_to_test')
|
47
|
+
did_call_redirect = false
|
48
|
+
c.follow_location = true
|
49
|
+
# NOTE: while this API is not supported by libcurl e.g. there is no redirect function callback in libcurl we could
|
50
|
+
# add support in ruby for this by executing this callback if redirect_count is greater than 0 at the end of a request in curb_multi.c
|
51
|
+
c.on_redirect do|x|
|
52
|
+
did_call_redirect = true
|
53
|
+
end
|
54
|
+
c.perform
|
55
|
+
assert_equal 1, c.redirect_count
|
56
|
+
assert_equal 200, c.response_code
|
57
|
+
|
58
|
+
assert did_call_redirect, "we should have called on_redirect"
|
59
|
+
|
60
|
+
c.url = 'http://127.0.0.1:9999/test'
|
61
|
+
c.perform
|
62
|
+
assert_equal 0, c.redirect_count
|
63
|
+
assert_equal 200, c.response_code
|
64
|
+
|
65
|
+
puts "checking for raise support"
|
66
|
+
did_raise = false
|
67
|
+
begin
|
68
|
+
c = Curl::Easy.new('http://127.0.0.1:9999/redirect_to_test')
|
69
|
+
did_call_redirect = false
|
70
|
+
c.on_redirect do|x|
|
71
|
+
raise "raise"
|
72
|
+
did_call_redirect = true
|
73
|
+
end
|
74
|
+
c.perform
|
75
|
+
rescue => e
|
76
|
+
did_raise = true
|
77
|
+
end
|
78
|
+
assert_equal 307, c.response_code
|
79
|
+
assert did_raise
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -35,15 +35,13 @@ class BugTestInstancePostDiffersFromClassPost < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def do_test
|
38
|
-
c = Curl::Easy.http_post('https://www.google.com/accounts/ServiceLoginAuth',
|
39
|
-
Curl::PostField.content('ltmpl','m_blanco'))
|
38
|
+
c = Curl::Easy.http_post('https://www.google.com/accounts/ServiceLoginAuth', Curl::PostField.content('ltmpl','m_blanco'))
|
40
39
|
body_c, header_c = c.body_str, c.header_str
|
41
40
|
|
42
41
|
sleep 2
|
43
42
|
|
44
|
-
c.http_post('https://www.google.com/accounts/ServiceLoginAuth',
|
45
|
-
|
46
|
-
body_i, header_i = c.body_str, c.header_str
|
43
|
+
c.http_post('https://www.google.com/accounts/ServiceLoginAuth', Curl::PostField.content('ltmpl','m_blanco'))
|
44
|
+
body_i, header_i = c.body, c.head
|
47
45
|
|
48
46
|
# timestamps will differ, just check first bit. We wont get here if
|
49
47
|
# the bug bites anyway...
|
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}")
|
@@ -143,7 +169,6 @@ module TestServerMethods
|
|
143
169
|
def server_setup(port=9129,servlet=TestServlet)
|
144
170
|
@__port = port
|
145
171
|
if (@server ||= nil).nil? and !File.exist?(locked_file)
|
146
|
-
|
147
172
|
File.open(locked_file,'w') {|f| f << 'locked' }
|
148
173
|
if TEST_SINGLE_THREADED
|
149
174
|
rd, wr = IO.pipe
|
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
|
@@ -21,7 +29,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
21
29
|
end
|
22
30
|
output = File.read(path)
|
23
31
|
|
24
|
-
assert_match(
|
32
|
+
assert_match(/HTTP\/1\.1\ 200\ OK(?:\ )?/, output)
|
25
33
|
assert_match('Host: 127.0.0.1:9129', output)
|
26
34
|
end
|
27
35
|
|
@@ -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
|