Skip to content

Commit

Permalink
Fix #344: Added parser :type, nil, which disables parsing for a given…
Browse files Browse the repository at this point in the history
… content-type.
  • Loading branch information
dblock committed Apr 14, 2013
1 parent b03753c commit bcf18e1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Next Release
============

* [#378](https://github.com/intridea/grape/pull/378): Fix: stop rescuing all exceptions during formatting - [@kbarrette](https://github.com/kbarrette).
* [#380](https://github.com/intridea/grape/pull/380): Fix: Formatter#read_body_input when transfer encoding is chunked - [@paulnicholon](https://github.com/paulnicholson).
* [#380](https://github.com/intridea/grape/pull/380): Fix: `Formatter#read_body_input` when transfer encoding is chunked - [@paulnicholon](https://github.com/paulnicholson).
* [#344](https://github.com/intridea/grape/pull/344): Added `parser :type, nil` which disables input parsing for a given content-type - [@dblock](https://github.com/dblock).
* Your contribution here.

0.4.1 (4/1/2013)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ You can invoke the above API as follows.
curl -X PUT -d 'data' 'http://localhost:9292/value' -H Content-Type:text/custom -v
```

You can disable parsing for a content-type with `nil`. For example, `parser :json, nil` will disable JSON parsing altogether. The request data is then available as-is in `env['api.request.body']`.

## RESTful Model Representations

Grape supports a range of ways to present your data with some help from a generic `present` method,
Expand Down
2 changes: 2 additions & 0 deletions lib/grape/middleware/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def read_rack_input(body)
rescue Exception => e
throw :error, :status => 400, :message => e.message
end
else
env['api.request.body'] = body
end
else
throw :error, :status => 406, :message => "The requested content-type '#{request.media_type}' is not supported."
Expand Down
13 changes: 13 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,19 @@ def self.call(object, env)
last_response.body.should eql 'Disallowed type attribute: "symbol"'
end
end
context "none parser class" do
before :each do
subject.parser :json, nil
subject.put "data" do
"body: #{env['api.request.body']}"
end
end
it "does not parse data" do
put '/data', 'not valid json', "CONTENT_TYPE" => "application/json"
last_response.status.should == 200
last_response.body.should == "body: not valid json"
end
end
end

describe '.default_error_status' do
Expand Down

0 comments on commit bcf18e1

Please sign in to comment.