Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/faraday/logging/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def dump_headers(headers)

def dump_body(body)
if body.respond_to?(:to_str)
body.to_str
body.to_str.encode(Encoding::UTF_8, undef: :replace, invalid: :replace)
else
pretty_inspect(body)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/faraday/response/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
stubs.post('/ohai') { [200, { 'Content-Type' => 'text/html' }, 'fred'] }
stubs.post('/ohyes') { [200, { 'Content-Type' => 'text/html' }, 'pebbles'] }
stubs.get('/rubbles') { [200, { 'Content-Type' => 'application/json' }, rubbles] }
stubs.get('/8bit') { [200, { 'Content-Type' => 'text/html' }, 'café!'.dup.force_encoding(Encoding::ASCII_8BIT)] }
stubs.get('/filtered_body') { [200, { 'Content-Type' => 'text/html' }, 'soylent green is people'] }
stubs.get('/filtered_headers') { [200, { 'Content-Type' => 'text/html' }, 'headers response'] }
stubs.get('/filtered_params') { [200, { 'Content-Type' => 'text/html' }, 'params response'] }
Expand Down Expand Up @@ -238,6 +239,11 @@ def response(_env)
expect(string_io.string).to match(%(fred))
end

it 'converts to UTF-8' do
conn.get '/8bit'
expect(string_io.string).to match(%(caf��!))
end

after do
described_class.default_options = { bodies: false }
end
Expand Down