Permalink
Browse files

Don't use the JSON parser if the response content-type isn't indicati…

…ng that kind of content.
  • Loading branch information...
1 parent f23b3cc commit 6e321702e34d6d21efa494582c89e33eea4ce79f @benschwarz committed Mar 5, 2011
Showing with 8 additions and 0 deletions.
  1. +2 −0 lib/faraday/parse_json.rb
  2. +6 −0 spec/parse_json_spec.rb
@@ -9,6 +9,8 @@ class Response::ParseJson < Response::Middleware
end
def on_complete(env)
+ return env[:body] unless env[:response_headers]["content-type"].include? "json"
+
env[:body] = begin
case env[:body]
when ''
View
@@ -10,6 +10,12 @@
end
end
+ it "shouldn't change the response if it isn't json" do
+ @stubs.get('/text') {[200, {'content-type' => 'text/plain'}, 'plain']}
+ empty = @connection.get('/text').body
+ empty.should == 'plain'
+ end
+
it 'should handle a blank response' do
@stubs.get('/empty') {[200, {'content-type' => 'application/json; charset=utf-8'}, '']}
empty = @connection.get('/empty').body

0 comments on commit 6e32170

Please sign in to comment.