Skip to content

Impit response.text() returns corrupted HTML with garbage bytes when running under Bun #363

@garysassano

Description

@garysassano

When using Impit with Bun, response.text() returns HTML with leading garbage bytes, making the response binary/unviewable. The same code running under Node.js returns clean, valid HTML.

  • On amazon.it: Response is completely corrupted, file is binary/unviewable
  • On amazon.com: Response is viewable but contains extra encoded/garbled bytes scattered throughout

When running the exact same code with Node.js, both URLs return clean UTF-8 HTML starting with <!doctype html>.

Repro steps

  1. Install dependencies: npm install impit
  2. Create test file:
import { Impit } from "impit";

const impit = new Impit();
const res = await impit.fetch("https://www.amazon.it/dp/B00LH3DMUO", {
  method: "GET",
  headers: { "accept-encoding": "identity" },
});

console.log("Status:", res.status);
console.log("Content-Encoding:", res.headers.get("content-encoding"));
console.log("Content-Type:", res.headers.get("content-type"));

const html = await res.text();
console.log("Preview:", html.slice(0, 200));
  1. Run with Bun: bun run test.tscorrupted output
  2. Run with Node: node test.mjsclean HTML

Expected

res.text() returns valid HTML starting with <!doctype html> regardless of runtime.

Actual (Bun)

  • amazon.it: res.text() starts with non-UTF8 garbage bytes; saved file is binary/unviewable
  • amazon.com: Response is viewable but contains scattered encoded/garbled bytes (e.g., �Y�S=t� interspersed in HTML)
  • content-encoding header is null

Actual (Node.js)

  • Both URLs return clean UTF-8 HTML starting with <!doctype html>
  • No garbage bytes, file is viewable and valid

Environment

  • OS: Linux
  • impit version: ^0.8.2
  • Bun version: latest
  • Node.js version: LTS
  • content-type returned: text/html;charset=UTF-8

Additional observations

  • The issue only occurs when running under Bun; Node.js works correctly
  • Plain Bun fetch() (without Impit) also returns clean HTML, so the issue is specific to Impit + Bun combination
  • Setting accept-encoding: identity does not fix the issue under Bun

Metadata

Metadata

Assignees

Labels

t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions