taf2-curb 0.3.6.0 → 0.4.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/curb.h CHANGED
@@ -20,11 +20,11 @@
20
20
  #include "curb_macros.h"
21
21
 
22
22
  // These should be managed from the Rake 'release' task.
23
- #define CURB_VERSION "0.3.6.0"
24
- #define CURB_VER_NUM 360
23
+ #define CURB_VERSION "0.4.0.0"
24
+ #define CURB_VER_NUM 400
25
25
  #define CURB_VER_MAJ 0
26
- #define CURB_VER_MIN 3
27
- #define CURB_VER_MIC 6
26
+ #define CURB_VER_MIN 4
27
+ #define CURB_VER_MIC 0
28
28
  #define CURB_VER_PATCH 0
29
29
 
30
30
 
data/ext/curb_easy.c CHANGED
@@ -1629,7 +1629,7 @@ static VALUE handle_perform(VALUE self, ruby_curl_easy *rbce) {
1629
1629
  if (result != 0) {
1630
1630
  // printf("error: %s\n", errors);
1631
1631
  if (rbce->failure_proc != Qnil) {
1632
- rb_funcall( rbce->failure_proc, idCall, 1, self );
1632
+ rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, INT2FIX(result) );
1633
1633
  } else {
1634
1634
  raise_curl_easy_error_exception(result);
1635
1635
  }
@@ -1641,7 +1641,7 @@ static VALUE handle_perform(VALUE self, ruby_curl_easy *rbce) {
1641
1641
  }
1642
1642
  else if (rbce->failure_proc != Qnil &&
1643
1643
  (response_code >= 300 && response_code <= 999)) {
1644
- rb_funcall( rbce->failure_proc, idCall, 1, self );
1644
+ rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, INT2FIX(result) );
1645
1645
  }
1646
1646
 
1647
1647
  return Qtrue;
