curb 1.1.0 → 1.2.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 +4 -4
- data/README.md +5 -1
- data/ext/curb.c +6 -4
- data/ext/curb.h +3 -3
- data/ext/curb_easy.c +97 -8
- data/ext/curb_multi.c +477 -15
- data/ext/curb_postfield.c +6 -0
- data/ext/curb_upload.c +3 -0
- data/ext/extconf.rb +214 -17
- 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/helper.rb +33 -0
- data/tests/mem_check.rb +3 -0
- data/tests/tc_curl_download.rb +2 -1
- data/tests/tc_curl_easy.rb +65 -6
- data/tests/tc_curl_multi.rb +2 -0
- data/tests/tc_fiber_scheduler.rb +190 -0
- data/tests/test_basic.rb +29 -0
- data/tests/test_fiber_debug.rb +69 -0
- data/tests/test_fiber_simple.rb +65 -0
- data/tests/test_real_url.rb +65 -0
- data/tests/test_simple_fiber.rb +34 -0
- metadata +20 -6
- data/tests/bug_issue277.rb +0 -32
- data/tests/bug_resolve.rb +0 -15
data/ext/extconf.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
require 'mkmf'
|
2
|
+
require 'tmpdir'
|
3
|
+
begin
|
4
|
+
require 'etc'
|
5
|
+
rescue LoadError
|
6
|
+
# Etc may not be available on all Ruby builds (very rare). Fallback later.
|
7
|
+
end
|
2
8
|
|
3
9
|
dir_config('curl')
|
4
10
|
|
@@ -37,26 +43,195 @@ end
|
|
37
43
|
# puts "Selected arch: #{archs.first}"
|
38
44
|
#end
|
39
45
|
|
40
|
-
def define(s, v=1)
|
41
|
-
$defs.push(
|
46
|
+
def define(s, v = 1)
|
47
|
+
$defs.push(format("-D HAVE_%s=%d", s.to_s.upcase, v))
|
42
48
|
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
# Optional parallelization support for constant checks only.
|
51
|
+
# Enable automatically when job hints are present (JOBS, BUNDLE_JOBS, MAKEFLAGS -jN),
|
52
|
+
# or explicitly via EXTCONF_JOBS/EXTCONF_PARALLEL.
|
53
|
+
|
54
|
+
def parse_jobs_from_makeflags(flags)
|
55
|
+
return nil if flags.nil? || flags.empty?
|
56
|
+
tokens = flags.to_s.split(/\s+/)
|
57
|
+
jobs = nil
|
58
|
+
tokens.each_with_index do |tok, i|
|
59
|
+
case tok
|
60
|
+
when /\A-j(\d+)\z/
|
61
|
+
jobs = $1.to_i
|
62
|
+
when '-j'
|
63
|
+
nxt = tokens[i + 1]
|
64
|
+
jobs = nxt.to_i if nxt && nxt =~ /\A\d+\z/
|
65
|
+
when /\A--jobs(?:=(\d+)|\s+(\d+))\z/
|
66
|
+
jobs = ($1 || $2).to_i
|
67
|
+
when /\Aj(\d+)\z/ # sometimes make condenses flags
|
68
|
+
jobs = $1.to_i
|
69
|
+
end
|
70
|
+
break if jobs && jobs > 0
|
71
|
+
end
|
72
|
+
jobs
|
73
|
+
end
|
74
|
+
|
75
|
+
def detect_job_hints
|
76
|
+
# Priority: explicit extconf hint, then common envs used by bundler/rubygems
|
77
|
+
[
|
78
|
+
ENV['EXTCONF_JOBS'],
|
79
|
+
ENV['JOBS'],
|
80
|
+
ENV['BUNDLE_JOBS'],
|
81
|
+
parse_jobs_from_makeflags(ENV['MAKEFLAGS'])
|
82
|
+
].each do |v|
|
83
|
+
n = v.to_i if v
|
84
|
+
return n if n && n > 0
|
85
|
+
end
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
explicit_parallel = ENV.key?('EXTCONF_PARALLEL') && ENV['EXTCONF_PARALLEL'] == '1'
|
90
|
+
job_hints = detect_job_hints
|
91
|
+
|
92
|
+
DEFAULT_PARALLEL_JOBS = begin
|
93
|
+
n = Etc.respond_to?(:nprocessors) ? Etc.nprocessors.to_i : 1
|
94
|
+
n = 1 if n <= 0
|
95
|
+
# Use half the CPUs by default (rounded up), but at least 1
|
96
|
+
jobs = [(n.to_f / 2).ceil, 1].max
|
97
|
+
jobs
|
98
|
+
rescue
|
99
|
+
1
|
100
|
+
end
|
101
|
+
|
102
|
+
PARALLEL_JOBS = begin
|
103
|
+
if job_hints && job_hints > 0
|
104
|
+
job_hints
|
105
|
+
else
|
106
|
+
# If no hints provided, default to half the CPUs.
|
107
|
+
DEFAULT_PARALLEL_JOBS
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Only enable if the platform supports fork. On Windows this stays sequential.
|
112
|
+
PARALLEL_CONSTANT_CHECKS = PARALLEL_JOBS > 1 && Process.respond_to?(:fork)
|
113
|
+
|
114
|
+
$queued_constants = []
|
115
|
+
|
116
|
+
def try_constant_compile(sname)
|
117
|
+
src = %{
|
118
|
+
#include <curl/curl.h>
|
119
|
+
int main() {
|
120
|
+
int test = (int)#{sname};
|
121
|
+
(void)test;
|
122
|
+
return 0;
|
53
123
|
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
124
|
+
}
|
125
|
+
try_compile(src, "#{$CFLAGS} #{$LIBS}")
|
126
|
+
end
|
127
|
+
|
128
|
+
def have_constant(name)
|
129
|
+
# Queue constants for optional parallel probing. Falls back to sequential.
|
130
|
+
if PARALLEL_CONSTANT_CHECKS
|
131
|
+
$queued_constants << name
|
132
|
+
true
|
133
|
+
else
|
134
|
+
sname = name.is_a?(Symbol) ? name.to_s : name.upcase
|
135
|
+
checking_for name do
|
136
|
+
if try_constant_compile(sname)
|
137
|
+
define name
|
138
|
+
true
|
139
|
+
else
|
140
|
+
false
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def flush_constant_checks
|
147
|
+
return if $queued_constants.empty?
|
148
|
+
|
149
|
+
constants = $queued_constants.uniq
|
150
|
+
$queued_constants.clear
|
151
|
+
|
152
|
+
# On platforms without fork (e.g., Windows), run sequentially.
|
153
|
+
unless PARALLEL_CONSTANT_CHECKS
|
154
|
+
constants.each { |name| have_constant(name) }
|
155
|
+
return
|
156
|
+
end
|
157
|
+
|
158
|
+
# Run constant probes in isolated child processes to avoid mkmf
|
159
|
+
# scratch file and logfile contention.
|
160
|
+
results = {}
|
161
|
+
pending = constants.dup
|
162
|
+
running = {}
|
163
|
+
max_jobs = PARALLEL_JOBS
|
164
|
+
|
165
|
+
spawn_probe = lambda do |const_name|
|
166
|
+
r, w = IO.pipe
|
167
|
+
pid = fork do
|
168
|
+
begin
|
169
|
+
r.close
|
170
|
+
Dir.mktmpdir('curb-mkmf-') do |dir|
|
171
|
+
Dir.chdir(dir) do
|
172
|
+
begin
|
173
|
+
# Avoid clobbering the main mkmf.log
|
174
|
+
Logging::logfile = File.open(File::NULL, 'w') rescue File.open(File.join(dir, 'mkmf.log'), 'w')
|
175
|
+
rescue
|
176
|
+
# best-effort
|
177
|
+
end
|
178
|
+
sname = const_name.is_a?(Symbol) ? const_name.to_s : const_name.upcase
|
179
|
+
ok = try_constant_compile(sname)
|
180
|
+
w.write([const_name, ok ? 1 : 0].join("\t"))
|
181
|
+
end
|
182
|
+
end
|
183
|
+
rescue
|
184
|
+
# Treat as failure if anything unexpected happens in child
|
185
|
+
begin
|
186
|
+
w.write([const_name, 0].join("\t"))
|
187
|
+
rescue
|
188
|
+
end
|
189
|
+
ensure
|
190
|
+
begin w.close rescue nil end
|
191
|
+
# Ensure the child exits without running at_exit handlers
|
192
|
+
exit! 0
|
193
|
+
end
|
194
|
+
end
|
195
|
+
w.close
|
196
|
+
running[pid] = r
|
197
|
+
end
|
198
|
+
|
199
|
+
# Start initial batch
|
200
|
+
while running.size < max_jobs && !pending.empty?
|
201
|
+
spawn_probe.call(pending.shift)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Collect results and keep spawning until done
|
205
|
+
until running.empty?
|
206
|
+
pid = Process.wait
|
207
|
+
io = running.delete(pid)
|
208
|
+
if io
|
209
|
+
begin
|
210
|
+
msg = io.read.to_s
|
211
|
+
name_str, ok_str = msg.split("\t", 2)
|
212
|
+
if name_str
|
213
|
+
# Map back to the original object if symbol-like
|
214
|
+
original = constants.find { |n| n.to_s == name_str }
|
215
|
+
results[original || name_str] = ok_str.to_i == 1
|
216
|
+
end
|
217
|
+
ensure
|
218
|
+
begin io.close rescue nil end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
# Fill next task slot
|
222
|
+
spawn_probe.call(pending.shift) unless pending.empty?
|
223
|
+
end
|
224
|
+
|
225
|
+
# Apply results to $defs and output summary via checking_for
|
226
|
+
results.each do |const_name, ok|
|
227
|
+
sname = const_name.is_a?(Symbol) ? const_name.to_s : const_name.upcase
|
228
|
+
checking_for const_name do
|
229
|
+
if ok
|
230
|
+
define const_name
|
231
|
+
true
|
232
|
+
else
|
233
|
+
false
|
234
|
+
end
|
60
235
|
end
|
61
236
|
end
|
62
237
|
end
|
@@ -469,9 +644,31 @@ test_for("curl_easy_escape", "CURL_EASY_ESCAPE", %{
|
|
469
644
|
have_func('rb_thread_blocking_region')
|
470
645
|
have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
|
471
646
|
have_header('ruby/io.h')
|
647
|
+
have_func('rb_thread_fd_select', 'ruby/io.h')
|
648
|
+
have_func('rb_wait_for_single_fd', 'ruby/io.h')
|
649
|
+
have_header('ruby/fiber/scheduler.h')
|
650
|
+
have_func('rb_fiber_scheduler_current', 'ruby/fiber/scheduler.h')
|
651
|
+
have_func('rb_fiber_scheduler_io_wait', 'ruby/fiber/scheduler.h')
|
472
652
|
have_func('rb_io_stdio_file')
|
473
653
|
have_func('curl_multi_wait')
|
654
|
+
have_func('curl_multi_socket_action')
|
655
|
+
have_func('curl_multi_assign')
|
656
|
+
have_func('curl_multi_wakeup')
|
657
|
+
have_func('curl_multi_poll')
|
658
|
+
have_func('curl_multi_socket')
|
659
|
+
have_func('curl_multi_timer_callback')
|
660
|
+
have_constant 'curlmopt_socketfunction'
|
661
|
+
have_constant 'curlmopt_timerfunction'
|
474
662
|
have_func('curl_easy_duphandle')
|
475
663
|
|
664
|
+
# Optional: enable verbose socket-action debug logging.
|
665
|
+
# Set CURB_SOCKET_DEBUG=1 in the environment before running extconf to enable.
|
666
|
+
if ENV['CURB_SOCKET_DEBUG'] == '1'
|
667
|
+
$defs << '-DCURB_SOCKET_DEBUG=1'
|
668
|
+
end
|
669
|
+
|
670
|
+
# Run any queued constant checks (in parallel if enabled) before header generation.
|
671
|
+
flush_constant_checks
|
672
|
+
|
476
673
|
create_header('curb_config.h')
|
477
674
|
create_makefile('curb_core')
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
class BugIssueNoproxy < Test::Unit::TestCase
|
4
|
+
def test_noproxy_option_support
|
5
|
+
# Test that CURLOPT_NOPROXY constant is defined
|
6
|
+
assert Curl.const_defined?(:CURLOPT_NOPROXY), "CURLOPT_NOPROXY constant should be defined"
|
7
|
+
|
8
|
+
# Test basic noproxy setting using setopt
|
9
|
+
c = Curl::Easy.new('https://google.com')
|
10
|
+
|
11
|
+
# This should not raise an error
|
12
|
+
assert_nothing_raised do
|
13
|
+
c.setopt(Curl::CURLOPT_NOPROXY, "localhost,127.0.0.1")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Test using the convenience method if it exists
|
17
|
+
if c.respond_to?(:noproxy=)
|
18
|
+
assert_nothing_raised do
|
19
|
+
c.noproxy = "localhost,127.0.0.1"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Test getter if it exists
|
23
|
+
if c.respond_to?(:noproxy)
|
24
|
+
assert_equal "localhost,127.0.0.1", c.noproxy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_noproxy_with_set_method
|
30
|
+
c = Curl::Easy.new('https://google.com')
|
31
|
+
|
32
|
+
# The issue specifically mentions using the set method
|
33
|
+
# This currently raises TypeError as reported in the issue
|
34
|
+
assert_nothing_raised(TypeError) do
|
35
|
+
c.set(:noproxy, "localhost,127.0.0.1")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_noproxy_empty_string
|
40
|
+
c = Curl::Easy.new('https://google.com')
|
41
|
+
|
42
|
+
# Test setting empty string to override environment variables
|
43
|
+
assert_nothing_raised do
|
44
|
+
c.setopt(Curl::CURLOPT_NOPROXY, "")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_noproxy_nil_value
|
49
|
+
c = Curl::Easy.new('https://google.com')
|
50
|
+
|
51
|
+
# Test setting nil to reset
|
52
|
+
assert_nothing_raised do
|
53
|
+
c.setopt(Curl::CURLOPT_NOPROXY, nil)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class BugIssuePostRedirect < Test::Unit::TestCase
|
5
|
+
include BugTestServerSetupTeardown
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@port = 9998
|
9
|
+
super
|
10
|
+
# Mount a POST endpoint that returns a redirect
|
11
|
+
@server.mount_proc("/post_redirect") do |req, res|
|
12
|
+
if req.request_method == "POST"
|
13
|
+
res.status = 302
|
14
|
+
res['Location'] = "http://127.0.0.1:#{@port}/redirected"
|
15
|
+
res.body = "Redirecting..."
|
16
|
+
else
|
17
|
+
res.status = 405
|
18
|
+
res.body = "Method not allowed"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Mount the redirect target
|
23
|
+
@server.mount_proc("/redirected") do |req, res|
|
24
|
+
res.status = 200
|
25
|
+
res['Content-Type'] = "text/plain"
|
26
|
+
res.body = "You have been redirected"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_post_with_max_redirects_zero_should_not_follow_redirect
|
31
|
+
# Test case replicating the issue: POST with max_redirects=0 and follow_location=false
|
32
|
+
# should NOT trigger on_redirect callback or follow the redirect
|
33
|
+
|
34
|
+
redirect_called = false
|
35
|
+
|
36
|
+
handle = Curl::Easy.new("http://127.0.0.1:#{@port}/post_redirect") do |curl|
|
37
|
+
curl.max_redirects = 0
|
38
|
+
curl.follow_location = false
|
39
|
+
curl.on_redirect do |easy|
|
40
|
+
redirect_called = true
|
41
|
+
end
|
42
|
+
curl.headers['Content-Type'] = 'application/json'
|
43
|
+
curl.post_body = {test: "data"}.to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
handle.http(:POST)
|
47
|
+
|
48
|
+
# The response should be the redirect response (302)
|
49
|
+
assert_equal 302, handle.response_code
|
50
|
+
assert_match(/Redirecting/, handle.body_str)
|
51
|
+
|
52
|
+
# on_redirect should NOT be called when follow_location is false
|
53
|
+
assert !redirect_called, "on_redirect callback should not be called when follow_location is false"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_post_with_follow_location_true_triggers_redirect
|
57
|
+
# Test that on_redirect IS called when follow_location is true
|
58
|
+
redirect_called = false
|
59
|
+
|
60
|
+
handle = Curl::Easy.new("http://127.0.0.1:#{@port}/post_redirect") do |curl|
|
61
|
+
curl.follow_location = true
|
62
|
+
curl.on_redirect do |easy|
|
63
|
+
redirect_called = true
|
64
|
+
end
|
65
|
+
curl.headers['Content-Type'] = 'application/json'
|
66
|
+
curl.post_body = {test: "data"}.to_json
|
67
|
+
end
|
68
|
+
|
69
|
+
handle.http(:POST)
|
70
|
+
|
71
|
+
# Should follow the redirect and get the final response
|
72
|
+
assert_equal 200, handle.response_code
|
73
|
+
assert_match(/You have been redirected/, handle.body_str)
|
74
|
+
|
75
|
+
# on_redirect SHOULD be called when follow_location is true
|
76
|
+
assert redirect_called, "on_redirect callback should be called when follow_location is true"
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_curl_post_class_method_respects_redirect_settings
|
80
|
+
# Test that Curl.post (class method) respects redirect settings
|
81
|
+
# According to the issue, this works correctly
|
82
|
+
|
83
|
+
response = Curl.post("http://127.0.0.1:#{@port}/post_redirect", {test: "data"}.to_json) do |curl|
|
84
|
+
curl.max_redirects = 0
|
85
|
+
curl.follow_location = false
|
86
|
+
curl.headers['Content-Type'] = 'application/json'
|
87
|
+
end
|
88
|
+
|
89
|
+
# Should get the redirect response, not follow it
|
90
|
+
assert_equal 302, response.response_code
|
91
|
+
assert_match(/Redirecting/, response.body_str)
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
class BugIssueSpnego < Test::Unit::TestCase
|
4
|
+
def test_spnego_detection_works
|
5
|
+
# The fix for issue #227 ensures that Curl.spnego? checks for both
|
6
|
+
# CURL_VERSION_SPNEGO (newer libcurl) and CURL_VERSION_GSSNEGOTIATE (older libcurl)
|
7
|
+
#
|
8
|
+
# We can't test that it returns true because that depends on how libcurl
|
9
|
+
# was compiled on the system. We can only test that:
|
10
|
+
# 1. The method exists and works
|
11
|
+
# 2. If CURLAUTH_GSSNEGOTIATE is available, we can use it
|
12
|
+
|
13
|
+
# Check if CURLAUTH_GSSNEGOTIATE is available
|
14
|
+
if Curl.const_defined?(:CURLAUTH_GSSNEGOTIATE) && Curl.const_get(:CURLAUTH_GSSNEGOTIATE) != 0
|
15
|
+
# Test that we can use GSSNEGOTIATE auth type
|
16
|
+
c = Curl::Easy.new('http://example.com')
|
17
|
+
assert_nothing_raised do
|
18
|
+
c.http_auth_types = Curl::CURLAUTH_GSSNEGOTIATE
|
19
|
+
end
|
20
|
+
|
21
|
+
# The fix ensures spnego? won't incorrectly return false when
|
22
|
+
# older libcurl versions have GSSNEGOTIATE support
|
23
|
+
# (The actual return value depends on system libcurl compilation)
|
24
|
+
end
|
25
|
+
|
26
|
+
# The important fix is that the method now checks both constants
|
27
|
+
# This test passes if no exceptions are raised
|
28
|
+
assert true, "SPNEGO detection is working correctly"
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_spnego_method_exists
|
32
|
+
# The method should always exist
|
33
|
+
assert Curl.respond_to?(:spnego?), "Curl should respond to spnego?"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_spnego_returns_boolean
|
37
|
+
# The method should return a boolean
|
38
|
+
result = Curl.spnego?
|
39
|
+
assert [true, false].include?(result), "Curl.spnego? should return true or false, got #{result.inspect}"
|
40
|
+
end
|
41
|
+
end
|
data/tests/helper.rb
CHANGED
@@ -11,6 +11,34 @@ $LIBDIR = File.join($TOPDIR, 'lib')
|
|
11
11
|
$:.unshift($LIBDIR)
|
12
12
|
$:.unshift($EXTDIR)
|
13
13
|
|
14
|
+
# Setup SimpleCov for Ruby code coverage if COVERAGE env var is set
|
15
|
+
if ENV['COVERAGE']
|
16
|
+
begin
|
17
|
+
require 'simplecov'
|
18
|
+
require 'simplecov-lcov'
|
19
|
+
|
20
|
+
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
|
21
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
22
|
+
SimpleCov::Formatter::HTMLFormatter,
|
23
|
+
SimpleCov::Formatter::LcovFormatter
|
24
|
+
])
|
25
|
+
|
26
|
+
SimpleCov.start do
|
27
|
+
add_filter '/tests/'
|
28
|
+
add_filter '/spec/'
|
29
|
+
add_filter '/vendor/'
|
30
|
+
add_filter '/.bundle/'
|
31
|
+
add_group 'Library', 'lib'
|
32
|
+
add_group 'Extensions', 'ext'
|
33
|
+
|
34
|
+
# Track branch coverage if available
|
35
|
+
enable_coverage :branch if respond_to?(:enable_coverage)
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
puts "SimpleCov not available. Install it with: gem install simplecov simplecov-lcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
14
42
|
require 'curb'
|
15
43
|
begin
|
16
44
|
require 'test/unit'
|
@@ -19,6 +47,11 @@ rescue LoadError
|
|
19
47
|
require 'test/unit'
|
20
48
|
end
|
21
49
|
require 'fileutils'
|
50
|
+
require 'rbconfig'
|
51
|
+
|
52
|
+
# Platform helpers
|
53
|
+
WINDOWS = /mswin|msys|mingw|cygwin|bccwin|wince|emc|windows/i.match?(RbConfig::CONFIG['host_os'])
|
54
|
+
NO_FORK = !Process.respond_to?(:fork)
|
22
55
|
|
23
56
|
$TEST_URL = "file://#{'/' if RUBY_DESCRIPTION =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/}#{File.expand_path(__FILE__).tr('\\','/')}"
|
24
57
|
|
data/tests/mem_check.rb
CHANGED
@@ -6,6 +6,9 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
6
6
|
# Run some tests to measure the memory usage of curb, these tests require fork and ps
|
7
7
|
#
|
8
8
|
class TestCurbMemory < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
omit('Memory fork/ps tests not supported on Windows') if WINDOWS || NO_FORK
|
11
|
+
end
|
9
12
|
|
10
13
|
def test_easy_memory
|
11
14
|
easy_avg, easy_std = measure_object_memory(Curl::Easy)
|
data/tests/tc_curl_download.rb
CHANGED
@@ -32,6 +32,7 @@ class TestCurbCurlDownload < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_download_url_to_file_via_io
|
35
|
+
omit('fork not available on this platform') if NO_FORK || WINDOWS
|
35
36
|
dl_url = "http://127.0.0.1:9129/ext/curb_easy.c"
|
36
37
|
dl_path = File.join(Dir::tmpdir, "dl_url_test.file")
|
37
38
|
reader, writer = IO.pipe
|
@@ -58,7 +59,7 @@ class TestCurbCurlDownload < Test::Unit::TestCase
|
|
58
59
|
assert File.exist?(dl_path)
|
59
60
|
assert_equal File.read(File.join(File.dirname(__FILE__), '..','ext','curb_easy.c')), File.read(dl_path)
|
60
61
|
ensure
|
61
|
-
File.unlink(dl_path) if File.exist?(dl_path)
|
62
|
+
File.unlink(dl_path) if dl_path && File.exist?(dl_path)
|
62
63
|
end
|
63
64
|
|
64
65
|
def test_download_bad_url_gives_404
|
data/tests/tc_curl_easy.rb
CHANGED
@@ -48,20 +48,62 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_curlopt_stderr_with_io
|
51
|
-
|
51
|
+
tmp = Tempfile.new('curb_test_curlopt_stderr')
|
52
|
+
path = tmp.path
|
52
53
|
fd = IO.sysopen(path, 'w')
|
53
|
-
io = IO.
|
54
|
+
io = IO.new(fd, 'w')
|
55
|
+
io.sync = true
|
54
56
|
|
55
57
|
easy = Curl::Easy.new(TestServlet.url)
|
56
58
|
easy.verbose = true
|
57
59
|
easy.setopt(Curl::CURLOPT_STDERR, io)
|
58
60
|
easy.perform
|
59
61
|
|
62
|
+
io.flush
|
63
|
+
io.close
|
64
|
+
output = File.read(path)
|
65
|
+
|
66
|
+
assert_match(/HTTP\/1\.1\ 200\ OK(?:\ )?/, output)
|
67
|
+
assert_match('Host: 127.0.0.1:9129', output)
|
68
|
+
ensure
|
69
|
+
tmp.close! if defined?(tmp) && tmp
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_curlopt_stderr_gc_safe
|
73
|
+
tmp = Tempfile.new('curb_test_curlopt_stderr_gc')
|
74
|
+
path = tmp.path
|
75
|
+
fd = IO.sysopen(path, 'w')
|
76
|
+
io = IO.new(fd, 'w')
|
77
|
+
|
78
|
+
easy = Curl::Easy.new(TestServlet.url)
|
79
|
+
easy.verbose = true
|
80
|
+
easy.setopt(Curl::CURLOPT_STDERR, io)
|
81
|
+
|
82
|
+
# Drop our Ruby reference and force GC; curb should retain it internally
|
83
|
+
io = nil
|
84
|
+
GC.start
|
85
|
+
|
86
|
+
easy.perform
|
60
87
|
|
61
88
|
output = File.read(path)
|
89
|
+
assert_match(/HTTP\/1\.1\ 200\ OK(?:\ )?/, output)
|
90
|
+
assert_match('Host: 127.0.0.1:9129', output)
|
91
|
+
ensure
|
92
|
+
tmp.close! if defined?(tmp) && tmp
|
93
|
+
end
|
62
94
|
|
63
|
-
|
64
|
-
|
95
|
+
def test_head_request_no_body_and_no_timeout
|
96
|
+
# Ensure a HEAD request completes and does not attempt to read a body
|
97
|
+
# even when the server advertises a Content-Length.
|
98
|
+
easy = nil
|
99
|
+
assert_nothing_raised do
|
100
|
+
easy = Curl.http(:HEAD, TestServlet.url)
|
101
|
+
end
|
102
|
+
assert_not_nil easy
|
103
|
+
# Header string should contain the HTTP status line.
|
104
|
+
assert_match(/HTTP\/1\.1\s\d+\s/, easy.header_str.to_s)
|
105
|
+
# Body should be empty for HEAD requests (libcurl won't call the write callback).
|
106
|
+
assert_equal "", easy.body_str.to_s
|
65
107
|
end
|
66
108
|
|
67
109
|
def test_curlopt_stderr_fails_with_tempdir
|
@@ -245,6 +287,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
245
287
|
|
246
288
|
|
247
289
|
def test_last_effective_url_01
|
290
|
+
omit('Windows file URL semantics differ') if WINDOWS
|
248
291
|
c = Curl::Easy.new($TEST_URL)
|
249
292
|
|
250
293
|
assert_equal $TEST_URL, c.url
|
@@ -1041,7 +1084,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
1041
1084
|
$auth_header = nil
|
1042
1085
|
# curl checks the auth type supported by the server, so we have to create a
|
1043
1086
|
# new easy handle if we're going to change the auth type...
|
1044
|
-
|
1087
|
+
if WINDOWS
|
1088
|
+
# On Windows, libcurl often uses SSPI for NTLM which yields a different
|
1089
|
+
# header value and encoding; skip the NTLM-specific assertion.
|
1090
|
+
return
|
1091
|
+
end
|
1045
1092
|
curl = Curl::Easy.new(TestServlet.url)
|
1046
1093
|
curl.username = "foo"
|
1047
1094
|
curl.password = "bar"
|
@@ -1073,7 +1120,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
1073
1120
|
easy.http_post(pf)
|
1074
1121
|
|
1075
1122
|
assert_not_equal(0,easy.body.size)
|
1076
|
-
assert_equal(Digest::MD5.hexdigest(easy.body), Digest::MD5.hexdigest(File.
|
1123
|
+
assert_equal(Digest::MD5.hexdigest(easy.body), Digest::MD5.hexdigest(File.binread(readme)))
|
1077
1124
|
end
|
1078
1125
|
|
1079
1126
|
def test_easy_close
|
@@ -1095,6 +1142,18 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
1095
1142
|
easy.http_get
|
1096
1143
|
end
|
1097
1144
|
|
1145
|
+
def test_last_result_initialization
|
1146
|
+
# Test for issue #463 - ensure last_result is properly initialized to 0
|
1147
|
+
easy = Curl::Easy.new
|
1148
|
+
assert_equal 0, easy.last_result, "last_result should be initialized to 0 for new instance"
|
1149
|
+
|
1150
|
+
# Test that reset also sets last_result to 0
|
1151
|
+
easy.url = TestServlet.url
|
1152
|
+
easy.http_get
|
1153
|
+
easy.reset
|
1154
|
+
assert_equal 0, easy.last_result, "last_result should be reset to 0 after calling reset"
|
1155
|
+
end
|
1156
|
+
|
1098
1157
|
def test_easy_use_http_versions
|
1099
1158
|
easy = Curl::Easy.new
|
1100
1159
|
easy.url = TestServlet.url + "?query=foo"
|
data/tests/tc_curl_multi.rb
CHANGED
@@ -10,6 +10,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
10
10
|
# for https://github.com/taf2/curb/issues/277
|
11
11
|
# must connect to an external
|
12
12
|
def test_connection_keepalive
|
13
|
+
omit('Not supported on Windows runners') if WINDOWS
|
13
14
|
# this test fails with libcurl 7.22.0. I didn't investigate, but it may be related
|
14
15
|
# to CURLOPT_MAXCONNECTS bug fixed in 7.30.0:
|
15
16
|
# https://github.com/curl/curl/commit/e87e76e2dc108efb1cae87df496416f49c55fca0
|
@@ -171,6 +172,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
171
172
|
end
|
172
173
|
|
173
174
|
def test_multi_easy_get_with_error
|
175
|
+
omit('Path/line parsing differs on Windows') if WINDOWS
|
174
176
|
begin
|
175
177
|
did_raise = false
|
176
178
|
n = 3
|