Custom headers lost on PUT?

214 views
Skip to first unread message

Kenneth Kalmer

unread,
Jun 21, 2009, 8:48:10 PM6/21/09
to curb---ruby-li...@googlegroups.com
Hi Todd and the list

I'm experiencing some difficulties where my custom headers aren't sent along with PUT requests.

I have the following invocation:

  c = Curl::Easy.new('http://localhost:4567/workitems/20090617-jozusagiku/0_0_0")
  c.headers['Content-Type'] = "application/json"
  c.http_put( <arbitrary json string> )

I thought I was going mad, but a quick tcpdump showed this is the fact:

  PUT /workitems/20090617-jozusagiku/0_0_0 HTTP/1.1
  Host: 127.0.0.1:4567
  Accept: */*
  Content-Length: 1420

I unfortunately know nothing of C/C++. I had a look at ruby_curl_easy_perform_put, and can only assume the different calls to ruby_curl_easy_headers_set are overwriting my custom header (again, no real knowledge of C/C++).

Any pointers? This is kinda a show stopper for me, and so far curb has been an absolute joy to use.

Best

--
Kenneth Kalmer
kenneth...@gmail.com
http://opensourcery.co.za
@kennethkalmer
kennethkalmer: New blog post: How to select an array of values in Rails - http://is.gd/12url ...

Kenneth Kalmer

unread,
Jun 21, 2009, 9:26:08 PM6/21/09
to Curb - Ruby libcurl Bindings
On Jun 22, 2:48 am, Kenneth Kalmer <kenneth.kal...@gmail.com> wrote:
> Hi Todd and the list
>
> I'm experiencing some difficulties where my custom headers aren't sent along
> with PUT requests.
>
> I have the following invocation:
>
>   c = Curl::Easy.new('http://localhost:4567/workitems/20090617-jozusagiku/0_0_0")
>   c.headers['Content-Type'] = "application/json"
>   c.http_put( <arbitrary json string> )
>
> I thought I was going mad, but a quick tcpdump showed this is the fact:
>
>   PUT /workitems/20090617-jozusagiku/0_0_0 HTTP/1.1
>   Host: 127.0.0.1:4567
>   Accept: */*
>   Content-Length: 1420

Seems irb confirmed this as well, headers are getting munched:

=> #<Curl::Easy:0xb5d5cc84>
>> c.headers['Content-Type'] = 'application/json'
=> "application/json"
>> c.headers
=> {"Content-Type"=>"application/json"}
>> c.http_put( wi.to_json )
=> true
>> c.headers
=> "Expect:"

Best

Todd Fisher

unread,
Jun 22, 2009, 4:03:38 PM6/22/09
to curb---ruby-li...@googlegroups.com
Hi Kenneth,
  I reworked most of the code that sends a PUT last week in my github fork and have to set a few extra headers in some cases like Transfer-Encoding: chunked.  This is so that you can now send a file without reading the whole file into memory.   As a result I incorrectly over wrote any previously set headers.  As of my most recent commit, http://github.com/taf2/curb/commit/4083aef21d5d357097ea2d5474b2fdea23fa9777#comments  Curb will again accept any header you set, with the pre-condition that you only set headers using the Hash interface.

Cheers,
Todd
Reply all
Reply to author
Forward
0 new messages