Skip to content

Keep response body mutable when there is no body and no Content-Type#57

Merged
olleolleolle merged 1 commit into
lostisland:mainfrom
kevinebaugh:claude/crazy-lichterman-71e241
May 29, 2026
Merged

Keep response body mutable when there is no body and no Content-Type#57
olleolleolle merged 1 commit into
lostisland:mainfrom
kevinebaugh:claude/crazy-lichterman-71e241

Conversation

@kevinebaugh

Copy link
Copy Markdown
Contributor

Summary

#56 changed the fallback in encoded_body from +'' to ''. Because lib/faraday/adapter/net_http.rb has # frozen_string_literal: true, the bare '' literal is frozen. When a response has no body and no Content-Type, the charset match block never runs (so the body is never re-duped), and encoded_body returns the frozen empty string. This becomes env.response_body, and any downstream middleware that mutates the body raises FrozenError.

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 || +''
  • Add a regression spec asserting encoded_body returns a non-frozen body when the response has no body and no Content-Type.

Test plan

  • bundle exec rspec — 386 examples, 0 failures
  • New spec fails before the revert (frozen body) and passes after
  • bundle exec rubocop — no offenses

🤖 Generated with Claude Code

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>
@kevinebaugh kevinebaugh force-pushed the claude/crazy-lichterman-71e241 branch from bf1b203 to 5bb85ea Compare May 28, 2026 22:44
@olleolleolle olleolleolle merged commit dd94639 into lostisland:main May 29, 2026
6 checks passed
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.

2 participants