Skip to content

Commit

Permalink
fix issue 50
Browse files Browse the repository at this point in the history
  • Loading branch information
taf2 committed Dec 22, 2010
1 parent 9e9a3db commit 5f223a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions ext/curb_easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,18 @@ static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
rb_easy_del("postdata_buffer");

} else {
data = StringValuePtr(post_body);
len = RSTRING_LEN(post_body);
if (rb_type(post_body) == T_STRING) {
data = StringValuePtr(post_body);
len = RSTRING_LEN(post_body);
}
else if (rb_respond_to(post_body, rb_intern("to_s"))) {
VALUE str_body = rb_funcall(post_body, rb_intern("to_s"), 0);
data = StringValuePtr(str_body);
len = RSTRING_LEN(post_body);
}
else {
rb_raise(rb_eRuntimeError, "post data must respond_to .to_s");
}

// Store the string, since it has to hang around for the duration of the
// request. See CURLOPT_POSTFIELDS in the libcurl docs.
Expand Down
2 changes: 1 addition & 1 deletion ext/curb_postfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static VALUE ruby_curl_postfield_new_content(int argc, VALUE *argv, VALUE klass)
// wierdness - we actually require two args, unless a block is provided, but
// we have to work that out below.
rb_scan_args(argc, argv, "12&", &rbcpf->name, &rbcpf->content, &rbcpf->content_type, &rbcpf->content_proc);

// special handling if theres a block, second arg is actually content_type
if (rbcpf->content_proc != Qnil) {
if (rbcpf->content != Qnil) {
Expand Down
4 changes: 2 additions & 2 deletions tests/tc_curl_easy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ def test_get_remote

def test_post_remote
curl = Curl::Easy.new(TestServlet.url)
curl.http_post
assert_equal "POST\n", curl.body_str
curl.http_post([Curl::PostField.content('document_id', 5)])
assert_equal "POST\ndocument%5Fid=5", curl.body_str
end

def test_post_remote_is_easy_handle
Expand Down

0 comments on commit 5f223a8

Please sign in to comment.