Skip to content

Conversation

@c960657
Copy link
Contributor

@c960657 c960657 commented May 14, 2025

Description

If the HTTP response body contains 8bit characters, and the adapter does not set the encoding of body to UTF-8 (like here: lostisland/faraday-net_http#13), the logger middleware fails with an error such as this:

log writing failed. "\xC3" from ASCII-8BIT to UTF-8

With this PR, the body is converted to UTF-8, replacing any 8-bit characters with the replacement character (U+FFFD, �).

Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this @c960657 and apologies if it took me so long to get to it 🙇
This fix only affects the logger and is not touching the actual response body, so it should be perfectly backwards-compatible 🙌

Addresses the following offense:
```
[Correctable] Performance/UnfreezeString: Use unary plus to get an unfrozen string literal.
```

Caused by: `'café!'.dup`
@iMacTia iMacTia merged commit fd81a73 into lostisland:main Sep 20, 2025
8 checks passed
@stanley90
Copy link

Hi, I seem to have a problem caused by this:

NameError - uninitialized constant Faraday::Encoding::UTF_8

Maybe the Encoding::UTF_8 should be prefixed with ::?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants