@broberg/http

中文文档
0.1.0发布于 2026/07/18MITTypeScriptESM + CJS零依赖近 30 天下载 6319

Framework-free HTTP header/response primitives (Node/Bun/edge), zero-dep. Seed: contentDisposition() builds an RFC 5987 Content-Disposition value (ASCII filename= fallback + filename*=UTF-8'' pct-encoded) that preserves non-ASCII filenames (æøå) and is he

原始使用文档

@broberg/http

Framework-free HTTP header/response primitives — Node, Bun, and edge, with zero runtime dependencies. Each helper returns a string; you set the header.

npm i @broberg/http

contentDisposition(filename, opts?)

Build a Content-Disposition value that survives non-ASCII filenames (æøå).

A raw non-ASCII byte in this header makes Bun reject it → HTTP 500 on download. The fix (RFC 5987 / RFC 6266) is to emit both an ASCII filename="..." fallback (old clients) and a filename*=UTF-8''<pct-encoded> form (modern clients prefer it) — so the user downloads brændte-filer.pdf with its real characters instead of a mangled transliteration.

import { contentDisposition } from "@broberg/http";

res.headers.set("Content-Disposition", contentDisposition("brændte-filer.pdf"));
// → attachment; filename="br_ndte-filer.pdf"; filename*=UTF-8''br%C3%A6ndte-filer.pdf

contentDisposition("report.pdf", { disposition: "inline" });
// → inline; filename="report.pdf"; filename*=UTF-8''report.pdf
  • disposition — "attachment" (default) or "inline".
  • ASCII fallback — control chars + CR/LF stripped, path separators / non-ASCII / " \ replaced with _; an empty name becomes download.
  • RFC 5987 form — encodeURIComponent plus the four attr-char-reserved characters ' ( ) * percent-encoded.
  • Header-injection safe — CR/LF and control characters are always removed.

MIT · part of the @broberg/* shared-library family.

版本与发布记录

@broberg/http 共发布 1 个版本,首次发布于 2026/07/18;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.0latest2026/07/183 个月前

关于 @broberg/http 的常见问题

@broberg/http 是什么?

Framework-free HTTP header/response primitives (Node/Bun/edge), zero-dep. Seed: contentDisposition() builds an RFC 5987 Content-Disposition value (ASCII filename= fallback + filename*=UTF-8'' pct-encoded) that preserves non-ASCII filenames (æøå) and is he

如何安装 @broberg/http?

在项目目录运行 npm install @broberg/http,或使用 pnpm add / yarn add / bun add。

@broberg/http 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@broberg/http 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@broberg/http 可以商用吗?

@broberg/http 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@broberg/http 的下载量有多少?

根据 npm 官方下载统计,@broberg/http 在 2026/10/09 – 2026/11/07 这 30 天内被下载 6,319 次,日均约 211 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@broberg/http 还在维护吗?

最新版本 0.1.0 发布于 2026/07/18(3 个月前);至今共发布 1 个版本,其中过去 12 个月发布了 1 个;首次发布于 2026/07/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。