Nil RestClient::Response on 204 "No Content"
egarson opened this issue · 4 comments
Hello,
Given the following which returns 204/"No Content":
$ curl -v -X POST -d count=1 -u foo:bar http://localhost:8003/das/reservation
[snip]
POST /das/reservation HTTP/1.1
Authorization: Basic YmlfIFJfe9pbg==
User-Agent: curl/7.18.2 (i486-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.10
Host: localhost:8003
Accept: /
Content-Length: 7
Content-Type: application/x-www-form-urlencoded< HTTP/1.1 204 No Content
< Server: Yaws/1.84 Yet Another Web Server
< Date: Thu, 01 Oct 2009 19:02:04 GMT
< Content-Length: 112
< Content-Type: text/html
[snip]
Then why does the rest-client equivalent call return nil?:
irb(main):209:0> res = RestClient::Resource.new("http://localhost:8003",:user=>'foo',:password=>'bar')
=> #<RestClient::Resource:0xb6e5ce1c...
irb(main):210:0> response_204 = res['das/reservation'].post "count=1"
=> nil
I expected a Response object with a code of 204 and a to_s of "" (i.e. empty HTTP body) to be consistent with e.g.:
irb(main):200:0> response = res['das/message_count'].get
=> "3"
irb(main):201:0> response.code
=> 200
Is this behavior by design, or am I doing something wrong?
And, thank you for RestClient, I really like it.
Edward Garson
...sorry about the formatting...
I came across this same issue, and so took a fork of the code and put in a fix so that it returns a response object with an empty ("") body for "204 No Content" responses, which then lets you also get to all the returned headers etc as with any other response.
I've sent a pull request to Adam so that he can take a look at it and decide whether to roll the fix into the main repo, but if you want to try it out in the meantime, you can try my fork - http://github.com/edraper/rest-client
Oh, that's great - many thanks edraper.
will be in next version as http://github.com/archiloque/rest-client/commit/e4d01c7688abbde405098824959ef24397938fbb