gamache / hyperresource

A self-inflating Ruby client for hypermedia APIs. Not under active development.
http://hyperresource.com/doc
MIT License
304 stars 29 forks source link

fix for empty body on 204 status code #40

Closed pvmeerbe closed 9 years ago

pvmeerbe commented 9 years ago

According to HTTP spec,status code 204 should not have a body The current code checks for 'response.body' to achieve this.

However Rack sends empty string as body for a 204 status code which is considered a body when using the response.body check. As a result deserializing from Json fails. using .present? solves this issue

related rack information:

gamache commented 9 years ago

Thanks for the patch! But Object#present? is a Rails method, not pure Ruby. I'd also like a test case if this is to make it into master.

pvmeerbe commented 9 years ago

I reworked the .present? function & added related tests.

I also provided a fix specifically for Grape with status 405 response (see last commit)

gamache commented 9 years ago

Thanks for the patch! Merging. :+1: