Keep response body mutable when there is no body and no Content-Type#57
Merged
olleolleolle merged 1 commit intoMay 29, 2026
Merged
Conversation
PR lostisland#56 changed the fallback in `encoded_body` from `+''` to `''`. With `frozen_string_literal: true`, the bare literal is frozen, so a response with no body and no Content-Type returns a frozen empty string that raises FrozenError when downstream middleware mutates it. Restore the unary `+` to keep the fallback mutable, as suggested by the maintainer. Co-Authored-By: jakeonfire <68826+jakeonfire@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bf1b203 to
5bb85ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#56 changed the fallback in
encoded_bodyfrom+''to''. Becauselib/faraday/adapter/net_http.rbhas# frozen_string_literal: true, the bare''literal is frozen. When a response has no body and noContent-Type, thecharsetmatch block never runs (so the body is never re-duped), andencoded_bodyreturns the frozen empty string. This becomesenv.response_body, and any downstream middleware that mutates the body raisesFrozenError.This was reported in #56 (comment) and @byroot confirmed that line 190 could be reverted. This restores the unary
+so the fallback stays mutable, leaving the rest of #56 intact.Changes
lib/faraday/adapter/net_http.rb:http_response.body || ''→http_response.body || +''encoded_bodyreturns a non-frozen body when the response has no body and noContent-Type.Test plan
bundle exec rspec— 386 examples, 0 failuresbundle exec rubocop— no offenses🤖 Generated with Claude Code