curb 0.6.4.1 → 0.6.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curb might be problematic. Click here for more details.

data/ext/curb.h CHANGED
@@ -20,12 +20,12 @@
20
20
  #include "curb_macros.h"
21
21
 
22
22
  // These should be managed from the Rake 'release' task.
23
- #define CURB_VERSION "0.6.4.1"
24
- #define CURB_VER_NUM 641
23
+ #define CURB_VERSION "0.6.5.0"
24
+ #define CURB_VER_NUM 650
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 6
27
- #define CURB_VER_MIC 4
28
- #define CURB_VER_PATCH 1
27
+ #define CURB_VER_MIC 5
28
+ #define CURB_VER_PATCH 0
29
29
 
30
30
 
31
31
  // Maybe not yet defined in Ruby
data/ext/curb_easy.c CHANGED
@@ -656,7 +656,7 @@ static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
656
656
 
657
657
  char *data;
658
658
  long len;
659
-
659
+
660
660
  Data_Get_Struct(self, ruby_curl_easy, rbce);
661
661
 
662
662
  curl = rbce->curl;
@@ -1988,12 +1988,16 @@ static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
1988
1988
 
1989
1989
  return ret;
1990
1990
  } else {
1991
- VALUE post_body;
1991
+ VALUE post_body = Qnil;
1992
1992
  if ((post_body = rb_funcall(args_ary, idJoin, 1, rbstrAmp)) == Qnil) {
1993
1993
  rb_raise(eCurlErrError, "Failed to join arguments");
1994
1994
  return Qnil;
1995
1995
  } else {
1996
- ruby_curl_easy_post_body_set(self, post_body);
1996
+ /* if the function call above returns an empty string because no additional arguments were passed this makes sure
1997
+ a previously set easy.post_body = "arg=foo&bar=bin" will be honored */
1998
+ if( post_body != Qnil && rb_type(post_body) == T_STRING && RSTRING_LEN(post_body) > 0 ) {
1999
+ ruby_curl_easy_post_body_set(self, post_body);
2000
+ }
1997
2001
 
1998
2002
  return handle_perform(self,rbce);
1999
2003
  }
@@ -0,0 +1,83 @@
1
+ =begin
2
+ From jwhitmire
3
+ Todd, I'm trying to use curb to post data to a REST url. We're using it to post support questions from our iphone app directly to tender. The post looks good to me, but curl is not adding the content-length header so I get a 411 length required response from the server.
4
+
5
+ Here's my post block, do you see anything obvious? Do I need to manually add the Content-Length header?
6
+
7
+ c = Curl::Easy.http_post(url) do |curl|
8
+ curl.headers["User-Agent"] = "Curl/Ruby"
9
+ if user
10
+ curl.headers["X-Multipass"] = user.multipass
11
+ else
12
+ curl.headers["X-Tender-Auth"] = TOKEN
13
+ end
14
+ curl.headers["Accept"] = "application/vnd.tender-v1+json"
15
+
16
+ curl.post_body = params.map{|f,k| "#{curl.escape(f)}=#{curl.escape(k)}"}.join('&')
17
+
18
+ curl.verbose = true
19
+ curl.follow_location = true
20
+ curl.enable_cookies = true
21
+ end
22
+ Any insight you care to share would be helpful. Thanks.
23
+ =end
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
25
+ require 'webrick'
26
+ class ::WEBrick::HTTPServer ; def access_log(config, req, res) ; end ; end
27
+ class ::WEBrick::BasicLog ; def log(level, data) ; end ; end
28
+
29
+ class BugCurbEasyPostWithStringNoContentLengthHeader < Test::Unit::TestCase
30
+ def test_bug_workaround
31
+ server = WEBrick::HTTPServer.new( :Port => 9999 )
32
+ server.mount_proc("/test") do|req,res|
33
+ assert_equal '15', req['Content-Length']
34
+ res.body = "hi"
35
+ res['Content-Type'] = "text/html"
36
+ end
37
+
38
+ thread = Thread.new(server) do|srv|
39
+ srv.start
40
+ end
41
+ params = {:cat => "hat", :foo => "bar"}
42
+
43
+ post_body = params.map{|f,k| "#{Curl::Easy.new.escape(f)}=#{Curl::Easy.new.escape(k)}"}.join('&')
44
+ c = Curl::Easy.http_post("http://127.0.0.1:9999/test",post_body) do |curl|
45
+ curl.headers["User-Agent"] = "Curl/Ruby"
46
+ curl.headers["X-Tender-Auth"] = "A Token"
47
+ curl.headers["Accept"] = "application/vnd.tender-v1+json"
48
+
49
+ curl.follow_location = true
50
+ curl.enable_cookies = true
51
+ end
52
+
53
+ server.shutdown
54
+ thread.join
55
+ end
56
+ def test_bug
57
+ server = WEBrick::HTTPServer.new( :Port => 9999 )
58
+ server.mount_proc("/test") do|req,res|
59
+ assert_equal '15', req['Content-Length']
60
+ res.body = "hi"
61
+ res['Content-Type'] = "text/html"
62
+ end
63
+
64
+ thread = Thread.new(server) do|srv|
65
+ srv.start
66
+ end
67
+ params = {:cat => "hat", :foo => "bar"}
68
+
69
+ c = Curl::Easy.http_post("http://127.0.0.1:9999/test") do |curl|
70
+ curl.headers["User-Agent"] = "Curl/Ruby"
71
+ curl.headers["X-Tender-Auth"] = "A Token"
72
+ curl.headers["Accept"] = "application/vnd.tender-v1+json"
73
+
74
+ curl.post_body = params.map{|f,k| "#{curl.escape(f)}=#{curl.escape(k)}"}.join('&')
75
+
76
+ curl.follow_location = true
77
+ curl.enable_cookies = true
78
+ end
79
+
80
+ server.shutdown
81
+ thread.join
82
+ end
83
+ 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.6.4.1
4
+ version: 0.6.5.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: 2010-01-16 00:00:00 -05:00
13
+ date: 2010-01-26 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -29,21 +29,21 @@ files:
29
29
  - Rakefile
30
30
  - doc.rb
31
31
  - ext/extconf.rb
32
- - lib/curb.rb
33
32
  - lib/curl.rb
33
+ - lib/curb.rb
34
34
  - ext/curb.c
35
+ - ext/curb_upload.c
36
+ - ext/curb_postfield.c
35
37
  - ext/curb_easy.c
36
- - ext/curb_errors.c
37
38
  - ext/curb_multi.c
38
- - ext/curb_postfield.c
39
- - ext/curb_upload.c
40
- - ext/curb.h
41
- - ext/curb_easy.h
39
+ - ext/curb_errors.c
42
40
  - ext/curb_errors.h
43
- - ext/curb_macros.h
44
41
  - ext/curb_multi.h
42
+ - ext/curb.h
43
+ - ext/curb_easy.h
45
44
  - ext/curb_postfield.h
46
45
  - ext/curb_upload.h
46
+ - ext/curb_macros.h
47
47
  has_rdoc: true
48
48
  homepage: http://curb.rubyforge.org/
49
49
  licenses: []
@@ -75,17 +75,18 @@ signing_key:
75
75
  specification_version: 3
76
76
  summary: Ruby libcurl bindings
77
77
  test_files:
78
- - tests/alltests.rb
79
- - tests/bug_curb_easy_blocks_ruby_threads.rb
78
+ - tests/mem_check.rb
79
+ - tests/bug_require_last_or_segfault.rb
80
+ - tests/helper.rb
81
+ - tests/tc_curl_postfield.rb
80
82
  - tests/bug_instance_post_differs_from_class_post.rb
81
83
  - tests/bug_multi_segfault.rb
84
+ - tests/alltests.rb
82
85
  - tests/bug_postfields_crash.rb
83
- - tests/bug_require_last_or_segfault.rb
84
- - tests/helper.rb
85
- - tests/mem_check.rb
86
86
  - tests/require_last_or_segfault_script.rb
87
+ - tests/unittests.rb
88
+ - tests/tc_curl_multi.rb
89
+ - tests/bug_curb_easy_post_with_string_no_content_length_header.rb
87
90
  - tests/tc_curl_download.rb
88
91
  - tests/tc_curl_easy.rb
89
- - tests/tc_curl_multi.rb
90
- - tests/tc_curl_postfield.rb
91
- - tests/unittests.rb
92
+ - tests/bug_curb_easy_blocks_ruby_threads.rb