curb 0.8.5 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +230 -0
- data/ext/curb.c +7 -0
- data/ext/curb.h +5 -9
- data/ext/curb_easy.c +34 -7
- data/ext/curb_errors.c +27 -16
- data/ext/curb_errors.h +8 -5
- data/ext/curb_multi.c +16 -10
- data/ext/extconf.rb +4 -17
- data/lib/curl.rb +2 -1
- data/lib/curl/easy.rb +69 -59
- data/tests/bug_crash_on_progress.rb +41 -1
- data/tests/bug_issue102.rb +17 -0
- data/tests/helper.rb +6 -1
- data/tests/tc_curl_download.rb +1 -1
- data/tests/tc_curl_easy.rb +11 -4
- data/tests/tc_curl_multi.rb +1 -1
- metadata +7 -5
- data/README +0 -194
@@ -5,7 +5,7 @@ class ::WEBrick::BasicLog ; def log(level, data) ; end ; end
|
|
5
5
|
|
6
6
|
class BugCrashOnDebug < Test::Unit::TestCase
|
7
7
|
|
8
|
-
def
|
8
|
+
def test_on_progress_raise
|
9
9
|
server = WEBrick::HTTPServer.new( :Port => 9999 )
|
10
10
|
server.mount_proc("/test") do|req,res|
|
11
11
|
res.body = "hi"
|
@@ -30,4 +30,44 @@ class BugCrashOnDebug < Test::Unit::TestCase
|
|
30
30
|
ensure
|
31
31
|
server.shutdown
|
32
32
|
end
|
33
|
+
|
34
|
+
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
|
+
# see: https://github.com/taf2/curb/issues/192,
|
46
|
+
# to pass:
|
47
|
+
#
|
48
|
+
# c = Curl::Easy.new('http://127.0.0.1:9999/test')
|
49
|
+
# c.on_progress do|x|
|
50
|
+
# puts "we're in the progress callback"
|
51
|
+
# false
|
52
|
+
# end
|
53
|
+
# c.perform
|
54
|
+
#
|
55
|
+
# notice no return keyword
|
56
|
+
#
|
57
|
+
c = Curl::Easy.new('http://127.0.0.1:9999/test')
|
58
|
+
c.on_progress do|x|
|
59
|
+
puts "we're in the progress callback"
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
c.perform
|
63
|
+
|
64
|
+
assert false, "should not reach this point"
|
65
|
+
|
66
|
+
rescue => e
|
67
|
+
assert_equal 'Curl::Err::AbortedByCallbackError', e.class.to_s
|
68
|
+
c.close
|
69
|
+
ensure
|
70
|
+
server.shutdown
|
71
|
+
end
|
72
|
+
|
33
73
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
class BugIssue102 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_interface
|
6
|
+
test = "https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true"
|
7
|
+
ip = "0.0.0.0"
|
8
|
+
|
9
|
+
c = Curl::Easy.new do |curl|
|
10
|
+
curl.url = test
|
11
|
+
curl.interface = ip
|
12
|
+
end
|
13
|
+
|
14
|
+
c.perform
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/tests/helper.rb
CHANGED
@@ -10,7 +10,12 @@ $:.unshift($LIBDIR)
|
|
10
10
|
$:.unshift($EXTDIR)
|
11
11
|
|
12
12
|
require 'curb'
|
13
|
-
|
13
|
+
begin
|
14
|
+
require 'test/unit'
|
15
|
+
rescue LoadError
|
16
|
+
gem 'test/unit'
|
17
|
+
require 'test/unit'
|
18
|
+
end
|
14
19
|
require 'fileutils'
|
15
20
|
|
16
21
|
$TEST_URL = "file://#{URI.escape(File.expand_path(__FILE__).tr('\\','/').tr(':','|'))}"
|
data/tests/tc_curl_download.rb
CHANGED
data/tests/tc_curl_easy.rb
CHANGED
@@ -645,8 +645,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
645
645
|
curl = Curl::Easy.new(TestServlet.url)
|
646
646
|
curl.multipart_form_post = true
|
647
647
|
fields = [
|
648
|
-
Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README'))),
|
649
|
-
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
648
|
+
Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))),
|
649
|
+
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
650
650
|
]
|
651
651
|
curl.http_post(fields)
|
652
652
|
assert_match /HTTP POST file upload/, curl.body_str
|
@@ -674,7 +674,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
674
674
|
def test_post_multipart_file_remote
|
675
675
|
curl = Curl::Easy.new(TestServlet.url)
|
676
676
|
curl.multipart_form_post = true
|
677
|
-
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
|
677
|
+
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
678
678
|
curl.http_post(pf)
|
679
679
|
assert_match /HTTP POST file upload/, curl.body_str
|
680
680
|
assert_match /Content-Disposition: form-data/, curl.body_str
|
@@ -855,7 +855,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
855
855
|
end
|
856
856
|
|
857
857
|
def test_post_streaming
|
858
|
-
readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README'))
|
858
|
+
readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))
|
859
859
|
|
860
860
|
pf = Curl::PostField.file("filename", readme)
|
861
861
|
|
@@ -1022,6 +1022,13 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
1022
1022
|
end
|
1023
1023
|
end
|
1024
1024
|
|
1025
|
+
def test_set_unsupported_options
|
1026
|
+
curl = Curl::Easy.new
|
1027
|
+
assert_raises TypeError do
|
1028
|
+
curl.set(99999, 1)
|
1029
|
+
end
|
1030
|
+
end
|
1031
|
+
|
1025
1032
|
include TestServerMethods
|
1026
1033
|
|
1027
1034
|
def setup
|
data/tests/tc_curl_multi.rb
CHANGED
@@ -466,7 +466,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
466
466
|
m.add(c)
|
467
467
|
m.add(c)
|
468
468
|
rescue => e
|
469
|
-
|
469
|
+
assert Curl::Err::MultiBadEasyHandle == e.class || Curl::Err::MultiAddedAlready == e.class
|
470
470
|
end
|
471
471
|
|
472
472
|
def test_multi_default_timeout
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings
|
16
16
|
for the libcurl(3), a fully-featured client-side URL transfer library. cURL and
|
@@ -21,10 +21,10 @@ extensions:
|
|
21
21
|
- ext/extconf.rb
|
22
22
|
extra_rdoc_files:
|
23
23
|
- LICENSE
|
24
|
-
- README
|
24
|
+
- README.markdown
|
25
25
|
files:
|
26
26
|
- LICENSE
|
27
|
-
- README
|
27
|
+
- README.markdown
|
28
28
|
- Rakefile
|
29
29
|
- doc.rb
|
30
30
|
- ext/extconf.rb
|
@@ -51,6 +51,7 @@ files:
|
|
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
53
|
- tests/bug_instance_post_differs_from_class_post.rb
|
54
|
+
- tests/bug_issue102.rb
|
54
55
|
- tests/bug_multi_segfault.rb
|
55
56
|
- tests/bug_postfields_crash.rb
|
56
57
|
- tests/bug_postfields_crash2.rb
|
@@ -74,7 +75,7 @@ licenses: []
|
|
74
75
|
post_install_message:
|
75
76
|
rdoc_options:
|
76
77
|
- --main
|
77
|
-
- README
|
78
|
+
- README.markdown
|
78
79
|
require_paths:
|
79
80
|
- lib
|
80
81
|
- ext
|
@@ -103,6 +104,7 @@ test_files:
|
|
103
104
|
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
104
105
|
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
105
106
|
- tests/bug_instance_post_differs_from_class_post.rb
|
107
|
+
- tests/bug_issue102.rb
|
106
108
|
- tests/bug_multi_segfault.rb
|
107
109
|
- tests/bug_postfields_crash.rb
|
108
110
|
- tests/bug_postfields_crash2.rb
|
data/README
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
# Curb - Libcurl bindings for Ruby
|
2
|
-
|
3
|
-
+ [rubyforge rdoc](http://curb.rubyforge.org/)
|
4
|
-
+ [rubyforge project](http://rubyforge.org/projects/curb)
|
5
|
-
+ [github project](http://github.com/taf2/curb/tree/master)
|
6
|
-
|
7
|
-
Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the
|
8
|
-
libcurl(3), a fully-featured client-side URL transfer library.
|
9
|
-
cURL and libcurl live at [http://curl.haxx.se/](http://curl.haxx.se/) .
|
10
|
-
|
11
|
-
Curb is a work-in-progress, and currently only supports libcurl's 'easy' and 'multi' modes.
|
12
|
-
|
13
|
-
## License
|
14
|
-
|
15
|
-
Curb is copyright (c)2006 Ross Bamford, and released under the terms of the
|
16
|
-
Ruby license. See the LICENSE file for the gory details.
|
17
|
-
|
18
|
-
## You will need
|
19
|
-
|
20
|
-
+ A working Ruby installation (1.8+, tested with 1.8.6, 1.8.7, 1.9.1, and 1.9.2)
|
21
|
-
+ A working (lib)curl installation, with development stuff (7.5+, tested with 7.19.x)
|
22
|
-
+ A sane build environment (e.g. gcc, make)
|
23
|
-
|
24
|
-
## Installation...
|
25
|
-
|
26
|
-
... will usually be as simple as:
|
27
|
-
|
28
|
-
$ gem install curb
|
29
|
-
|
30
|
-
Or, if you downloaded the archive:
|
31
|
-
|
32
|
-
$ rake install
|
33
|
-
|
34
|
-
If you have a wierd setup, you might need extconf options. In this case, pass
|
35
|
-
them like so:
|
36
|
-
|
37
|
-
$ rake install EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever'
|
38
|
-
|
39
|
-
Curb is tested only on GNU/Linux x86 and Mac OSX - YMMV on other platforms.
|
40
|
-
If you do use another platform and experience problems, or if you can
|
41
|
-
expand on the above instructions, please report the issue at http://github.com/taf2/curb/issues
|
42
|
-
|
43
|
-
On Ubuntu, the dependencies can be satisfied by installing the following packages:
|
44
|
-
|
45
|
-
$ sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev
|
46
|
-
|
47
|
-
Curb has fairly extensive RDoc comments in the source. You can build the
|
48
|
-
documentation with:
|
49
|
-
|
50
|
-
$ rake doc
|
51
|
-
|
52
|
-
## Usage & examples
|
53
|
-
|
54
|
-
Curb provides two classes:
|
55
|
-
|
56
|
-
+ Curl::Easy - simple API, for day-to-day tasks.
|
57
|
-
+ Curl::Multi - more advanced API, for operating on multiple URLs simultaneously.
|
58
|
-
|
59
|
-
### Super simple API (less typing)
|
60
|
-
|
61
|
-
http = Curl.get("http://www.google.com/")
|
62
|
-
puts http.body_str
|
63
|
-
|
64
|
-
http = Curl.post("http://www.google.com/", {:foo => "bar"})
|
65
|
-
puts http.body_str
|
66
|
-
|
67
|
-
http = Curl.get("http://www.google.com/") do|http|
|
68
|
-
http.headers['Cookie'] = 'foo=1;bar=2'
|
69
|
-
end
|
70
|
-
puts http.body_str
|
71
|
-
|
72
|
-
### Simple fetch via HTTP:
|
73
|
-
|
74
|
-
c = Curl::Easy.perform("http://www.google.co.uk")
|
75
|
-
puts c.body_str
|
76
|
-
|
77
|
-
Same thing, more manual:
|
78
|
-
|
79
|
-
c = Curl::Easy.new("http://www.google.co.uk")
|
80
|
-
c.perform
|
81
|
-
puts c.body_str
|
82
|
-
|
83
|
-
### Additional config:
|
84
|
-
|
85
|
-
Curl::Easy.perform("http://www.google.co.uk") do |curl|
|
86
|
-
curl.headers["User-Agent"] = "myapp-0.0"
|
87
|
-
curl.verbose = true
|
88
|
-
end
|
89
|
-
|
90
|
-
Same thing, more manual:
|
91
|
-
|
92
|
-
c = Curl::Easy.new("http://www.google.co.uk") do |curl|
|
93
|
-
curl.headers["User-Agent"] = "myapp-0.0"
|
94
|
-
curl.verbose = true
|
95
|
-
end
|
96
|
-
|
97
|
-
c.perform
|
98
|
-
|
99
|
-
### HTTP basic authentication:
|
100
|
-
|
101
|
-
c = Curl::Easy.new("http://github.com/")
|
102
|
-
c.http_auth_types = :basic
|
103
|
-
c.username = 'foo'
|
104
|
-
c.password = 'bar'
|
105
|
-
c.perform
|
106
|
-
|
107
|
-
### Supplying custom handlers:
|
108
|
-
|
109
|
-
c = Curl::Easy.new("http://www.google.co.uk")
|
110
|
-
|
111
|
-
c.on_body { |data| print(data) }
|
112
|
-
c.on_header { |data| print(data) }
|
113
|
-
|
114
|
-
c.perform
|
115
|
-
|
116
|
-
### Reusing Curls:
|
117
|
-
|
118
|
-
c = Curl::Easy.new
|
119
|
-
|
120
|
-
["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
|
121
|
-
c.url = url
|
122
|
-
c.perform
|
123
|
-
c.body_str
|
124
|
-
end
|
125
|
-
|
126
|
-
### HTTP POST form:
|
127
|
-
|
128
|
-
c = Curl::Easy.http_post("http://my.rails.box/thing/create",
|
129
|
-
Curl::PostField.content('thing[name]', 'box'),
|
130
|
-
Curl::PostField.content('thing[type]', 'storage'))
|
131
|
-
|
132
|
-
### HTTP POST file upload:
|
133
|
-
|
134
|
-
c = Curl::Easy.new("http://my.rails.box/files/upload")
|
135
|
-
c.multipart_form_post = true
|
136
|
-
c.http_post(Curl::PostField.file('thing[file]', 'myfile.rb'))
|
137
|
-
|
138
|
-
### Multi Interface (Basic HTTP GET):
|
139
|
-
|
140
|
-
# make multiple GET requests
|
141
|
-
easy_options = {:follow_location => true}
|
142
|
-
multi_options = {:pipeline => true}
|
143
|
-
|
144
|
-
Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
|
145
|
-
# do something interesting with the easy response
|
146
|
-
puts easy.last_effective_url
|
147
|
-
end
|
148
|
-
|
149
|
-
### Multi Interface (Basic HTTP POST):
|
150
|
-
|
151
|
-
# make multiple POST requests
|
152
|
-
easy_options = {:follow_location => true, :multipart_form_post => true}
|
153
|
-
multi_options = {:pipeline => true}
|
154
|
-
|
155
|
-
url_fields = [
|
156
|
-
{ :url => 'url1', :post_fields => {'f1' => 'v1'} },
|
157
|
-
{ :url => 'url2', :post_fields => {'f1' => 'v1'} },
|
158
|
-
{ :url => 'url3', :post_fields => {'f1' => 'v1'} }
|
159
|
-
]
|
160
|
-
|
161
|
-
Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
|
162
|
-
# do something interesting with the easy response
|
163
|
-
puts easy.last_effective_url
|
164
|
-
end
|
165
|
-
|
166
|
-
### Multi Interface (Advanced):
|
167
|
-
|
168
|
-
responses = {}
|
169
|
-
requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
|
170
|
-
m = Curl::Multi.new
|
171
|
-
# add a few easy handles
|
172
|
-
requests.each do |url|
|
173
|
-
responses[url] = ""
|
174
|
-
c = Curl::Easy.new(url) do|curl|
|
175
|
-
curl.follow_location = true
|
176
|
-
curl.on_body{|data| responses[url] << data; data.size }
|
177
|
-
curl.on_success {|easy| puts "success, add more easy handles" }
|
178
|
-
end
|
179
|
-
m.add(c)
|
180
|
-
end
|
181
|
-
|
182
|
-
m.perform do
|
183
|
-
puts "idling... can do some work here"
|
184
|
-
end
|
185
|
-
|
186
|
-
requests.each do|url|
|
187
|
-
puts responses[url]
|
188
|
-
end
|
189
|
-
|
190
|
-
### Easy Callbacks
|
191
|
-
|
192
|
-
on_success: is called when the response code is 20x
|
193
|
-
on_failure: is called when the response code is not success, including redirects e.g. 30x
|
194
|
-
on_complete: is called in all cases.
|