mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
204, 304 must not have a body
This commit is contained in:
parent
8ae879e4d5
commit
179fef4cbc
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,6 +13,9 @@ tmtags
|
||||
## VIM
|
||||
*.swp
|
||||
|
||||
## RUBYMINE
|
||||
.idea
|
||||
|
||||
## PROJECT::GENERAL
|
||||
coverage
|
||||
rdoc
|
||||
|
7
.idea/dictionaries/steveburkett.xml
generated
Normal file
7
.idea/dictionaries/steveburkett.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="steveburkett">
|
||||
<words>
|
||||
<w>upcaser</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
@ -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
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user