curb 1.0.9 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0105bb19d8f3c70c7b16dc47ede5eef29b26d78a765b6ab9ac19c81dc34c647a
4
- data.tar.gz: 8bb7441583b1caa916969f4a7aad3785777de7912347f6c454bb110c4ab50b08
3
+ metadata.gz: 25a6615cec70148cb19373a5ad0326a93b2e1b4424bd2d02734038857e261659
4
+ data.tar.gz: 85f2b05e3fd7e8b400d8cd86d65aa2778e4c60e55337442e34d6cda673278c55
5
5
  SHA512:
6
- metadata.gz: b9d63ab6203a5d37fe3ef02b081f92afa9ece68acdde249d6f3e09fd21fec5fd1342fa6e2fcbfb6fc58a6fd5ad2fce44fd0915d0b0bd31902cc9c5aef976d250
7
- data.tar.gz: cb9f110ebeddb88eddc31d9cf1985148365c6abe5a378e2ea157414dd7bc96c59b2b2883ba0b21ac1569d82ee4bc8744cfbeaae1eaae07245c81a146bae78510
6
+ metadata.gz: de609adca7bcd45c867a8fa91a20caa429e0064c68587d498bf25f455a1d4c49c6d00ec851af7c80aa1cc2694b4d0dd19291ebfb9b3010793dd8fa8c28e22d4c
7
+ data.tar.gz: af3d577715760e6b6ca977c5a6295d0af5d8b60858d673675d778deff7b06120876b72975ea35062c5299ac45fbab2d45a70b375cf94d07b410eb8c649a443d1
@@ -10,6 +10,8 @@ cURL and libcurl live at [https://curl.se/libcurl/](https://curl.se/libcurl/) .
10
10
 
11
11
  Curb is a work-in-progress, and currently only supports libcurl's `easy` and `multi` modes.
12
12
 
13
+ A big advantage to Curb over all other known ruby http libraries is it's ability to handle timeouts without the use of threads.
14
+
13
15
  ## License
14
16
 
15
17
  Curb is copyright (c) 2006 Ross Bamford, and released under the terms of the
data/ext/curb.h CHANGED
@@ -28,11 +28,11 @@
28
28
  #include "curb_macros.h"
29
29
 
30
30
  // These should be managed from the Rake 'release' task.
31
- #define CURB_VERSION "1.0.9"
32
- #define CURB_VER_NUM 1009
31
+ #define CURB_VERSION "1.1.0"
32
+ #define CURB_VER_NUM 1010
33
33
  #define CURB_VER_MAJ 1
34
- #define CURB_VER_MIN 0
35
- #define CURB_VER_MIC 9
34
+ #define CURB_VER_MIN 1
35
+ #define CURB_VER_MIC 0
36
36
  #define CURB_VER_PATCH 0
37
37
 
38
38
 
data/ext/curb_easy.c CHANGED
@@ -3821,6 +3821,27 @@ static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
3821
3821
  case CURLOPT_PROXY_SSL_VERIFYHOST:
3822
3822
  curl_easy_setopt(rbce->curl, CURLOPT_PROXY_SSL_VERIFYHOST, NUM2LONG(val));
3823
3823
  break;
3824
+ #endif
3825
+ #if HAVE_CURLOPT_RESOLVE
3826
+ case CURLOPT_RESOLVE: {
3827
+ struct curl_slist *list = NULL;
3828
+ if (NIL_P(val)) {
3829
+ /* When nil is passed, we clear any previous resolve list */
3830
+ list = NULL;
3831
+ } else if (TYPE(val) == T_ARRAY) {
3832
+ long i, len = RARRAY_LEN(val);
3833
+ for (i = 0; i < len; i++) {
3834
+ VALUE item = rb_ary_entry(val, i);
3835
+ list = curl_slist_append(list, StringValueCStr(item));
3836
+ }
3837
+ } else {
3838
+ /* If a single string is passed, use it directly */
3839
+ list = curl_slist_append(NULL, StringValueCStr(val));
3840
+ }
3841
+ /* Save the list pointer in the ruby_curl_easy structure for cleanup later */
3842
+ rbce->curl_resolve = list;
3843
+ curl_easy_setopt(rbce->curl, CURLOPT_RESOLVE, list);
3844
+ } break;
3824
3845
  #endif
3825
3846
  default:
3826
3847
  rb_raise(rb_eTypeError, "Curb unsupported option");
data/ext/curb_multi.c CHANGED
@@ -187,6 +187,25 @@ static VALUE ruby_curl_multi_max_connects(VALUE self, VALUE count) {
187
187
  return count;
188
188
  }
189
189
 
190
+ /*
191
+ * call-seq:
192
+ * multi = Curl::Multi.new
193
+ * multi.max_host_connections = 1
194
+ *
195
+ * Set the max number of connections per host
196
+ */
197
+ static VALUE ruby_curl_multi_max_host_connections(VALUE self, VALUE count) {
198
+ #ifdef HAVE_CURLMOPT_MAX_HOST_CONNECTIONS
199
+ ruby_curl_multi *rbcm;
200
+
201
+ Data_Get_Struct(self, ruby_curl_multi, rbcm);
202
+
203
+ curl_multi_setopt(rbcm->handle, CURLMOPT_MAX_HOST_CONNECTIONS, NUM2LONG(count));
204
+ #endif
205
+
206
+ return count;
207
+ }
208
+
190
209
  /*
191
210
  * call-seq:
192
211
  * multi = Curl::Multi.new
@@ -704,6 +723,7 @@ void init_curb_multi() {
704
723
  rb_define_singleton_method(cCurlMulti, "autoclose", ruby_curl_multi_get_autoclose, 0);
705
724
  /* Instance methods */
706
725
  rb_define_method(cCurlMulti, "max_connects=", ruby_curl_multi_max_connects, 1);
726
+ rb_define_method(cCurlMulti, "max_host_connections=", ruby_curl_multi_max_host_connections, 1);
707
727
  rb_define_method(cCurlMulti, "pipeline=", ruby_curl_multi_pipeline, 1);
708
728
  rb_define_method(cCurlMulti, "_add", ruby_curl_multi_add, 1);
709
729
  rb_define_method(cCurlMulti, "_remove", ruby_curl_multi_remove, 1);
data/ext/extconf.rb CHANGED
@@ -338,6 +338,9 @@ have_constant :CURL_SSLVERSION_TLSv1
338
338
  have_constant :CURL_SSLVERSION_SSLv2
339
339
  have_constant :CURL_SSLVERSION_SSLv3
340
340
 
341
+ # Added in 7.30.0
342
+ have_constant "curlmopt_max_host_connections"
343
+
341
344
  # Added in 7.34.0
342
345
  have_constant :CURL_SSLVERSION_TLSv1_0
343
346
  have_constant :CURL_SSLVERSION_TLSv1_1
data/lib/curl.rb CHANGED
@@ -3,7 +3,6 @@ require 'curb_core'
3
3
  require 'curl/easy'
4
4
  require 'curl/multi'
5
5
  require 'uri'
6
- require 'cgi'
7
6
 
8
7
  # expose shortcut methods
9
8
  module Curl
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ class BugResolve < Test::Unit::TestCase
4
+ include BugTestServerSetupTeardown
5
+
6
+ def test_abuse_resolve
7
+ c = Curl::Easy.new("http://localhost:#{@port}/test")
8
+ while true
9
+ c.get
10
+ assert_equal 200, c.response_code
11
+ assert_match(/hi/, c.body)
12
+ end
13
+ end
14
+
15
+ end
data/tests/helper.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  $CURB_TESTING = true
4
4
  require 'uri'
5
5
  require 'stringio'
6
+ require 'digest/md5'
6
7
 
7
8
  $TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
8
9
  $EXTDIR = File.join($TOPDIR, 'ext')
@@ -18,6 +18,20 @@ class TestCurbCurlEasy < Test::Unit::TestCase
18
18
  assert_equal 200, easy.code
19
19
  end
20
20
 
21
+ def test_curlopt_resolve
22
+ require 'resolv'
23
+ uri = URI.parse(TestServlet.url)
24
+ resolved_ip = Resolv.getaddress(uri.host) # perform DNS lookup once
25
+ mapping = "#{uri.host}:#{uri.port}:#{resolved_ip}"
26
+
27
+ http = Curl::Easy.new(TestServlet.url)
28
+ http.setopt(Curl::CURLOPT_RESOLVE, [mapping])
29
+
30
+ http.get
31
+
32
+ assert_match(/GET/, http.body)
33
+ end
34
+
21
35
  def test_curlopt_stderr_with_file
22
36
  # does not work with Tempfile directly
23
37
  path = Tempfile.new('curb_test_curlopt_stderr').path
@@ -805,8 +819,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
805
819
  curl = Curl::Easy.new(TestServlet.url)
806
820
  curl.multipart_form_post = true
807
821
  fields = [
808
- Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))),
809
- Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
822
+ Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.md'))),
823
+ Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.md')))
810
824
  ]
