mirror of
https://github.com/lostisland/faraday.git
synced 2025-08-29 00:03:58 -04:00
Ensure empty body responses are consistently returned as empty strings.
Zero-byte response bodies can be represented as either nil or '' in ruby. Most ruby HTTP clients use '' (which, conveniently, allows clients to assume the body is always a string), but Net::HTTP, for whatever reason, uses nil. This change makes it so that all faraday adapters consistently return '' for zero-byte response bodies.
This commit is contained in:
parent
55b4c73313
commit
f41ffaabb7
@ -38,7 +38,7 @@ module Faraday
|
||||
raise Error::ConnectionFailed, $!
|
||||
end
|
||||
|
||||
save_response(env, http_response.code.to_i, http_response.body) do |response_headers|
|
||||
save_response(env, http_response.code.to_i, http_response.body || '') do |response_headers|
|
||||
http_response.each_header do |key, value|
|
||||
response_headers[key] = value
|
||||
end
|
||||
|
@ -159,6 +159,11 @@ module Adapters
|
||||
end
|
||||
end
|
||||
|
||||
def test_empty_body_response_represented_as_blank_string
|
||||
response = get('204')
|
||||
assert_equal '', response.body
|
||||
end
|
||||
|
||||
def adapter
|
||||
raise NotImplementedError.new("Need to override #adapter")
|
||||
end
|
||||
|
@ -46,6 +46,10 @@ class LiveServer < Sinatra::Base
|
||||
[200, {}, 'ok']
|
||||
end
|
||||
|
||||
get '/204' do
|
||||
status 204 # no content
|
||||
end
|
||||
|
||||
error do |e|
|
||||
"#{e.class}\n#{e.to_s}\n#{e.backtrace.join("\n")}"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user