mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-09 00:04:39 -04:00
Merge pull request #61 from steveburkett/master
204, 304 must not have a body
This commit is contained in:
commit
006824f4ed
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,6 +13,9 @@ tmtags
|
|||||||
## VIM
|
## VIM
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
|
## RUBYMINE
|
||||||
|
.idea
|
||||||
|
|
||||||
## PROJECT::GENERAL
|
## PROJECT::GENERAL
|
||||||
coverage
|
coverage
|
||||||
rdoc
|
rdoc
|
||||||
|
@ -14,7 +14,7 @@ module Faraday
|
|||||||
# Calls the `parse` method if defined
|
# Calls the `parse` method if defined
|
||||||
def on_complete(env)
|
def on_complete(env)
|
||||||
if respond_to? :parse
|
if respond_to? :parse
|
||||||
env[:body] = parse(env[:body])
|
env[:body] = parse(env[:body]) unless [204,304].index env[:status]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,3 +45,30 @@ class ResponseMiddlewareTest < Faraday::TestCase
|
|||||||
assert_equal '<BODY></BODY>', @conn.get('ok').body
|
assert_equal '<BODY></BODY>', @conn.get('ok').body
|
||||||
end
|
end
|
||||||
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