811
825
  curl.http_post(fields)
812
826
  assert_match(/HTTP POST file upload/, curl.body_str)
@@ -815,8 +829,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
815
829
  curl = Curl::Easy.new(TestServlet.url)
816
830
  curl.multipart_form_post = true
817
831
  fields = [
818
- Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))),
819
- Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
832
+ Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.md'))),
833
+ Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.md')))
820
834
  ]
821
835
  curl.http_put(fields)
822
836
  assert_match(/HTTP POST file upload/, curl.body_str)
@@ -866,7 +880,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
866
880
  [:put, :post, :patch].each {|method|
867
881
  curl = Curl::Easy.new(TestServlet.url)
868
882
  curl.multipart_form_post = true
869
- pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
883
+ pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.md')))
870
884
  curl.send("http_#{method}", pf)
871
885
  assert_match(/HTTP POST file upload/, curl.body_str)
872
886
  assert_match(/Content-Disposition: form-data/, curl.body_str)
@@ -1048,7 +1062,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
1048
1062
  end
1049
1063
 
1050
1064
  def test_post_streaming
1051
- readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))
1065
+ readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README.md'))
1052
1066
 
1053
1067
  pf = Curl::PostField.file("filename", readme)
1054
1068
 
@@ -1058,11 +1072,10 @@ class TestCurbCurlEasy < Test::Unit::TestCase
1058
1072
  easy.multipart_form_post = true
