204, 304 must not have a body

This commit is contained in:
Steve Burkett 2011-05-23 14:28:23 -07:00
parent 8ae879e4d5
commit 179fef4cbc
4 changed files with 38 additions and 1 deletions

3
.gitignore vendored
View File

@ -13,6 +13,9 @@ tmtags
## VIM
*.swp
## RUBYMINE
.idea
## PROJECT::GENERAL
coverage
rdoc

7
.idea/dictionaries/steveburkett.xml generated Normal file
View File

@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="steveburkett">
<words>
<w>upcaser</w>
</words>
</dictionary>
</component>

View File

@ -14,7 +14,7 @@ module Faraday
# Calls the `parse` method if defined
def on_complete(env)
if respond_to? :parse
env[:body] = parse(env[:body])
env[:body] = parse(env[:body]) unless [204,304].index env[:status]
end
end
end

View File

@ -45,3 +45,30 @@ class ResponseMiddlewareTest < Faraday::TestCase
assert_equal '<BODY></BODY>', @conn.get('ok').body
end
end
class ResponseNoBodyMiddleWareTest < Faraday::TestCase
def setup
@conn = Faraday.new do |b|
b.response :raise_error
b.adapter :test do |stub|
stub.get('not modified') { [304, nil, nil] }
stub.get('no content') { [204, nil, nil] }
end
end
@conn.builder.insert(0, NotCalled)
end
class NotCalled < Faraday::Response::Middleware
def parse(body)
raise "this should not be called"
end
end
def test_204
assert_equal nil, @conn.get('no content').body
end
def test_304
assert_equal nil, @conn.get('not modified').body
end
end