curb 0.8.4 → 0.9.11
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.markdown +277 -0
- data/Rakefile +29 -18
- data/ext/banned.h +32 -0
- data/ext/curb.c +161 -46
- data/ext/curb.h +14 -10
- data/ext/curb_easy.c +612 -97
- data/ext/curb_easy.h +6 -0
- data/ext/curb_errors.c +113 -16
- data/ext/curb_errors.h +8 -5
- data/ext/curb_macros.h +7 -7
- data/ext/curb_multi.c +175 -167
- data/ext/curb_multi.h +0 -1
- data/ext/curb_upload.c +2 -2
- data/ext/extconf.rb +52 -17
- data/lib/curb.rb +1 -0
- data/lib/curl/easy.rb +79 -59
- data/lib/curl/multi.rb +59 -20
- data/lib/curl.rb +15 -9
- data/tests/bug_crash_on_progress.rb +41 -1
- data/tests/bug_issue102.rb +1 -1
- data/tests/bug_issue277.rb +32 -0
- data/tests/helper.rb +102 -13
- data/tests/tc_curl.rb +31 -1
- data/tests/tc_curl_download.rb +4 -4
- data/tests/tc_curl_easy.rb +197 -42
- data/tests/tc_curl_easy_resolve.rb +16 -0
- data/tests/tc_curl_maxfilesize.rb +12 -0
- data/tests/tc_curl_multi.rb +82 -16
- data/tests/tc_curl_postfield.rb +29 -29
- data/tests/timeout.rb +10 -2
- metadata +51 -52
- data/README +0 -194
data/tests/tc_curl_postfield.rb
CHANGED
|
@@ -2,63 +2,63 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|
|
2
2
|
|
|
3
3
|
class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
4
4
|
def test_private_new
|
|
5
|
-
assert_raise(NoMethodError) { Curl::PostField.new }
|
|
5
|
+
assert_raise(NoMethodError) { Curl::PostField.new }
|
|
6
6
|
end
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
def test_new_content_01
|
|
9
9
|
pf = Curl::PostField.content('foo', 'bar')
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
assert_equal 'foo', pf.name
|
|
12
12
|
assert_equal 'bar', pf.content
|
|
13
13
|
assert_nil pf.content_type
|
|
14
14
|
assert_nil pf.local_file
|
|
15
|
-
assert_nil pf.remote_file
|
|
15
|
+
assert_nil pf.remote_file
|
|
16
16
|
assert_nil pf.set_content_proc
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def test_new_content_02
|
|
20
20
|
pf = Curl::PostField.content('foo', 'bar', 'text/html')
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
assert_equal 'foo', pf.name
|
|
23
23
|
assert_equal 'bar', pf.content
|
|
24
24
|
assert_equal 'text/html', pf.content_type
|
|
25
25
|
assert_nil pf.local_file
|
|
26
26
|
assert_nil pf.remote_file
|
|
27
|
-
assert_nil pf.set_content_proc
|
|
28
|
-
end
|
|
29
|
-
|
|
27
|
+
assert_nil pf.set_content_proc
|
|
28
|
+
end
|
|
29
|
+
|
|
30
30
|
def test_new_content_03
|
|
31
31
|
l = lambda { |field| "never gets run" }
|
|
32
32
|
pf = Curl::PostField.content('foo', &l)
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
assert_equal 'foo', pf.name
|
|
35
35
|
assert_nil pf.content
|
|
36
36
|
assert_nil pf.content_type
|
|
37
37
|
assert_nil pf.local_file
|
|
38
38
|
assert_nil pf.remote_file
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
# N.B. This doesn't just get the proc, but also removes it.
|
|
41
41
|
assert_equal l, pf.set_content_proc
|
|
42
|
-
end
|
|
42
|
+
end
|
|
43
43
|
|
|
44
44
|
def test_new_content_04
|
|
45
45
|
l = lambda { |field| "never gets run" }
|
|
46
46
|
pf = Curl::PostField.content('foo', 'text/html', &l)
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
assert_equal 'foo', pf.name
|
|
49
49
|
assert_nil pf.content
|
|
50
50
|
assert_equal 'text/html', pf.content_type
|
|
51
51
|
assert_nil pf.local_file
|
|
52
52
|
assert_nil pf.remote_file
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
# N.B. This doesn't just get the proc, but also removes it.
|
|
55
55
|
assert_equal l, pf.set_content_proc
|
|
56
|
-
end
|
|
56
|
+
end
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def test_new_file_01
|
|
60
60
|
pf = Curl::PostField.file('foo', 'localname')
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
assert_equal 'foo', pf.name
|
|
63
63
|
assert_equal 'localname', pf.local_file
|
|
64
64
|
assert_equal 'localname', pf.remote_file
|
|
@@ -67,44 +67,44 @@ class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
|
67
67
|
assert_nil pf.content
|
|
68
68
|
assert_nil pf.set_content_proc
|
|
69
69
|
end
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
def test_new_file_02
|
|
72
72
|
pf = Curl::PostField.file('foo', 'localname', 'remotename')
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
assert_equal 'foo', pf.name
|
|
75
75
|
assert_equal 'localname', pf.local_file
|
|
76
76
|
assert_equal 'remotename', pf.remote_file
|
|
77
77
|
assert_nil pf.content_type
|
|
78
78
|
assert_nil pf.content
|
|
79
79
|
assert_nil pf.set_content_proc
|
|
80
|
-
end
|
|
81
|
-
|
|
80
|
+
end
|
|
81
|
+
|
|
82
82
|
def test_new_file_03
|
|
83
83
|
l = lambda { |field| "never gets run" }
|
|
84
84
|
pf = Curl::PostField.file('foo', 'remotename', &l)
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
assert_equal 'foo', pf.name
|
|
87
87
|
assert_equal 'remotename', pf.remote_file
|
|
88
88
|
assert_nil pf.local_file
|
|
89
89
|
assert_nil pf.content_type
|
|
90
90
|
assert_nil pf.content
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
# N.B. This doesn't just get the proc, but also removes it.
|
|
93
93
|
assert_equal l, pf.set_content_proc
|
|
94
|
-
end
|
|
94
|
+
end
|
|
95
95
|
|
|
96
96
|
def test_new_file_04
|
|
97
97
|
assert_raise(ArgumentError) do
|
|
98
98
|
# no local name, no block
|
|
99
99
|
Curl::PostField.file('foo')
|
|
100
100
|
end
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
assert_raise(ArgumentError) do
|
|
103
103
|
# no remote name with block
|
|
104
104
|
Curl::PostField.file('foo') { |field| "never runs" }
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
def test_new_file_05
|
|
109
109
|
# local gets ignored when supplying a block, but remote
|
|
110
110
|
# is still set up properly.
|
|
@@ -118,15 +118,15 @@ class TestCurbCurlPostfield < Test::Unit::TestCase
|
|
|
118
118
|
assert_nil pf.content
|
|
119
119
|
|
|
120
120
|
assert_equal l, pf.set_content_proc
|
|
121
|
-
end
|
|
122
|
-
|
|
121
|
+
end
|
|
122
|
+
|
|
123
123
|
def test_to_s_01
|
|
124
|
-
pf = Curl::PostField.content('foo', 'bar')
|
|
124
|
+
pf = Curl::PostField.content('foo', 'bar')
|
|
125
125
|
assert_equal "foo=bar", pf.to_s
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
def test_to_s_02
|
|
129
|
-
pf = Curl::PostField.content('foo', 'bar ton')
|
|
129
|
+
pf = Curl::PostField.content('foo', 'bar ton')
|
|
130
130
|
assert_equal "foo=bar%20ton", pf.to_s
|
|
131
131
|
end
|
|
132
132
|
|
data/tests/timeout.rb
CHANGED
|
@@ -13,7 +13,7 @@ class TestCurbTimeouts < Test::Unit::TestCase
|
|
|
13
13
|
elapsed = Time.now - start
|
|
14
14
|
assert elapsed > 2
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
def test_overall_timeout_on_dead_transfer
|
|
18
18
|
curl = Curl::Easy.new(wait_url(2))
|
|
19
19
|
curl.timeout = 1
|
|
@@ -21,7 +21,15 @@ class TestCurbTimeouts < Test::Unit::TestCase
|
|
|
21
21
|
curl.http_get
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
def test_overall_timeout_ms_on_dead_transfer
|
|
26
|
+
curl = Curl::Easy.new(wait_url(2))
|
|
27
|
+
curl.timeout_ms = 1000
|
|
28
|
+
assert_raise(Curl::Err::TimeoutError) do
|
|
29
|
+
curl.http_get
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
25
33
|
def test_clearing_timeout
|
|
26
34
|
curl = Curl::Easy.new(wait_url(2))
|
|
27
35
|
curl.timeout = 1
|
metadata
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: curb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.9.11
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Ross Bamford
|
|
9
8
|
- Todd A. Fisher
|
|
10
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date:
|
|
12
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
|
14
13
|
dependencies: []
|
|
15
14
|
description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings
|
|
16
15
|
for the libcurl(3), a fully-featured client-side URL transfer library. cURL and
|
|
@@ -21,30 +20,31 @@ extensions:
|
|
|
21
20
|
- ext/extconf.rb
|
|
22
21
|
extra_rdoc_files:
|
|
23
22
|
- LICENSE
|
|
24
|
-
- README
|
|
23
|
+
- README.markdown
|
|
25
24
|
files:
|
|
26
25
|
- LICENSE
|
|
27
|
-
- README
|
|
26
|
+
- README.markdown
|
|
28
27
|
- Rakefile
|
|
29
28
|
- doc.rb
|
|
30
|
-
- ext/
|
|
31
|
-
- lib/curb.rb
|
|
32
|
-
- lib/curl/easy.rb
|
|
33
|
-
- lib/curl/multi.rb
|
|
34
|
-
- lib/curl.rb
|
|
29
|
+
- ext/banned.h
|
|
35
30
|
- ext/curb.c
|
|
36
|
-
- ext/curb_easy.c
|
|
37
|
-
- ext/curb_errors.c
|
|
38
|
-
- ext/curb_multi.c
|
|
39
|
-
- ext/curb_postfield.c
|
|
40
|
-
- ext/curb_upload.c
|
|
41
31
|
- ext/curb.h
|
|
32
|
+
- ext/curb_easy.c
|
|
42
33
|
- ext/curb_easy.h
|
|
34
|
+
- ext/curb_errors.c
|
|
43
35
|
- ext/curb_errors.h
|
|
44
36
|
- ext/curb_macros.h
|
|
37
|
+
- ext/curb_multi.c
|
|
45
38
|
- ext/curb_multi.h
|
|
39
|
+
- ext/curb_postfield.c
|
|
46
40
|
- ext/curb_postfield.h
|
|
41
|
+
- ext/curb_upload.c
|
|
47
42
|
- ext/curb_upload.h
|
|
43
|
+
- ext/extconf.rb
|
|
44
|
+
- lib/curb.rb
|
|
45
|
+
- lib/curl.rb
|
|
46
|
+
- lib/curl/easy.rb
|
|
47
|
+
- lib/curl/multi.rb
|
|
48
48
|
- tests/alltests.rb
|
|
49
49
|
- tests/bug_crash_on_debug.rb
|
|
50
50
|
- tests/bug_crash_on_progress.rb
|
|
@@ -52,6 +52,7 @@ files:
|
|
|
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
54
|
- tests/bug_issue102.rb
|
|
55
|
+
- tests/bug_issue277.rb
|
|
55
56
|
- tests/bug_multi_segfault.rb
|
|
56
57
|
- tests/bug_postfields_crash.rb
|
|
57
58
|
- tests/bug_postfields_crash2.rb
|
|
@@ -64,68 +65,66 @@ files:
|
|
|
64
65
|
- tests/tc_curl.rb
|
|
65
66
|
- tests/tc_curl_download.rb
|
|
66
67
|
- tests/tc_curl_easy.rb
|
|
68
|
+
- tests/tc_curl_easy_resolve.rb
|
|
67
69
|
- tests/tc_curl_easy_setopt.rb
|
|
70
|
+
- tests/tc_curl_maxfilesize.rb
|
|
68
71
|
- tests/tc_curl_multi.rb
|
|
69
72
|
- tests/tc_curl_postfield.rb
|
|
70
73
|
- tests/timeout.rb
|
|
71
74
|
- tests/timeout_server.rb
|
|
72
75
|
- tests/unittests.rb
|
|
73
|
-
homepage:
|
|
74
|
-
licenses:
|
|
75
|
-
|
|
76
|
+
homepage: https://github.com/taf2/curb
|
|
77
|
+
licenses:
|
|
78
|
+
- MIT
|
|
79
|
+
metadata: {}
|
|
80
|
+
post_install_message:
|
|
76
81
|
rdoc_options:
|
|
77
|
-
- --main
|
|
78
|
-
- README
|
|
82
|
+
- "--main"
|
|
83
|
+
- README.markdown
|
|
79
84
|
require_paths:
|
|
80
85
|
- lib
|
|
81
86
|
- ext
|
|
82
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
|
-
none: false
|
|
84
88
|
requirements:
|
|
85
|
-
- -
|
|
89
|
+
- - ">="
|
|
86
90
|
- !ruby/object:Gem::Version
|
|
87
91
|
version: '0'
|
|
88
|
-
segments:
|
|
89
|
-
- 0
|
|
90
|
-
hash: -243569426931689339
|
|
91
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
-
none: false
|
|
93
93
|
requirements:
|
|
94
|
-
- -
|
|
94
|
+
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
|
-
segments:
|
|
98
|
-
- 0
|
|
99
|
-
hash: -243569426931689339
|
|
100
97
|
requirements: []
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
specification_version: 3
|
|
98
|
+
rubygems_version: 3.0.8
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 4
|
|
105
101
|
summary: Ruby libcurl bindings
|
|
106
102
|
test_files:
|
|
103
|
+
- tests/tc_curl_multi.rb
|
|
107
104
|
- tests/alltests.rb
|
|
108
|
-
- tests/
|
|
109
|
-
- tests/
|
|
110
|
-
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
|
111
|
-
- tests/bug_curb_easy_post_with_string_no_content_length_header.rb
|
|
112
|
-
- tests/bug_instance_post_differs_from_class_post.rb
|
|
113
|
-
- tests/bug_issue102.rb
|
|
114
|
-
- tests/bug_multi_segfault.rb
|
|
105
|
+
- tests/tc_curl_easy_setopt.rb
|
|
106
|
+
- tests/tc_curl.rb
|
|
115
107
|
- tests/bug_postfields_crash.rb
|
|
108
|
+
- tests/bug_crash_on_progress.rb
|
|
109
|
+
- tests/helper.rb
|
|
110
|
+
- tests/bug_issue277.rb
|
|
116
111
|
- tests/bug_postfields_crash2.rb
|
|
117
112
|
- tests/bug_require_last_or_segfault.rb
|
|
118
|
-
- tests/
|
|
119
|
-
- tests/
|
|
120
|
-
- tests/
|
|
113
|
+
- tests/timeout.rb
|
|
114
|
+
- tests/bug_crash_on_debug.rb
|
|
115
|
+
- tests/unittests.rb
|
|
116
|
+
- tests/bug_issue102.rb
|
|
117
|
+
- tests/bug_curb_easy_blocks_ruby_threads.rb
|
|
118
|
+
- tests/bug_multi_segfault.rb
|
|
119
|
+
- tests/bug_instance_post_differs_from_class_post.rb
|
|
121
120
|
- tests/require_last_or_segfault_script.rb
|
|
122
|
-
- tests/
|
|
123
|
-
- tests/tc_curl.rb
|
|
121
|
+
- tests/timeout_server.rb
|
|
124
122
|
- tests/tc_curl_download.rb
|
|
125
123
|
- tests/tc_curl_easy.rb
|
|
126
|
-
- tests/
|
|
127
|
-
- tests/tc_curl_multi.rb
|
|
124
|
+
- tests/mem_check.rb
|
|
128
125
|
- tests/tc_curl_postfield.rb
|
|
129
|
-
- tests/
|
|
130
|
-
- tests/
|
|
131
|
-
- tests/
|
|
126
|
+
- tests/tc_curl_maxfilesize.rb
|
|
127
|
+
- tests/bugtests.rb
|
|
128
|
+
- tests/tc_curl_easy_resolve.rb
|
|
129
|
+
- tests/signals.rb
|
|
130
|
+
- tests/bug_curb_easy_post_with_string_no_content_length_header.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.
|