1059
1073
  easy.http_post(pf)
1060
1074
 
1061
- assert_not_equal(0,easy.body_str.size)
1062
- assert_equal(easy.body_str.tr("\r", ''), File.read(readme))
1075
+ assert_not_equal(0,easy.body.size)
1076
+ assert_equal(Digest::MD5.hexdigest(easy.body), Digest::MD5.hexdigest(File.read(readme)))
1063
1077
  end
1064
1078
 
1065
-
1066
1079
  def test_easy_close
1067
1080
  easy = Curl::Easy.new
1068
1081
  easy.close
@@ -552,6 +552,25 @@ class TestCurbCurlMulti < Test::Unit::TestCase
552
552
  end
553
553
  end
554
554
 
555
+ def test_multi_easy_http_with_max_host_connections
556
+ urls = [
557
+ { :url => TestServlet.url + '?q=1', :method => :get },
558
+ { :url => TestServlet.url + '?q=2', :method => :get },
559
+ { :url => TestServlet.url + '?q=3', :method => :get }
560
+ ]
561
+ Curl::Multi.http(urls, {:pipeline => true, :max_host_connections => 1}) do|easy, code, method|
562
+ assert_equal 200, code
563
+ case method
564
+ when :post
565
+ assert_match(/POST/, easy.body)
566
+ when :get
567
+ assert_match(/GET/, easy.body)
568
+ when :put
569
+ assert_match(/PUT/, easy.body)
570
+ end
571
+ end
572
+ end
573
+
555
574
  def test_multi_recieves_500
556
575
  m = Curl::Multi.new
557
576
  e = Curl::Easy.new("http://127.0.0.1:9129/methods")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Bamford
8
8
  - Todd A. Fisher
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-15 00:00:00.000000000 Z
11
+ date: 2025-07-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings
14
14
  for the libcurl(3), a fully-featured client-side URL transfer library. cURL and
@@ -19,10 +19,10 @@ extensions:
19
19
  - ext/extconf.rb
20
20
  extra_rdoc_files:
21
21
  - LICENSE
22
- - README.markdown
22
+ - README.md
23
23
  files:
24
24
  - LICENSE
25
- - README.markdown
25
+ - README.md
26
26
  - Rakefile
27
27
  - doc.rb
28
28
  - ext/banned.h
@@ -58,6 +58,7 @@ files:
58
58
  - tests/bug_postfields_crash2.rb
59
59
  - tests/bug_raise_on_callback.rb
60
60
  - tests/bug_require_last_or_segfault.rb
61
+ - tests/bug_resolve.rb
61
62
  - tests/bugtests.rb
62
63
  - tests/helper.rb
63
64
  - tests/mem_check.rb
@@ -83,7 +84,7 @@ metadata:
83
84
  changelog_uri: https://github.com/taf2/curb/blob/master/ChangeLog.md
84
85
  rdoc_options:
85
86
  - "--main"
86
- - README.markdown
87
+ - README.md
87
88
  require_paths:
88
89
  - lib
89
90
  - ext
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  - !ruby/object:Gem::Version
99
100
  version: '0'
100
101
  requirements: []
101
- rubygems_version: 3.6.2
102
+ rubygems_version: 3.6.9
102
103
  specification_version: 4
103
104
  summary: Ruby libcurl bindings
104
105
  test_files:
@@ -116,6 +117,7 @@ test_files:
116
117
  - tests/bug_postfields_crash2.rb
117
118
  - tests/bug_raise_on_callback.rb
118
119
  - tests/bug_require_last_or_segfault.rb
120
+ - tests/bug_resolve.rb
119
121
  - tests/bugtests.rb
120
122
  - tests/helper.rb
121
123
  - tests/mem_check.rb