curb 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +6 -0
- data/ext/curb.c +3 -0
- data/ext/curb.h +3 -3
- data/ext/curb_easy.c +46 -4
- data/ext/curb_multi.c +12 -50
- data/ext/extconf.rb +7 -0
- data/lib/curl.rb +3 -8
- data/tests/helper.rb +9 -7
- data/tests/tc_curl_download.rb +3 -3
- data/tests/tc_curl_easy.rb +36 -27
- data/tests/tc_curl_multi.rb +9 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f745e8a670b83facff3af44169290e38d59fc087
|
4
|
+
data.tar.gz: 23258e4b6f84aaec880ffb050c8fd774f82728a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f79f4530412869086922114a4a9170acd57e5a8b68c43b19616a3d31609d9f85ef94bf890cad9b57cdd4f7a59bf1257eeb7d20ca40781e72ec4a2f03fe91711
|
7
|
+
data.tar.gz: 5f67114460a69c76e6e7835124e26825833c8de153232ba10bab032732481e2c694baf54976dcba80cd43fce37a75f1267a9e9c507d369dead6c924ebb829b67
|
data/README.markdown
CHANGED
@@ -65,6 +65,12 @@ Curb provides two classes:
|
|
65
65
|
* `Curl::Easy` - simple API, for day-to-day tasks.
|
66
66
|
* `Curl::Multi` - more advanced API, for operating on multiple URLs simultaneously.
|
67
67
|
|
68
|
+
To use either, you will need to require the curb gem:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'curb'
|
72
|
+
```
|
73
|
+
|
68
74
|
### Super simple API (less typing)
|
69
75
|
|
70
76
|
```ruby
|
data/ext/curb.c
CHANGED
@@ -398,6 +398,9 @@ void Init_curb_core() {
|
|
398
398
|
CURB_DEFINE(CURLOPT_HEADER);
|
399
399
|
CURB_DEFINE(CURLOPT_NOPROGRESS);
|
400
400
|
CURB_DEFINE(CURLOPT_NOSIGNAL);
|
401
|
+
#if HAVE_CURLOPT_PATH_AS_IS
|
402
|
+
CURB_DEFINE(CURLOPT_PATH_AS_IS);
|
403
|
+
#endif
|
401
404
|
CURB_DEFINE(CURLOPT_WRITEFUNCTION);
|
402
405
|
CURB_DEFINE(CURLOPT_WRITEDATA);
|
403
406
|
CURB_DEFINE(CURLOPT_READFUNCTION);
|
data/ext/curb.h
CHANGED
@@ -20,10 +20,10 @@
|
|
20
20
|
#include "curb_macros.h"
|
21
21
|
|
22
22
|
// These should be managed from the Rake 'release' task.
|
23
|
-
#define CURB_VERSION "0.9.
|
24
|
-
#define CURB_VER_NUM
|
23
|
+
#define CURB_VERSION "0.9.4"
|
24
|
+
#define CURB_VER_NUM 904
|
25
25
|
#define CURB_VER_MAJ 0
|
26
|
-
#define CURB_VER_MIN
|
26
|
+
#define CURB_VER_MIN 4
|
27
27
|
#define CURB_VER_MIC 0
|
28
28
|
#define CURB_VER_PATCH 0
|
29
29
|
|
data/ext/curb_easy.c
CHANGED
@@ -228,6 +228,16 @@ static void ruby_curl_easy_free(ruby_curl_easy *rbce) {
|
|
228
228
|
}
|
229
229
|
|
230
230
|
if (rbce->curl) {
|
231
|
+
/* disable any progress or debug events */
|
232
|
+
curl_easy_setopt(rbce->curl, CURLOPT_WRITEFUNCTION, NULL);
|
233
|
+
curl_easy_setopt(rbce->curl, CURLOPT_WRITEDATA, NULL);
|
234
|
+
curl_easy_setopt(rbce->curl, CURLOPT_HEADERFUNCTION, NULL);
|
235
|
+
curl_easy_setopt(rbce->curl, CURLOPT_HEADERDATA, NULL);
|
236
|
+
curl_easy_setopt(rbce->curl, CURLOPT_DEBUGFUNCTION, NULL);
|
237
|
+
curl_easy_setopt(rbce->curl, CURLOPT_DEBUGDATA, NULL);
|
238
|
+
curl_easy_setopt(rbce->curl, CURLOPT_VERBOSE, 0);
|
239
|
+
curl_easy_setopt(rbce->curl, CURLOPT_PROGRESSFUNCTION, NULL);
|
240
|
+
curl_easy_setopt(rbce->curl, CURLOPT_NOPROGRESS, 1);
|
231
241
|
curl_easy_cleanup(rbce->curl);
|
232
242
|
}
|
233
243
|
}
|
@@ -3072,12 +3082,40 @@ static VALUE ruby_curl_easy_num_connects_get(VALUE self) {
|
|
3072
3082
|
}
|
3073
3083
|
|
3074
3084
|
|
3075
|
-
/*
|
3085
|
+
/*
|
3086
|
+
* call-seq:
|
3087
|
+
* easy.cookielist => array
|
3088
|
+
*
|
3089
|
+
* Retrieves the cookies curl knows in an array of strings.
|
3090
|
+
* Returned strings are in Netscape cookiejar format or in Set-Cookie format.
|
3091
|
+
*
|
3092
|
+
* See also option CURLINFO_COOKIELIST of curl_easy_getopt(3) to see how libcurl behaves.
|
3093
|
+
*
|
3094
|
+
* (requires libcurl 7.14.1 or higher, otherwise -1 is always returned).
|
3095
|
+
*/
|
3096
|
+
static VALUE ruby_curl_easy_cookielist_get(VALUE self) {
|
3097
|
+
#ifdef HAVE_CURLINFO_COOKIELIST
|
3098
|
+
ruby_curl_easy *rbce;
|
3099
|
+
struct curl_slist *cookies;
|
3100
|
+
struct curl_slist *cookie;
|
3101
|
+
VALUE rb_cookies;
|
3076
3102
|
|
3077
|
-
|
3103
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
3104
|
+
curl_easy_getinfo(rbce->curl, CURLINFO_COOKIELIST, &cookies);
|
3105
|
+
if (!cookies)
|
3106
|
+
return Qnil;
|
3107
|
+
rb_cookies = rb_ary_new();
|
3108
|
+
for (cookie = cookies; cookie; cookie = cookie->next)
|
3109
|
+
rb_ary_push(rb_cookies, rb_str_new2(cookie->data));
|
3110
|
+
curl_slist_free_all(cookies);
|
3111
|
+
return rb_cookies;
|
3112
|
+
|
3113
|
+
#else
|
3114
|
+
rb_warn("Installed libcurl is too old to support cookielist");
|
3115
|
+
return INT2FIX(-1);
|
3116
|
+
#endif
|
3117
|
+
}
|
3078
3118
|
|
3079
|
-
Pass a pointer to a 'struct curl_slist *' to receive a linked-list of all cookies cURL knows (expired ones, too). Don't forget to curl_slist_free_all(3) the list after it has been used. If there are no cookies (cookies for the handle have not been enabled or simply none have been received) 'struct curl_slist *' will be set to point to NULL. (Added in 7.14.1)
|
3080
|
-
*/
|
3081
3119
|
|
3082
3120
|
/* TODO this needs to be implemented. Could probably support CONNECT_ONLY by having this
|
3083
3121
|
* return an open Socket or something.
|
@@ -3193,6 +3231,9 @@ static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
|
|
3193
3231
|
case CURLOPT_HEADER:
|
3194
3232
|
case CURLOPT_NOPROGRESS:
|
3195
3233
|
case CURLOPT_NOSIGNAL:
|
3234
|
+
#if HAVE_CURLOPT_PATH_AS_IS
|
3235
|
+
case CURLOPT_PATH_AS_IS:
|
3236
|
+
#endif
|
3196
3237
|
case CURLOPT_HTTPGET:
|
3197
3238
|
case CURLOPT_NOBODY: {
|
3198
3239
|
int type = rb_type(val);
|
@@ -3536,6 +3577,7 @@ void init_curb_easy() {
|
|
3536
3577
|
rb_define_method(cCurlEasy, "content_type", ruby_curl_easy_content_type_get, 0);
|
3537
3578
|
rb_define_method(cCurlEasy, "os_errno", ruby_curl_easy_os_errno_get, 0);
|
3538
3579
|
rb_define_method(cCurlEasy, "num_connects", ruby_curl_easy_num_connects_get, 0);
|
3580
|
+
rb_define_method(cCurlEasy, "cookielist", ruby_curl_easy_cookielist_get, 0);
|
3539
3581
|
rb_define_method(cCurlEasy, "ftp_entry_path", ruby_curl_easy_ftp_entry_path_get, 0);
|
3540
3582
|
|
3541
3583
|
rb_define_method(cCurlEasy, "close", ruby_curl_easy_close, 0);
|
data/ext/curb_multi.c
CHANGED
@@ -79,9 +79,7 @@ void curl_multi_free(ruby_curl_multi *rbcm) {
|
|
79
79
|
rbcm->requests = Qnil;
|
80
80
|
}
|
81
81
|
|
82
|
-
|
83
|
-
curl_multi_cleanup(rbcm->handle);
|
84
|
-
}
|
82
|
+
curl_multi_cleanup(rbcm->handle);
|
85
83
|
free(rbcm);
|
86
84
|
}
|
87
85
|
|
@@ -194,13 +192,6 @@ static VALUE ruby_curl_multi_max_connects(VALUE self, VALUE count) {
|
|
194
192
|
|
195
193
|
Data_Get_Struct(self, ruby_curl_multi, rbcm);
|
196
194
|
|
197
|
-
if (!rbcm->handle) {
|
198
|
-
rbcm->handle = curl_multi_init();
|
199
|
-
if (!rbcm->handle) {
|
200
|
-
rb_raise(mCurlErrFailedInit, "Failed to initialize multi handle");
|
201
|
-
}
|
202
|
-
}
|
203
|
-
|
204
195
|
curl_multi_setopt(rbcm->handle, CURLMOPT_MAXCONNECTS, NUM2LONG(count));
|
205
196
|
#endif
|
206
197
|
|
@@ -234,14 +225,6 @@ static VALUE ruby_curl_multi_pipeline(VALUE self, VALUE method) {
|
|
234
225
|
}
|
235
226
|
|
236
227
|
Data_Get_Struct(self, ruby_curl_multi, rbcm);
|
237
|
-
|
238
|
-
if (!rbcm->handle) {
|
239
|
-
rbcm->handle = curl_multi_init();
|
240
|
-
if (!rbcm->handle) {
|
241
|
-
rb_raise(mCurlErrFailedInit, "Failed to initialize multi handle");
|
242
|
-
}
|
243
|
-
}
|
244
|
-
|
245
228
|
curl_multi_setopt(rbcm->handle, CURLMOPT_PIPELINING, value);
|
246
229
|
#endif
|
247
230
|
return method == Qtrue ? 1 : 0;
|
@@ -274,13 +257,6 @@ VALUE ruby_curl_multi_add(VALUE self, VALUE easy) {
|
|
274
257
|
/* setup the easy handle */
|
275
258
|
ruby_curl_easy_setup( rbce );
|
276
259
|
|
277
|
-
if (!rbcm->handle) {
|
278
|
-
rbcm->handle = curl_multi_init();
|
279
|
-
if (!rbcm->handle) {
|
280
|
-
rb_raise(mCurlErrFailedInit, "Failed to initialize multi handle");
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
260
|
mcode = curl_multi_add_handle(rbcm->handle, rbce->curl);
|
285
261
|
if (mcode != CURLM_CALL_MULTI_PERFORM && mcode != CURLM_OK) {
|
286
262
|
raise_curl_multi_error_exception(mcode);
|
@@ -319,13 +295,6 @@ VALUE ruby_curl_multi_remove(VALUE self, VALUE easy) {
|
|
319
295
|
|
320
296
|
Data_Get_Struct(self, ruby_curl_multi, rbcm);
|
321
297
|
|
322
|
-
if (!rbcm->handle) {
|
323
|
-
rbcm->handle = curl_multi_init();
|
324
|
-
if (!rbcm->handle) {
|
325
|
-
rb_raise(mCurlErrFailedInit, "Failed to initialize multi handle");
|
326
|
-
}
|
327
|
-
}
|
328
|
-
|
329
298
|
rb_curl_multi_remove(rbcm,easy);
|
330
299
|
|
331
300
|
return self;
|
@@ -376,13 +345,6 @@ static VALUE ruby_curl_multi_cancel(VALUE self) {
|
|
376
345
|
ruby_curl_multi *rbcm;
|
377
346
|
|
378
347
|
Data_Get_Struct(self, ruby_curl_multi, rbcm);
|
379
|
-
|
380
|
-
if (!rbcm->handle) {
|
381
|
-
rbcm->handle = curl_multi_init();
|
382
|
-
if (!rbcm->handle) {
|
383
|
-
rb_raise(mCurlErrFailedInit, "Failed to initialize multi handle");
|
384
|
-
}
|
385
|
-
}
|
386
348
|
|
387
349
|
rb_hash_foreach( rbcm->requests, ruby_curl_multi_cancel_callback, (VALUE)rbcm );
|
388
350
|
|
@@ -505,11 +467,10 @@ static void rb_curl_multi_run(VALUE self, CURLM *multi_handle, int *still_runnin
|
|
505
467
|
mcode = curl_multi_perform(multi_handle, still_running);
|
506
468
|
} while (mcode == CURLM_CALL_MULTI_PERFORM);
|
507
469
|
|
508
|
-
|
509
470
|
if (mcode != CURLM_OK) {
|
510
471
|
raise_curl_multi_error_exception(mcode);
|
511
472
|
}
|
512
|
-
|
473
|
+
|
513
474
|
}
|
514
475
|
|
515
476
|
#ifdef _WIN32
|
@@ -634,6 +595,15 @@ VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
|
|
634
595
|
raise_curl_multi_error_exception(mcode);
|
635
596
|
}
|
636
597
|
|
598
|
+
if (maxfd == -1) {
|
599
|
+
/* libcurl recommends sleeping for 100ms */
|
600
|
+
rb_thread_wait_for(rb_time_timeval(DBL2NUM(0.1)));
|
601
|
+
rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
|
602
|
+
rb_curl_multi_read_info( self, rbcm->handle );
|
603
|
+
if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
|
604
|
+
continue;
|
605
|
+
}
|
606
|
+
|
637
607
|
#ifdef _WIN32
|
638
608
|
create_crt_fd(&fdread, &crt_fdread);
|
639
609
|
create_crt_fd(&fdwrite, &crt_fdwrite);
|
@@ -683,15 +653,7 @@ VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
|
|
683
653
|
|
684
654
|
rb_curl_multi_read_info( self, rbcm->handle );
|
685
655
|
if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
|
686
|
-
|
687
|
-
/* do early cleanup */
|
688
|
-
VALUE hash = rbcm->requests;
|
689
|
-
if (!NIL_P(hash) && rb_type(hash) == T_HASH && RHASH_SIZE(hash) > 0) {
|
690
|
-
rb_hash_foreach(hash, curl_multi_flush_easy, (VALUE)rbcm);
|
691
|
-
}
|
692
|
-
curl_multi_cleanup(rbcm->handle);
|
693
|
-
rbcm->handle = NULL;
|
694
|
-
|
656
|
+
|
695
657
|
return Qtrue;
|
696
658
|
}
|
697
659
|
|
data/ext/extconf.rb
CHANGED
@@ -66,6 +66,7 @@ have_constant "curlinfo_filetime"
|
|
66
66
|
have_constant "curlinfo_redirect_count"
|
67
67
|
have_constant "curlinfo_os_errno"
|
68
68
|
have_constant "curlinfo_num_connects"
|
69
|
+
have_constant "curlinfo_cookielist"
|
69
70
|
have_constant "curlinfo_ftp_entry_path"
|
70
71
|
have_constant "curl_version_ssl"
|
71
72
|
have_constant "curl_version_libz"
|
@@ -101,6 +102,9 @@ have_constant "curle_send_fail_rewind"
|
|
101
102
|
have_constant "curle_ssl_engine_initfailed"
|
102
103
|
have_constant "curle_login_denied"
|
103
104
|
|
105
|
+
# older than 7.16.0
|
106
|
+
have_constant "curlmopt_pipelining"
|
107
|
+
|
104
108
|
# older than 7.16.3
|
105
109
|
have_constant "curlmopt_maxconnects"
|
106
110
|
|
@@ -370,6 +374,9 @@ have_constant "CURLM_ADDED_ALREADY"
|
|
370
374
|
# added in 7.40.0
|
371
375
|
have_constant "curlopt_unix_socket_path"
|
372
376
|
|
377
|
+
# added in 7.42.0
|
378
|
+
have_constant "curlopt_path_as_is"
|
379
|
+
|
373
380
|
if try_compile('int main() { return 0; }','-Wall')
|
374
381
|
$CFLAGS << ' -Wall'
|
375
382
|
end
|
data/lib/curl.rb
CHANGED
@@ -47,14 +47,9 @@ module Curl
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.urlalize(url, params={})
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
elsif query_str.size > 0
|
54
|
-
"#{url}?#{query_str}"
|
55
|
-
else
|
56
|
-
url
|
57
|
-
end
|
50
|
+
uri = URI(url)
|
51
|
+
uri.query = params.map {|k,v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join("&")
|
52
|
+
uri.to_s
|
58
53
|
end
|
59
54
|
|
60
55
|
def self.postalize(params={})
|
data/tests/helper.rb
CHANGED
@@ -18,7 +18,7 @@ rescue LoadError
|
|
18
18
|
end
|
19
19
|
require 'fileutils'
|
20
20
|
|
21
|
-
$TEST_URL = "file://#{URI.escape(File.expand_path(__FILE__).tr('\\','/')
|
21
|
+
$TEST_URL = "file://#{'/' if RUBY_DESCRIPTION =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/}#{URI.escape(File.expand_path(__FILE__).tr('\\','/'))}"
|
22
22
|
|
23
23
|
require 'thread'
|
24
24
|
require 'webrick'
|
@@ -52,13 +52,12 @@ class TestServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.port
|
55
|
-
|
55
|
+
@port ||= 9129
|
56
56
|
end
|
57
57
|
|
58
58
|
def self.path
|
59
59
|
'/methods'
|
60
60
|
end
|
61
|
-
|
62
61
|
def self.url
|
63
62
|
"http://127.0.0.1:#{port}#{path}"
|
64
63
|
end
|
@@ -70,12 +69,12 @@ class TestServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
70
69
|
end
|
71
70
|
|
72
71
|
def do_GET(req,res)
|
73
|
-
if req.path.match
|
72
|
+
if req.path.match(/redirect$/)
|
74
73
|
res.status = 302
|
75
74
|
res['Location'] = '/foo'
|
76
|
-
elsif req.path.match
|
75
|
+
elsif req.path.match(/not_here$/)
|
77
76
|
res.status = 404
|
78
|
-
elsif req.path.match
|
77
|
+
elsif req.path.match(/error$/)
|
79
78
|
res.status = 500
|
80
79
|
end
|
81
80
|
respond_with("GET#{req.query_string}",req,res)
|
@@ -94,6 +93,9 @@ class TestServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
94
93
|
end
|
95
94
|
if params and params['s'] == '500'
|
96
95
|
res.status = 500
|
96
|
+
elsif params and params['c']
|
97
|
+
cookie = URI.decode_www_form(params['c'])[0][0].split('=')
|
98
|
+
res.cookies << WEBrick::Cookie.new(*cookie)
|
97
99
|
else
|
98
100
|
respond_with("POST\n#{req.body}",req,res)
|
99
101
|
end
|
@@ -136,7 +138,7 @@ module TestServerMethods
|
|
136
138
|
|
137
139
|
def server_setup(port=9129,servlet=TestServlet)
|
138
140
|
@__port = port
|
139
|
-
if @server.nil? and !File.exist?(locked_file)
|
141
|
+
if (@server ||= nil).nil? and !File.exist?(locked_file)
|
140
142
|
|
141
143
|
File.open(locked_file,'w') {|f| f << 'locked' }
|
142
144
|
if TEST_SINGLE_THREADED
|
data/tests/tc_curl_download.rb
CHANGED
@@ -11,7 +11,7 @@ class TestCurbCurlDownload < Test::Unit::TestCase
|
|
11
11
|
dl_url = "http://127.0.0.1:9129/ext/curb_easy.c"
|
12
12
|
dl_path = File.join(Dir::tmpdir, "dl_url_test.file")
|
13
13
|
|
14
|
-
|
14
|
+
Curl::Easy.download(dl_url, dl_path)
|
15
15
|
assert File.exist?(dl_path)
|
16
16
|
assert_equal File.read(File.join(File.dirname(__FILE__), '..','ext','curb_easy.c')), File.read(dl_path)
|
17
17
|
ensure
|
@@ -23,7 +23,7 @@ class TestCurbCurlDownload < Test::Unit::TestCase
|
|
23
23
|
dl_path = File.join(Dir::tmpdir, "dl_url_test.file")
|
24
24
|
io = File.open(dl_path, 'wb')
|
25
25
|
|
26
|
-
|
26
|
+
Curl::Easy.download(dl_url, io)
|
27
27
|
assert io.closed?
|
28
28
|
assert File.exist?(dl_path)
|
29
29
|
assert_equal File.read(File.join(File.dirname(__FILE__), '..','ext','curb_easy.c')), File.read(dl_path)
|
@@ -49,7 +49,7 @@ class TestCurbCurlDownload < Test::Unit::TestCase
|
|
49
49
|
# Download remote source
|
50
50
|
begin
|
51
51
|
reader.close
|
52
|
-
|
52
|
+
Curl::Easy.download(dl_url, writer)
|
53
53
|
Process.wait
|
54
54
|
ensure
|
55
55
|
writer.close rescue IOError # if the stream has already been closed, which occurs in Easy::download
|
data/tests/tc_curl_easy.rb
CHANGED
@@ -5,7 +5,7 @@ end
|
|
5
5
|
|
6
6
|
class TestCurbCurlEasy < Test::Unit::TestCase
|
7
7
|
def test_global_reset
|
8
|
-
|
8
|
+
Curl.get($TEST_URL)
|
9
9
|
# in a Timeout block you should reset the thread current handle
|
10
10
|
Curl.reset
|
11
11
|
end
|
@@ -24,7 +24,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
t.each {|
|
27
|
+
t.each {|x| x.join }
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_class_perform_01
|
@@ -44,7 +44,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_class_perform_03
|
47
|
-
assert_raise(Curl::Err::CouldntReadError) {
|
47
|
+
assert_raise(Curl::Err::CouldntReadError) { Curl::Easy.perform($TEST_URL + "nonexistent") }
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_new_01
|
@@ -595,6 +595,15 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
595
595
|
assert_equal "some.file", c.cookiejar
|
596
596
|
end
|
597
597
|
|
598
|
+
def test_cookielist
|
599
|
+
c = Curl::Easy.new TestServlet.url
|
600
|
+
c.enable_cookies = true
|
601
|
+
c.post_body = URI.encode_www_form c: 'somename=somevalue'
|
602
|
+
assert_nil c.cookielist
|
603
|
+
c.perform
|
604
|
+
assert_match(/somevalue/, c.cookielist.join(''))
|
605
|
+
end
|
606
|
+
|
598
607
|
def test_on_success
|
599
608
|
curl = Curl::Easy.new($TEST_URL)
|
600
609
|
on_success_called = false
|
@@ -657,7 +666,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
657
666
|
retries = 0
|
658
667
|
begin
|
659
668
|
count = 0
|
660
|
-
|
669
|
+
Curl::Easy.send("http_#{method}", TestServlet.url) do|c|
|
661
670
|
count += 1
|
662
671
|
assert_equal Curl::Easy, c.class
|
663
672
|
end
|
@@ -679,8 +688,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
679
688
|
Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
680
689
|
]
|
681
690
|
curl.http_post(fields)
|
682
|
-
assert_match
|
683
|
-
assert_match
|
691
|
+
assert_match(/HTTP POST file upload/, curl.body_str)
|
692
|
+
assert_match(/Content-Disposition: form-data/, curl.body_str)
|
684
693
|
end
|
685
694
|
|
686
695
|
def test_post_with_body_remote
|
@@ -706,8 +715,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
706
715
|
curl.multipart_form_post = true
|
707
716
|
pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
|
708
717
|
curl.http_post(pf)
|
709
|
-
assert_match
|
710
|
-
assert_match
|
718
|
+
assert_match(/HTTP POST file upload/, curl.body_str)
|
719
|
+
assert_match(/Content-Disposition: form-data/, curl.body_str)
|
711
720
|
end
|
712
721
|
|
713
722
|
def test_delete_remote
|
@@ -729,7 +738,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
729
738
|
redirect = curl.header_str.match(/Location: (.*)/)
|
730
739
|
|
731
740
|
assert_equal '', curl.body_str
|
732
|
-
assert_match
|
741
|
+
assert_match('/nonexistent', redirect[1])
|
733
742
|
end
|
734
743
|
|
735
744
|
def test_head_accessor
|
@@ -740,7 +749,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
740
749
|
redirect = curl.header_str.match(/Location: (.*)/)
|
741
750
|
|
742
751
|
assert_equal '', curl.body_str
|
743
|
-
assert_match
|
752
|
+
assert_match('/nonexistent', redirect[1])
|
744
753
|
curl.head = false
|
745
754
|
curl.perform
|
746
755
|
assert_equal 'GET', curl.body_str
|
@@ -750,11 +759,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
750
759
|
curl = Curl::Easy.new(TestServlet.url)
|
751
760
|
curl.headers['Content-Type'] = 'application/json'
|
752
761
|
assert curl.http_put("message")
|
753
|
-
assert_match
|
754
|
-
assert_match
|
755
|
-
assert_match
|
756
|
-
assert_match
|
757
|
-
assert_match
|
762
|
+
assert_match(/^PUT/, curl.body_str)
|
763
|
+
assert_match(/message$/, curl.body_str)
|
764
|
+
assert_match(/message$/, curl.body)
|
765
|
+
assert_match(/application\/json/, curl.header_str)
|
766
|
+
assert_match(/application\/json/, curl.head)
|
758
767
|
end
|
759
768
|
|
760
769
|
def test_put_data
|
@@ -763,8 +772,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
763
772
|
|
764
773
|
curl.perform
|
765
774
|
|
766
|
-
assert_match
|
767
|
-
assert_match
|
775
|
+
assert_match(/^PUT/, curl.body_str)
|
776
|
+
assert_match(/message$/, curl.body_str)
|
768
777
|
end
|
769
778
|
|
770
779
|
# https://github.com/taf2/curb/issues/101
|
@@ -774,8 +783,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
774
783
|
|
775
784
|
curl.perform
|
776
785
|
|
777
|
-
assert_match
|
778
|
-
assert_match
|
786
|
+
assert_match(/^PUT/, curl.body_str)
|
787
|
+
assert_match("a\0b", curl.body_str)
|
779
788
|
end
|
780
789
|
|
781
790
|
def test_put_nil_data_no_crash
|
@@ -790,7 +799,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
790
799
|
File.open(__FILE__,'rb') do|f|
|
791
800
|
assert curl.http_put(f)
|
792
801
|
end
|
793
|
-
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
802
|
+
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
|
794
803
|
end
|
795
804
|
|
796
805
|
def test_put_class_method
|
@@ -800,7 +809,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
800
809
|
assert_equal Curl::Easy, c.class
|
801
810
|
end
|
802
811
|
assert_equal 1, count
|
803
|
-
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
|
812
|
+
assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
|
804
813
|
end
|
805
814
|
|
806
815
|
# Generate a self-signed cert with
|
@@ -809,7 +818,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
809
818
|
def test_cert
|
810
819
|
curl = Curl::Easy.new(TestServlet.url)
|
811
820
|
curl.cert= File.join(File.dirname(__FILE__),"cert.pem")
|
812
|
-
assert_match
|
821
|
+
assert_match(/cert.pem$/,curl.cert)
|
813
822
|
end
|
814
823
|
|
815
824
|
def test_cert_with_password
|
@@ -817,7 +826,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
817
826
|
path = File.join(File.dirname(__FILE__),"cert.pem")
|
818
827
|
curl.certpassword = 'password'
|
819
828
|
curl.cert = path
|
820
|
-
assert_match
|
829
|
+
assert_match(/cert.pem$/,curl.cert)
|
821
830
|
end
|
822
831
|
|
823
832
|
def test_cert_type
|
@@ -838,7 +847,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
838
847
|
def test_ca_cert
|
839
848
|
curl = Curl::Easy.new(TestServlet.url)
|
840
849
|
curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")
|
841
|
-
assert_match
|
850
|
+
assert_match(/cacert.pem$/, curl.cacert)
|
842
851
|
end
|
843
852
|
|
844
853
|
def test_user_agent
|
@@ -896,7 +905,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
896
905
|
easy.http_post(pf)
|
897
906
|
|
898
907
|
assert_not_equal(0,easy.body_str.size)
|
899
|
-
assert_equal(easy.body_str,File.read(readme))
|
908
|
+
assert_equal(easy.body_str.tr("\r", ''), File.read(readme))
|
900
909
|
end
|
901
910
|
|
902
911
|
|
@@ -992,8 +1001,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
992
1001
|
curl.headers['Accept'] = '*/*'
|
993
1002
|
curl.headers['Authorization'] = 'Foo Bar Biz Baz'
|
994
1003
|
curl.http_put(rd)
|
995
|
-
assert_match
|
996
|
-
assert_match
|
1004
|
+
assert_match(/^PUT/, curl.body_str)
|
1005
|
+
assert_match(/hello$/, curl.body_str)
|
997
1006
|
curl.header_str
|
998
1007
|
curl.body_str
|
999
1008
|
end
|
data/tests/tc_curl_multi.rb
CHANGED
@@ -331,7 +331,6 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
331
331
|
Curl::Multi.download(urls,{},{},downloads) do|curl,download_path|
|
332
332
|
assert_equal 200, curl.response_code
|
333
333
|
assert File.exist?(download_path)
|
334
|
-
store = file_info[File.basename(download_path)]
|
335
334
|
assert_equal file_info[File.basename(download_path)][:size], File.size(download_path), "incomplete download: #{download_path}"
|
336
335
|
end
|
337
336
|
ensure
|
@@ -346,7 +345,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
346
345
|
]
|
347
346
|
Curl::Multi.post(urls, {:follow_location => true, :multipart_form_post => true}, {:pipeline => true}) do|easy|
|
348
347
|
str = easy.body_str
|
349
|
-
assert_match
|
348
|
+
assert_match(/POST/, str)
|
350
349
|
fields = {}
|
351
350
|
str.gsub(/POST\n/,'').split('&').map{|sv| k, v = sv.split('='); fields[k] = v }
|
352
351
|
expected = urls.find{|s| s[:url] == easy.last_effective_url }
|
@@ -361,8 +360,8 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
361
360
|
{ :url => TestServlet.url, :method => :put, :put_data => "message",
|
362
361
|
:headers => {'Content-Type' => 'application/json' } }]
|
363
362
|
Curl::Multi.put(urls, {}, {:pipeline => true}) do|easy|
|
364
|
-
assert_match
|
365
|
-
assert_match
|
363
|
+
assert_match(/PUT/, easy.body_str)
|
364
|
+
assert_match(/message/, easy.body_str)
|
366
365
|
end
|
367
366
|
end
|
368
367
|
|
@@ -379,11 +378,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
379
378
|
assert_equal nil, code
|
380
379
|
case method
|
381
380
|
when :post
|
382
|
-
assert_match
|
381
|
+
assert_match(/POST/, easy.body_str)
|
383
382
|
when :get
|
384
|
-
assert_match
|
383
|
+
assert_match(/GET/, easy.body_str)
|
385
384
|
when :put
|
386
|
-
assert_match
|
385
|
+
assert_match(/PUT/, easy.body_str)
|
387
386
|
end
|
388
387
|
#puts "#{easy.body_str.inspect}, #{method.inspect}, #{code.inspect}"
|
389
388
|
end
|
@@ -399,11 +398,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
399
398
|
assert_equal nil, code
|
400
399
|
case method
|
401
400
|
when :post
|
402
|
-
assert_match
|
401
|
+
assert_match(/POST/, easy.body_str)
|
403
402
|
when :get
|
404
|
-
assert_match
|
403
|
+
assert_match(/GET/, easy.body_str)
|
405
404
|
when :put
|
406
|
-
assert_match
|
405
|
+
assert_match(/PUT/, easy.body_str)
|
407
406
|
end
|
408
407
|
end
|
409
408
|
end
|
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.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ross Bamford
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings
|
15
15
|
for the libcurl(3), a fully-featured client-side URL transfer library. cURL and
|