curb 0.9.7 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.markdown +54 -5
- data/Rakefile +33 -20
- data/ext/banned.h +32 -0
- data/ext/curb.c +170 -8
- data/ext/curb.h +18 -5
- data/ext/curb_easy.c +321 -43
- data/ext/curb_easy.h +6 -0
- data/ext/curb_multi.c +136 -171
- data/ext/curb_multi.h +0 -1
- data/ext/curb_postfield.c +7 -7
- data/ext/extconf.rb +45 -0
- data/lib/curb.rb +1 -0
- data/lib/curl/easy.rb +14 -7
- data/lib/curl/multi.rb +42 -3
- data/lib/curl.rb +12 -3
- data/tests/bug_issue277.rb +32 -0
- data/tests/helper.rb +79 -1
- data/tests/tc_curl_easy.rb +118 -16
- data/tests/tc_curl_maxfilesize.rb +12 -0
- data/tests/tc_curl_multi.rb +109 -5
- data/tests/tc_curl_postfield.rb +29 -29
- data/tests/tc_curl_protocols.rb +37 -0
- data/tests/timeout.rb +21 -5
- metadata +14 -8
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
|
@@ -59,6 +61,9 @@ def have_constant(name)
|
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
64
|
+
have_constant "curlopt_tcp_keepalive"
|
65
|
+
have_constant "curlopt_tcp_keepidle"
|
66
|
+
have_constant "curlopt_tcp_keepintvl"
|
62
67
|
have_constant "curlinfo_appconnect_time"
|
63
68
|
have_constant "curlinfo_redirect_time"
|
64
69
|
have_constant "curlinfo_response_code"
|
@@ -84,6 +89,7 @@ have_constant "curlproxy_http"
|
|
84
89
|
have_constant "curlproxy_socks4"
|
85
90
|
have_constant "curlproxy_socks4a"
|
86
91
|
have_constant "curlproxy_socks5"
|
92
|
+
have_constant "curlproxy_socks5_hostname"
|
87
93
|
have_constant "curlauth_basic"
|
88
94
|
have_constant "curlauth_digest"
|
89
95
|
have_constant "curlauth_gssnegotiate"
|
@@ -152,6 +158,8 @@ have_func("curl_multi_timeout")
|
|
152
158
|
have_func("curl_multi_fdset")
|
153
159
|
have_func("curl_multi_perform")
|
154
160
|
|
161
|
+
have_constant "curlopt_haproxyprotocol"
|
162
|
+
|
155
163
|
# constants
|
156
164
|
have_constant "curlopt_interleavefunction"
|
157
165
|
have_constant "curlopt_interleavedata"
|
@@ -216,6 +224,7 @@ have_constant "curlopt_httppost"
|
|
216
224
|
have_constant "curlopt_referer"
|
217
225
|
have_constant "curlopt_useragent"
|
218
226
|
have_constant "curlopt_httpheader"
|
227
|
+
have_constant "curlopt_proxyheader"
|
219
228
|
have_constant "curlopt_http200aliases"
|
220
229
|
have_constant "curlopt_cookie"
|
221
230
|
have_constant "curlopt_cookiefile"
|
@@ -334,6 +343,9 @@ have_constant :CURL_SSLVERSION_TLSv1_0
|
|
334
343
|
have_constant :CURL_SSLVERSION_TLSv1_1
|
335
344
|
have_constant :CURL_SSLVERSION_TLSv1_2
|
336
345
|
|
346
|
+
# Added in 7.52.0
|
347
|
+
have_constant :CURL_SSLVERSION_TLSv1_3
|
348
|
+
|
337
349
|
have_constant "curlopt_ssl_verifypeer"
|
338
350
|
have_constant "curlopt_cainfo"
|
339
351
|
have_constant "curlopt_issuercert"
|
@@ -393,6 +405,37 @@ have_constant "curlopt_path_as_is"
|
|
393
405
|
# added in 7.43.0
|
394
406
|
have_constant "curlopt_pipewait"
|
395
407
|
|
408
|
+
# protocol constants
|
409
|
+
have_constant "curlproto_all"
|
410
|
+
have_constant "curlproto_dict"
|
411
|
+
have_constant "curlproto_file"
|
412
|
+
have_constant "curlproto_ftp"
|
413
|
+
have_constant "curlproto_ftps"
|
414
|
+
have_constant "curlproto_gopher"
|
415
|
+
have_constant "curlproto_http"
|
416
|
+
have_constant "curlproto_https"
|
417
|
+
have_constant "curlproto_imap"
|
418
|
+
have_constant "curlproto_imaps"
|
419
|
+
have_constant "curlproto_ldap"
|
420
|
+
have_constant "curlproto_ldaps"
|
421
|
+
have_constant "curlproto_pop3"
|
422
|
+
have_constant "curlproto_pop3s"
|
423
|
+
have_constant "curlproto_rtmp"
|
424
|
+
have_constant "curlproto_rtmpe"
|
425
|
+
have_constant "curlproto_rtmps"
|
426
|
+
have_constant "curlproto_rtmpt"
|
427
|
+
have_constant "curlproto_rtmpte"
|
428
|
+
have_constant "curlproto_rtmpts"
|
429
|
+
have_constant "curlproto_rtsp"
|
430
|
+
have_constant "curlproto_scp"
|
431
|
+
have_constant "curlproto_sftp"
|
432
|
+
have_constant "curlproto_smb"
|
433
|
+
have_constant "curlproto_smbs"
|
434
|
+
have_constant "curlproto_smtp"
|
435
|
+
have_constant "curlproto_smtps"
|
436
|
+
have_constant "curlproto_telnet"
|
437
|
+
have_constant "curlproto_tftp"
|
438
|
+
|
396
439
|
if try_compile('int main() { return 0; }','-Wall')
|
397
440
|
$CFLAGS << ' -Wall'
|
398
441
|
end
|
@@ -420,6 +463,8 @@ test_for("curl_easy_escape", "CURL_EASY_ESCAPE", %{
|
|
420
463
|
|
421
464
|
have_func('rb_thread_blocking_region')
|
422
465
|
have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
|
466
|
+
have_header('ruby/io.h')
|
467
|
+
have_func('rb_io_stdio_file')
|
423
468
|
|
424
469
|
create_header('curb_config.h')
|
425
470
|
create_makefile('curb_core')
|
data/lib/curb.rb
CHANGED
data/lib/curl/easy.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Curl
|
2
3
|
class Easy
|
3
4
|
|
@@ -20,7 +21,7 @@ module Curl
|
|
20
21
|
#
|
21
22
|
def status
|
22
23
|
# Matches the last HTTP Status - following the HTTP protocol specification 'Status-Line = HTTP-Version SP Status-Code SP (Opt:)Reason-Phrase CRLF'
|
23
|
-
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] }
|
24
25
|
statuses.last.strip if statuses.length > 0
|
25
26
|
end
|
26
27
|
|
@@ -68,9 +69,15 @@ module Curl
|
|
68
69
|
ret = self.multi.perform
|
69
70
|
self.multi.remove self
|
70
71
|
|
72
|
+
if Curl::Multi.autoclose
|
73
|
+
self.multi.close
|
74
|
+
self.multi = nil
|
75
|
+
end
|
76
|
+
|
71
77
|
if self.last_result != 0 && self.on_failure.nil?
|
72
|
-
|
73
|
-
|
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(": "))
|
74
81
|
end
|
75
82
|
|
76
83
|
ret
|
@@ -314,7 +321,7 @@ module Curl
|
|
314
321
|
|
315
322
|
#
|
316
323
|
# call-seq:
|
317
|
-
# Curl::Easy.perform(url) { |easy| ... } =>
|
324
|
+
# Curl::Easy.perform(url) { |easy| ... } => #<Curl::Easy...>
|
318
325
|
#
|
319
326
|
# Convenience method that creates a new Curl::Easy instance with
|
320
327
|
# the specified URL and calls the general +perform+ method, before returning
|
@@ -332,7 +339,7 @@ module Curl
|
|
332
339
|
|
333
340
|
#
|
334
341
|
# call-seq:
|
335
|
-
# Curl::Easy.http_get(url) { |easy| ... } =>
|
342
|
+
# Curl::Easy.http_get(url) { |easy| ... } => #<Curl::Easy...>
|
336
343
|
#
|
337
344
|
# Convenience method that creates a new Curl::Easy instance with
|
338
345
|
# the specified URL and calls +http_get+, before returning the new instance.
|
@@ -349,7 +356,7 @@ module Curl
|
|
349
356
|
|
350
357
|
#
|
351
358
|
# call-seq:
|
352
|
-
# Curl::Easy.http_head(url) { |easy| ... } =>
|
359
|
+
# Curl::Easy.http_head(url) { |easy| ... } => #<Curl::Easy...>
|
353
360
|
#
|
354
361
|
# Convenience method that creates a new Curl::Easy instance with
|
355
362
|
# the specified URL and calls +http_head+, before returning the new instance.
|
@@ -403,7 +410,7 @@ module Curl
|
|
403
410
|
|
404
411
|
#
|
405
412
|
# call-seq:
|
406
|
-
# Curl::Easy.http_delete(url) { |easy| ... } =>
|
413
|
+
# Curl::Easy.http_delete(url) { |easy| ... } => #<Curl::Easy...>
|
407
414
|
#
|
408
415
|
# Convenience method that creates a new Curl::Easy instance with
|
409
416
|
# the specified URL and calls +http_delete+, before returning the new instance.
|
data/lib/curl/multi.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Curl
|
2
|
-
|
3
3
|
class Multi
|
4
4
|
class << self
|
5
5
|
# call-seq:
|
@@ -144,7 +144,7 @@ module Curl
|
|
144
144
|
|
145
145
|
max_connects.times do
|
146
146
|
conf = urls_with_config.pop
|
147
|
-
add_free_handle.call
|
147
|
+
add_free_handle.call(conf, nil) if conf
|
148
148
|
break if urls_with_config.empty?
|
149
149
|
end
|
150
150
|
|
@@ -153,7 +153,7 @@ module Curl
|
|
153
153
|
if urls_with_config.size > 0 && free_handles.size > 0
|
154
154
|
easy = free_handles.pop
|
155
155
|
conf = urls_with_config.pop
|
156
|
-
add_free_handle.call
|
156
|
+
add_free_handle.call(conf, easy) if conf
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
@@ -168,6 +168,7 @@ module Curl
|
|
168
168
|
end
|
169
169
|
free_handles = nil
|
170
170
|
end
|
171
|
+
|
171
172
|
end
|
172
173
|
|
173
174
|
# call-seq:
|
@@ -242,7 +243,45 @@ module Curl
|
|
242
243
|
}
|
243
244
|
raise errors unless errors.empty?
|
244
245
|
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def cancel!
|
249
|
+
requests.each do |_,easy|
|
250
|
+
remove(easy)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def idle?
|
255
|
+
requests.empty?
|
256
|
+
end
|
245
257
|
|
258
|
+
def requests
|
259
|
+
@requests ||= {}
|
246
260
|
end
|
261
|
+
|
262
|
+
def add(easy)
|
263
|
+
return self if requests[easy.object_id]
|
264
|
+
requests[easy.object_id] = easy
|
265
|
+
_add(easy)
|
266
|
+
self
|
267
|
+
end
|
268
|
+
|
269
|
+
def remove(easy)
|
270
|
+
return self if !requests[easy.object_id]
|
271
|
+
requests.delete(easy.object_id)
|
272
|
+
_remove(easy)
|
273
|
+
self
|
274
|
+
end
|
275
|
+
|
276
|
+
def close
|
277
|
+
requests.values.each {|easy|
|
278
|
+
_remove(easy)
|
279
|
+
}
|
280
|
+
@requests = {}
|
281
|
+
_close
|
282
|
+
self
|
283
|
+
end
|
284
|
+
|
285
|
+
|
247
286
|
end
|
248
287
|
end
|
data/lib/curl.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'curb_core'
|
2
3
|
require 'curl/easy'
|
3
4
|
require 'curl/multi'
|
@@ -8,12 +9,20 @@ require 'cgi'
|
|
8
9
|
module Curl
|
9
10
|
|
10
11
|
def self.http(verb, url, post_body=nil, put_data=nil, &block)
|
11
|
-
|
12
|
-
|
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
|
13
18
|
handle.url = url
|
14
19
|
handle.post_body = post_body if post_body
|
15
20
|
handle.put_data = put_data if put_data
|
16
|
-
|
21
|
+
if block_given?
|
22
|
+
Thread.current[:curb_curl_yielding] = true
|
23
|
+
yield handle
|
24
|
+
Thread.current[:curb_curl_yielding] = false
|
25
|
+
end
|
17
26
|
handle.http(verb)
|
18
27
|
handle
|
19
28
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
|
4
|
+
require 'curb'
|
5
|
+
|
6
|
+
class BugIssue102 < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_gc_closewait
|
9
|
+
100.times do
|
10
|
+
responses = {}
|
11
|
+
requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
|
12
|
+
m = Curl::Multi.new
|
13
|
+
# add a few easy handles
|
14
|
+
requests.each do |url|
|
15
|
+
responses[url] = ""
|
16
|
+
c = Curl::Easy.new(url) do|curl|
|
17
|
+
curl.follow_location = true
|
18
|
+
curl.on_body{|data| responses[url] << data; data.size }
|
19
|
+
curl.on_success {|easy| #puts "success, add more easy handles"
|
20
|
+
}
|
21
|
+
end
|
22
|
+
m.add(c)
|
23
|
+
end
|
24
|
+
|
25
|
+
m.perform do
|
26
|
+
#puts "idling... can do some work here"
|
27
|
+
end
|
28
|
+
GC.start
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/tests/helper.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# Copyright (c)2006 Ross Bamford. See LICENSE.
|
3
3
|
$CURB_TESTING = true
|
4
4
|
require 'uri'
|
5
|
+
require 'stringio'
|
5
6
|
|
6
7
|
$TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
7
8
|
$EXTDIR = File.join($TOPDIR, 'ext')
|
@@ -142,7 +143,6 @@ module TestServerMethods
|
|
142
143
|
def server_setup(port=9129,servlet=TestServlet)
|
143
144
|
@__port = port
|
144
145
|
if (@server ||= nil).nil? and !File.exist?(locked_file)
|
145
|
-
|
146
146
|
File.open(locked_file,'w') {|f| f << 'locked' }
|
147
147
|
if TEST_SINGLE_THREADED
|
148
148
|
rd, wr = IO.pipe
|
@@ -207,3 +207,81 @@ module TestServerMethods
|
|
207
207
|
rescue Errno::EADDRINUSE
|
208
208
|
end
|
209
209
|
end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
# Backport for Ruby 1.8
|
214
|
+
module Backports
|
215
|
+
module Ruby18
|
216
|
+
module URIFormEncoding
|
217
|
+
TBLENCWWWCOMP_ = {}
|
218
|
+
TBLDECWWWCOMP_ = {}
|
219
|
+
|
220
|
+
def encode_www_form_component(str)
|
221
|
+
if TBLENCWWWCOMP_.empty?
|
222
|
+
256.times do |i|
|
223
|
+
TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
|
224
|
+
end
|
225
|
+
TBLENCWWWCOMP_[' '] = '+'
|
226
|
+
TBLENCWWWCOMP_.freeze
|
227
|
+
end
|
228
|
+
str.to_s.gsub( /([^*\-.0-9A-Z_a-z])/ ) {|*| TBLENCWWWCOMP_[$1] }
|
229
|
+
end
|
230
|
+
|
231
|
+
def decode_www_form_component(str)
|
232
|
+
if TBLDECWWWCOMP_.empty?
|
233
|
+
256.times do |i|
|
234
|
+
h, l = i>>4, i&15
|
235
|
+
TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
|
236
|
+
TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
|
237
|
+
TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
|
238
|
+
TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
|
239
|
+
end
|
240
|
+
TBLDECWWWCOMP_['+'] = ' '
|
241
|
+
TBLDECWWWCOMP_.freeze
|
242
|
+
end
|
243
|
+
|
244
|
+
raise ArgumentError, "invalid %-encoding (#{str.dump})" unless /\A(?:%[[:xdigit:]]{2}|[^%]+)*\z/ =~ str
|
245
|
+
str.gsub( /(\+|%[[:xdigit:]]{2})/ ) {|*| TBLDECWWWCOMP_[$1] }
|
246
|
+
end
|
247
|
+
|
248
|
+
def encode_www_form( enum )
|
249
|
+
enum.map do |k,v|
|
250
|
+
if v.nil?
|
251
|
+
encode_www_form_component(k)
|
252
|
+
elsif v.respond_to?(:to_ary)
|
253
|
+
v.to_ary.map do |w|
|
254
|
+
str = encode_www_form_component(k)
|
255
|
+
unless w.nil?
|
256
|
+
str << '='
|
257
|
+
str << encode_www_form_component(w)
|
258
|
+
end
|
259
|
+
end.join('&')
|
260
|
+
else
|
261
|
+
str = encode_www_form_component(k)
|
262
|
+
str << '='
|
263
|
+
str << encode_www_form_component(v)
|
264
|
+
end
|
265
|
+
end.join('&')
|
266
|
+
end
|
267
|
+
|
268
|
+
WFKV_ = '(?:%\h\h|[^%#=;&])'
|
269
|
+
def decode_www_form(str, _)
|
270
|
+
return [] if str.to_s == ''
|
271
|
+
|
272
|
+
unless /\A#{WFKV_}=#{WFKV_}(?:[;&]#{WFKV_}=#{WFKV_})*\z/ =~ str
|
273
|
+
raise ArgumentError, "invalid data of application/x-www-form-urlencoded (#{str})"
|
274
|
+
end
|
275
|
+
ary = []
|
276
|
+
$&.scan(/([^=;&]+)=([^;&]*)/) do
|
277
|
+
ary << [decode_www_form_component($1, enc), decode_www_form_component($2, enc)]
|
278
|
+
end
|
279
|
+
ary
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
unless URI.methods.include?(:encode_www_form)
|
286
|
+
URI.extend(Backports::Ruby18::URIFormEncoding)
|
287
|
+
end
|
data/tests/tc_curl_easy.rb
CHANGED
@@ -10,6 +10,74 @@ 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.response_code
|
17
|
+
}
|
18
|
+
assert_equal 200, easy.response_code
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_curlopt_stderr_with_file
|
22
|
+
# does not work with Tempfile directly
|
23
|
+
path = Tempfile.new('curb_test_curlopt_stderr').path
|
24
|
+
File.open(path, 'w') do |file|
|
25
|
+
easy = Curl::Easy.new(TestServlet.url)
|
26
|
+
easy.verbose = true
|
27
|
+
easy.setopt(Curl::CURLOPT_STDERR, file)
|
28
|
+
easy.perform
|
29
|
+
end
|
30
|
+
output = File.read(path)
|
31
|
+
|
32
|
+
assert_match(/HTTP\/1\.1\ 200\ OK(?:\ )?/, output)
|
33
|
+
assert_match('Host: 127.0.0.1:9129', output)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_curlopt_stderr_with_io
|
37
|
+
path = Tempfile.new('curb_test_curlopt_stderr').path
|
38
|
+
fd = IO.sysopen(path, 'w')
|
39
|
+
io = IO.for_fd(fd)
|
40
|
+
|
41
|
+
easy = Curl::Easy.new(TestServlet.url)
|
42
|
+
easy.verbose = true
|
43
|
+
easy.setopt(Curl::CURLOPT_STDERR, io)
|
44
|
+
easy.perform
|
45
|
+
|
46
|
+
|
47
|
+
output = File.read(path)
|
48
|
+
|
49
|
+
assert_match(output, 'HTTP/1.1 200 OK')
|
50
|
+
assert_match(output, 'Host: 127.0.0.1:9129')
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_curlopt_stderr_fails_with_tempdir
|
54
|
+
Tempfile.open('curb_test_curlopt_stderr') do |tempfile|
|
55
|
+
easy = Curl::Easy.new(TestServlet.url)
|
56
|
+
|
57
|
+
assert_raise(TypeError) do
|
58
|
+
easy.setopt(Curl::CURLOPT_STDERR, tempfile)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_curlopt_stderr_fails_with_stringio
|
64
|
+
stringio = StringIO.new
|
65
|
+
easy = Curl::Easy.new(TestServlet.url)
|
66
|
+
|
67
|
+
assert_raise(TypeError) do
|
68
|
+
easy.setopt(Curl::CURLOPT_STDERR, stringio)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_curlopt_stderr_fails_with_string
|
73
|
+
string = String.new
|
74
|
+
easy = Curl::Easy.new(TestServlet.url)
|
75
|
+
|
76
|
+
assert_raise(TypeError) do
|
77
|
+
easy.setopt(Curl::CURLOPT_STDERR, string)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
13
81
|
def test_exception
|
14
82
|
begin
|
15
83
|
Curl.get('NOT_FOUND_URL')
|
@@ -28,8 +96,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
28
96
|
c = Curl.get($TEST_URL)
|
29
97
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
30
98
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
|
31
|
-
assert_equal "", c.header_str
|
32
|
-
assert_equal "", c.head
|
33
99
|
end
|
34
100
|
end
|
35
101
|
end
|
@@ -41,7 +107,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
41
107
|
assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
|
42
108
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
43
109
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
|
44
|
-
assert_equal "", c.header_str
|
45
110
|
end
|
46
111
|
|
47
112
|
def test_class_perform_02
|
@@ -49,7 +114,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
49
114
|
assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL) { |curl| curl.on_body { |d| data << d; d.length } }
|
50
115
|
|
51
116
|
assert_nil c.body_str
|
52
|
-
assert_equal "", c.header_str
|
53
117
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
|
54
118
|
end
|
55
119
|
|
@@ -144,7 +208,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
144
208
|
c = Curl::Easy.new($TEST_URL)
|
145
209
|
assert_equal true, c.http_get
|
146
210
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
|
147
|
-
assert_equal "", c.header_str
|
148
211
|
end
|
149
212
|
|
150
213
|
def test_get_02
|
@@ -156,7 +219,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
156
219
|
assert_equal true, c.http_get
|
157
220
|
|
158
221
|
assert_nil c.body_str
|
159
|
-
assert_equal "", c.header_str
|
160
222
|
assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
|
161
223
|
end
|
162
224
|
|
@@ -339,29 +401,69 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
339
401
|
c.max_redirects = nil
|
340
402
|
assert_nil c.max_redirects
|
341
403
|
end
|
342
|
-
|
404
|
+
|
405
|
+
def test_timeout_with_floats
|
406
|
+
c = Curl::Easy.new($TEST_URL)
|
407
|
+
|
408
|
+
c.timeout = 1.5
|
409
|
+
assert_equal 1500, c.timeout_ms
|
410
|
+
assert_equal 1.5, c.timeout
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_timeout_with_negative
|
414
|
+
c = Curl::Easy.new($TEST_URL)
|
415
|
+
|
416
|
+
c.timeout = -1.5
|
417
|
+
assert_equal 0, c.timeout
|
418
|
+
assert_equal 0, c.timeout_ms
|
419
|
+
|
420
|
+
c.timeout = -4.8
|
421
|
+
assert_equal 0, c.timeout
|
422
|
+
assert_equal 0, c.timeout_ms
|
423
|
+
end
|
424
|
+
|
343
425
|
def test_timeout_01
|
344
426
|
c = Curl::Easy.new($TEST_URL)
|
345
|
-
|
346
|
-
|
347
|
-
|
427
|
+
|
428
|
+
assert_equal 0, c.timeout
|
429
|
+
|
348
430
|
c.timeout = 3
|
349
431
|
assert_equal 3, c.timeout
|
350
|
-
|
351
|
-
c.timeout =
|
352
|
-
|
432
|
+
|
433
|
+
c.timeout = 0
|
434
|
+
assert_equal 0, c.timeout
|
353
435
|
end
|
354
436
|
|
355
437
|
def test_timeout_ms_01
|
356
438
|
c = Curl::Easy.new($TEST_URL)
|
357
439
|
|
358
|
-
|
440
|
+
assert_equal 0, c.timeout_ms
|
359
441
|
|
360
442
|
c.timeout_ms = 100
|
361
443
|
assert_equal 100, c.timeout_ms
|
362
444
|
|
363
445
|
c.timeout_ms = nil
|
364
|
-
|
446
|
+
assert_equal 0, c.timeout_ms
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_timeout_ms_with_floats
|
450
|
+
c = Curl::Easy.new($TEST_URL)
|
451
|
+
|
452
|
+
c.timeout_ms = 55.5
|
453
|
+
assert_equal 55, c.timeout_ms
|
454
|
+
assert_equal 0.055, c.timeout
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_timeout_ms_with_negative
|
458
|
+
c = Curl::Easy.new($TEST_URL)
|
459
|
+
|
460
|
+
c.timeout_ms = -1.5
|
461
|
+
assert_equal 0, c.timeout
|
462
|
+
assert_equal 0, c.timeout_ms
|
463
|
+
|
464
|
+
c.timeout_ms = -4.8
|
465
|
+
assert_equal 0, c.timeout
|
466
|
+
assert_equal 0, c.timeout_ms
|
365
467
|
end
|
366
468
|
|
367
469
|
def test_connect_timeout_01
|
@@ -608,7 +710,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
608
710
|
def test_cookielist
|
609
711
|
c = Curl::Easy.new TestServlet.url
|
610
712
|
c.enable_cookies = true
|
611
|
-
c.post_body = URI.encode_www_form
|
713
|
+
c.post_body = URI.encode_www_form('c' => 'somename=somevalue')
|
612
714
|
assert_nil c.cookielist
|
613
715
|
c.perform
|
614
716
|
assert_match(/somevalue/, c.cookielist.join(''))
|
@@ -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
|