Permalink
Browse files

ResponseMiddleware only parses if the body is string

  • Loading branch information...
1 parent 58b7e12 commit cb85bb01082f5bdcf1ce4effab98b766ed2aeb53 @mislav committed Mar 28, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/faraday_stack/response_middleware.rb
@@ -32,7 +32,7 @@ def initialize(app = nil, options = {})
# Override this to modify the environment after the response has finished.
def on_complete(env)
- if process_response_type?(response_type(env))
+ if process_response_type?(response_type(env)) and parse_response?(env)
env[:body] = parse(env[:body])
end
end
@@ -62,5 +62,9 @@ def process_response_type?(type)
Regexp === pattern ? type =~ pattern : type == pattern
}
end
+
+ def parse_response?(env)
+ env[:body].respond_to? :to_str
+ end
end
end

0 comments on commit cb85bb0

Please sign in to comment.