@@ -1697,11 +1697,14 @@ static VALUE ruby_curl_easy_perform_delete(VALUE self) {
1697
1697
  *
1698
1698
  * Transfer the currently configured URL using the options set for this
1699
1699
  * Curl::Easy instance. If this is an HTTP URL, it will be transferred via
1700
- * the GET request method (i.e. this method is a synonym for +http_get+
1701
- * when using HTTP URLs).
1700
+ * the GET or HEAD request method.
1702
1701
  */
1703
1702
  static VALUE ruby_curl_easy_perform(VALUE self) {
1704
- return ruby_curl_easy_perform_get(self);
1703
+ ruby_curl_easy *rbce;
1704
+
1705
+ Data_Get_Struct(self, ruby_curl_easy, rbce);
1706
+
1707
+ return handle_perform(self,rbce);
1705
1708
  }
1706
1709
 
1707
1710
  /*
@@ -1803,6 +1806,28 @@ static VALUE ruby_curl_easy_perform_head(VALUE self) {
1803
1806
  return handle_perform(self,rbce);
1804
1807
  }
1805
1808
 
1809
+ /*
1810
+ *call-seq:
1811
+ * easy = Curl::Easy.new("url") do|c|
1812
+ * c.head = true
1813
+ * end
1814
+ * easy.perform
1815
+ */
1816
+ static VALUE ruby_curl_easy_set_head_option(VALUE self, VALUE onoff) {
1817
+ ruby_curl_easy *rbce;
1818
+
1819
+ Data_Get_Struct(self, ruby_curl_easy, rbce);
1820
+
1821
+ if( onoff == Qtrue ) {
1822
+ curl_easy_setopt(rbce->curl, CURLOPT_NOBODY, 1);
1823
+ }
1824
+ else {
1825
+ curl_easy_setopt(rbce->curl, CURLOPT_NOBODY, 0);
1826
+ }
1827
+
1828
+ return onoff;
1829
+ }
1830
+
1806
1831
  /*
1807
1832
  * call-seq:
1808
1833
  * easy.http_put(data) => true
@@ -2685,6 +2710,7 @@ void init_curb_easy() {
2685
2710
  rb_define_method(cCurlEasy, "http_post", ruby_curl_easy_perform_post, -1);
2686
2711
  rb_define_method(cCurlEasy, "http_head", ruby_curl_easy_perform_head, 0);
2687
2712
  rb_define_method(cCurlEasy, "http_put", ruby_curl_easy_perform_put, 1);
2713
+ rb_define_method(cCurlEasy, "head=", ruby_curl_easy_set_head_option, 1);
2688
2714
 
2689
2715
  /* Post-perform info methods */
2690
2716
  rb_define_method(cCurlEasy, "body_str", ruby_curl_easy_body_str_get, 0);
data/ext/curb_multi.c CHANGED
@@ -106,7 +106,28 @@ static VALUE ruby_curl_multi_max_connects(VALUE self, VALUE count) {
106
106
  curl_multi_setopt(rbcm->handle, CURLMOPT_MAXCONNECTS, NUM2INT(count));
107
107
  #endif
108
108
 
109
- return self;
109
+ return count;
110
+ }
111
+
112
+ /*
113
+ * call-seq:
114
+ * multi = Curl::Multi.new
115
+ * multi.pipeline = true
116
+ *
117
+ * Pass a long set to 1 to enable or 0 to disable. Enabling pipelining on a multi handle will make it
118
+ * attempt to perform HTTP Pipelining as far as possible for transfers using this handle. This means
119
+ * that if you add a second request that can use an already existing connection, the second request will
120
+ * be "piped" on the same connection rather than being executed in parallel. (Added in 7.16.0)
121
+ *
122
+ */
123
+ static VALUE ruby_curl_multi_pipeline(VALUE self, VALUE onoff) {
124
+ #ifdef HAVE_CURLMOPT_PIPELINING
125
+ ruby_curl_multi *rbcm;
126
+
127
+ Data_Get_Struct(self, ruby_curl_multi, rbcm);
128
+ curl_multi_setopt(rbcm->handle, CURLMOPT_PIPELINING, onoff == Qtrue ? 1 : 0);
129
+ #endif
130
+ return onoff;
110
131
  }
111
132
 
112
133
  /*
@@ -235,7 +256,7 @@ static void rb_curl_multi_read_info(VALUE self, CURLM *multi_handle) {
235
256
 
236
257
  if (result != 0) {
237
258
  if (rbce->failure_proc != Qnil) {
238
- rb_funcall( rbce->failure_proc, idCall, 1, rbce->self );
259
+ rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, INT2FIX(result) );
239
260
  }
240
261
  }
241
262
  else if (rbce->success_proc != Qnil &&
@@ -245,7 +266,7 @@ static void rb_curl_multi_read_info(VALUE self, CURLM *multi_handle) {
245
266
  }
246
267
  else if (rbce->failure_proc != Qnil &&
247
268
  (response_code >= 300 && response_code <= 999)) {
248
- rb_funcall( rbce->failure_proc, idCall, 1, rbce->self );
269
+ rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, INT2FIX(result) );
249
270
  }
250
271
  rbce->self = Qnil;
251
272
  }
@@ -359,6 +380,7 @@ void init_curb_multi() {
359
380
 
360
381
  /* Instnace methods */
361
382
  rb_define_method(cCurlMulti, "max_connects=", ruby_curl_multi_max_connects, 1);
383
+ rb_define_method(cCurlMulti, "pipeline=", ruby_curl_multi_pipeline, 1);
362
384
  rb_define_method(cCurlMulti, "add", ruby_curl_multi_add, 1);
363
385
  rb_define_method(cCurlMulti, "remove", ruby_curl_multi_remove, 1);
364
386
  rb_define_method(cCurlMulti, "perform", ruby_curl_multi_perform, 0);
@@ -471,7 +471,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
471
471
  curl = Curl::Easy.new("#{$TEST_URL.gsub(/file:\/\//,'')}/not_here")
472
472
  on_failure_called = false
473
473
  curl.on_success {|c| } # make sure we get the failure call even though this handler is defined
474
- curl.on_failure {|c| on_failure_called = true }
474
+ curl.on_failure {|c,code| on_failure_called = true }
475
475
  curl.perform
476
476
  assert on_failure_called, "Failure handler not called"
477
477
  end
@@ -504,6 +504,20 @@ class TestCurbCurlEasy < Test::Unit::TestCase
504
504
  assert_match '/nonexistent', redirect[1]
505
505
  end
506
506
 
507
+ def test_head_accessor
508
+ curl = Curl::Easy.new(TestServlet.url)
509
+ curl.head = true
510
+ curl.perform
511
+
512
+ redirect = curl.header_str.match(/Location: (.*)/)
513
+
514
+ assert_equal '', curl.body_str
515
+ assert_match '/nonexistent', redirect[1]
516
+ curl.head = false
517
+ curl.perform
518
+ assert_equal 'GET', curl.body_str
519
+ end
520
+
507
521
  def test_put_remote
508
522
  curl = Curl::Easy.new(TestServlet.url)
509
523
  assert curl.http_put("message")
@@ -146,7 +146,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
146
146
  #assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
147
147
  end
148
148
 
149
- c1.on_failure do|c|
149
+ c1.on_failure do|c,rc|
150
150
  #puts "failure called: #{c.body_str.inspect}"
151
151
  end
152
152
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taf2-curb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6.0
4
+ version: 0.4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Bamford
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-13 00:00:00 -07:00
13
+ date: 2009-06-17 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16