diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d6e425445..49f4f0a9c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 4becc327e6..ec7c0ff45d 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/lib/grape/middleware/formatter.rb b/lib/grape/middleware/formatter.rb index 7b81934512..a0dfb88cd5 100644 --- a/lib/grape/middleware/formatter.rb +++ b/lib/grape/middleware/formatter.rb @@ -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." diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 5f6e5e721e..fa4ce2dcf4 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -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