curb 0.8.5 → 1.3.6
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.md +579 -0
- data/Rakefile +85 -27
- data/doc.rb +48 -8
- data/ext/banned.h +32 -0
- data/ext/curb.c +563 -233
- data/ext/curb.h +19 -10
- data/ext/curb_easy.c +3229 -368
- data/ext/curb_easy.h +42 -0
- data/ext/curb_errors.c +117 -18
- data/ext/curb_errors.h +9 -5
- data/ext/curb_macros.h +33 -21
- data/ext/curb_multi.c +1904 -272
- data/ext/curb_multi.h +11 -3
- data/ext/curb_postfield.c +149 -77
- data/ext/curb_postfield.h +1 -0
- data/ext/curb_upload.c +38 -11
- data/ext/curb_upload.h +2 -0
- data/ext/extconf.rb +355 -35
- data/lib/curb.rb +1 -0
- data/lib/curl/download.rb +160 -0
- data/lib/curl/easy.rb +422 -88
- data/lib/curl/multi.rb +295 -56
- data/lib/curl.rb +676 -11
- data/tests/bug_crash_on_debug.rb +14 -28
- data/tests/bug_crash_on_progress.rb +32 -16
- data/tests/bug_curb_easy_blocks_ruby_threads.rb +10 -15
- 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_issue102.rb +17 -0
- data/tests/bug_issue_noproxy.rb +56 -0
- data/tests/bug_issue_post_redirect.rb +93 -0
- data/tests/bug_issue_spnego.rb +41 -0
- data/tests/bug_multi_segfault.rb +1 -0
- data/tests/bug_poison.rb +29 -0
- data/tests/bug_raise_on_callback.rb +30 -0
- data/tests/helper.rb +400 -44
- data/tests/leak_trace.rb +237 -0
- data/tests/mem_check.rb +3 -0
- data/tests/tc_curl.rb +31 -1
- data/tests/tc_curl_download.rb +98 -7
- data/tests/tc_curl_easy.rb +985 -66
- data/tests/tc_curl_easy_cookielist.rb +277 -0
- data/tests/tc_curl_easy_request_target.rb +41 -0
- data/tests/tc_curl_easy_resolve.rb +48 -0
- data/tests/tc_curl_maxfilesize.rb +212 -0
- data/tests/tc_curl_multi.rb +1111 -51
- data/tests/tc_curl_native_coverage.rb +145 -0
- data/tests/tc_curl_network_policy.rb +1475 -0
- data/tests/tc_curl_postfield.rb +207 -30
- data/tests/tc_curl_protocols.rb +388 -0
- data/tests/tc_fiber_scheduler.rb +584 -0
- data/tests/tc_ftp_options.rb +39 -0
- data/tests/tc_gc_compact.rb +223 -0
- data/tests/tc_test_server_methods.rb +110 -0
- data/tests/timeout.rb +30 -6
- metadata +66 -31
- data/README +0 -194
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
2
|
+
|
|
3
|
+
class TestCurbCurlErrorMappings < Test::Unit::TestCase
|
|
4
|
+
def assert_easy_error_mapping(code, expected_class)
|
|
5
|
+
actual_class, message = Curl::Easy.error(code)
|
|
6
|
+
|
|
7
|
+
assert_equal expected_class, actual_class
|
|
8
|
+
assert_kind_of String, message
|
|
9
|
+
assert_not_empty message
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_easy_error_known_mappings
|
|
13
|
+
assert_easy_error_mapping(0, Curl::Err::CurlOK)
|
|
14
|
+
assert_easy_error_mapping(1, Curl::Err::UnsupportedProtocolError)
|
|
15
|
+
assert_easy_error_mapping(2, Curl::Err::FailedInitError)
|
|
16
|
+
assert_easy_error_mapping(3, Curl::Err::MalformedURLError)
|
|
17
|
+
assert_easy_error_mapping(5, Curl::Err::ProxyResolutionError)
|
|
18
|
+
assert_easy_error_mapping(6, Curl::Err::HostResolutionError)
|
|
19
|
+
assert_easy_error_mapping(7, Curl::Err::ConnectionFailedError)
|
|
20
|
+
assert_easy_error_mapping(23, Curl::Err::WriteError)
|
|
21
|
+
assert_easy_error_mapping(26, Curl::Err::ReadError)
|
|
22
|
+
assert_easy_error_mapping(28, Curl::Err::TimeoutError)
|
|
23
|
+
assert_easy_error_mapping(42, Curl::Err::AbortedByCallbackError)
|
|
24
|
+
assert_easy_error_mapping(47, Curl::Err::TooManyRedirectsError)
|
|
25
|
+
assert_easy_error_mapping(52, Curl::Err::GotNothingError)
|
|
26
|
+
assert_easy_error_mapping(55, Curl::Err::SendError)
|
|
27
|
+
assert_easy_error_mapping(56, Curl::Err::RecvError)
|
|
28
|
+
assert_easy_error_mapping(57, Curl::Err::ShareInUseError)
|
|
29
|
+
assert_easy_error_mapping(58, Curl::Err::SSLCertificateError)
|
|
30
|
+
assert_easy_error_mapping(59, Curl::Err::SSLCypherError)
|
|
31
|
+
assert_easy_error_mapping(61, Curl::Err::BadContentEncodingError)
|
|
32
|
+
assert_easy_error_mapping(63, Curl::Err::FileSizeExceededError)
|
|
33
|
+
assert_easy_error_mapping(64, Curl::Err::FTPSSLFailed)
|
|
34
|
+
|
|
35
|
+
ssl_peer_or_ca_error =
|
|
36
|
+
if Gem::Version.new(Curl::CURL_VERSION) >= Gem::Version.new('7.62.0')
|
|
37
|
+
Curl::Err::SSLPeerCertificateError
|
|
38
|
+
else
|
|
39
|
+
Curl::Err::SSLCACertificateError
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
assert_easy_error_mapping(60, ssl_peer_or_ca_error)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_easy_error_returns_error_info_for_known_numeric_range
|
|
46
|
+
0.upto(92) do |code|
|
|
47
|
+
error_class, message = Curl::Easy.error(code)
|
|
48
|
+
|
|
49
|
+
assert_kind_of Class, error_class
|
|
50
|
+
assert error_class <= Curl::Err::CurlError
|
|
51
|
+
assert_kind_of String, message
|
|
52
|
+
assert_not_empty message
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_easy_error_uses_generic_mapping_for_unknown_codes
|
|
57
|
+
error_class, message = Curl::Easy.error(9_999)
|
|
58
|
+
|
|
59
|
+
assert_equal Curl::Err::CurlError, error_class
|
|
60
|
+
assert_equal 'Unknown error result from libcurl', message
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class TestCurbCurlNativeCoverage < Test::Unit::TestCase
|
|
65
|
+
include TestServerMethods
|
|
66
|
+
|
|
67
|
+
def setup
|
|
68
|
+
server_setup
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_clone_preserves_native_lists_after_original_handle_closes
|
|
72
|
+
easy = Curl::Easy.new("http://curb.invalid:#{TestServlet.port}#{TestServlet.path}")
|
|
73
|
+
easy.headers['X-Test'] = '1'
|
|
74
|
+
easy.proxy_headers['X-Proxy'] = '2'
|
|
75
|
+
easy.ftp_commands = ['PWD']
|
|
76
|
+
easy.resolve = ["curb.invalid:#{TestServlet.port}:127.0.0.1"]
|
|
77
|
+
|
|
78
|
+
clone = easy.clone
|
|
79
|
+
easy.close
|
|
80
|
+
|
|
81
|
+
clone.http_get
|
|
82
|
+
|
|
83
|
+
assert_equal 'GET', clone.body_str
|
|
84
|
+
assert_equal '1', clone.headers['X-Test']
|
|
85
|
+
assert_equal '2', clone.proxy_headers['X-Proxy']
|
|
86
|
+
assert_equal ['PWD'], clone.ftp_commands
|
|
87
|
+
assert_equal ["curb.invalid:#{TestServlet.port}:127.0.0.1"], clone.resolve
|
|
88
|
+
ensure
|
|
89
|
+
clone.close if defined?(clone) && clone
|
|
90
|
+
easy.close if defined?(easy) && easy
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_clone_rebinds_upload_callbacks_to_clone_state
|
|
94
|
+
easy = Curl::Easy.new(TestServlet.url)
|
|
95
|
+
easy.put_data = 'clone-data'
|
|
96
|
+
|
|
97
|
+
clone = easy.clone
|
|
98
|
+
easy.put_data = 'other-data'
|
|
99
|
+
|
|
100
|
+
clone.perform
|
|
101
|
+
|
|
102
|
+
assert_equal "PUT\nclone-data", clone.body_str
|
|
103
|
+
ensure
|
|
104
|
+
clone.close if defined?(clone) && clone
|
|
105
|
+
easy.close if defined?(easy) && easy
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_native_accessors_round_trip
|
|
109
|
+
easy = Curl::Easy.new(TestServlet.url)
|
|
110
|
+
|
|
111
|
+
assert_equal '127.0.0.1', easy.interface = '127.0.0.1'
|
|
112
|
+
assert_equal 'user:pass', easy.userpwd = 'user:pass'
|
|
113
|
+
assert_equal 'proxy:pass', easy.proxypwd = 'proxy:pass'
|
|
114
|
+
assert_equal 'tests/cert.pem', easy.cert_key = 'tests/cert.pem'
|
|
115
|
+
assert_equal 'gzip', easy.encoding = 'gzip'
|
|
116
|
+
|
|
117
|
+
if easy.respond_to?(:max_send_speed_large=)
|
|
118
|
+
assert_equal 123, easy.max_send_speed_large = 123
|
|
119
|
+
assert_equal 123, easy.max_send_speed_large
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
if easy.respond_to?(:max_recv_speed_large=)
|
|
123
|
+
assert_equal 456, easy.max_recv_speed_large = 456
|
|
124
|
+
assert_equal 456, easy.max_recv_speed_large
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
assert_equal '127.0.0.1', easy.interface
|
|
128
|
+
assert_equal 'user:pass', easy.userpwd
|
|
129
|
+
assert_equal 'proxy:pass', easy.proxypwd
|
|
130
|
+
assert_equal 'tests/cert.pem', easy.cert_key
|
|
131
|
+
assert_equal 'gzip', easy.encoding
|
|
132
|
+
ensure
|
|
133
|
+
easy.close if defined?(easy) && easy
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_upload_round_trips_stream_and_offset
|
|
137
|
+
upload = Curl::Upload.new
|
|
138
|
+
stream = StringIO.new('payload')
|
|
139
|
+
|
|
140
|
+
assert_same stream, upload.stream = stream
|
|
141
|
+
assert_same stream, upload.stream
|
|
142
|
+
assert_equal 7, upload.offset = 7
|
|
143
|
+
assert_equal 7, upload.offset
|
|
144
|
+
end
|
|
145
|
+
end
|