Skip to content

Comments

fix: work around Bun fetch ZlibError on compressed responses#105

Open
maciej wants to merge 1 commit intosteipete:mainfrom
maciej:fix/bun-zlib-decompression
Open

fix: work around Bun fetch ZlibError on compressed responses#105
maciej wants to merge 1 commit intosteipete:mainfrom
maciej:fix/bun-zlib-decompression

Conversation

@maciej
Copy link

@maciej maciej commented Feb 20, 2026

Summary

  • avoid brotli by default by setting Accept-Encoding: gzip, deflate
  • detect Bun zlib decompression failures and retry with Accept-Encoding: identity
  • apply the safer header strategy consistently across fetch paths

Why

Bun currently throws Decompression error: ZlibError on some compressed/chunked responses that Node handles correctly.

No matching upstream summarize issue was found, so this PR is posted directly as requested.

Bun's compiled binary throws "Decompression error: ZlibError" when
fetching certain pages (e.g. theregister.com). This is a known Bun bug
in its streaming zlib decompression pipeline — it mishandles edge cases
with chunked + gzip/br responses that Node.js processes fine.

Changes:
- Set Accept-Encoding to "gzip, deflate" (exclude brotli) in all
  REQUEST_HEADERS to avoid the most problematic codec.
- Add isZlibError() detection and automatic retry with
  "Accept-Encoding: identity" in fetchHtmlDocument(), so if Bun's
  decompression still fails on gzip, the request is retried without
  any compression.

Upstream Bun issues:
- oven-sh/bun#23149 (open — ZlibError)
- oven-sh/bun#18413 (ShortRead variant)
- oven-sh/bun#8017 (original report)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant