Files
SnowLuma/.pnpm-store/v11/files/7e/bdd71a41457a5555d993f7292b13d170592b866138fdbee18f658a108ce01ee2d2324a37be3375a203fa6ccf96d2cda980f542ad475de1efeafeb1f2e26eb3
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

35 lines
1.2 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
//#region src/early-hints.ts
/**
* Early Hints middleware for Node.js
* Automatically sends a 103 Early Hints informational response with the specified Link header(s).
*
* @param options EarlyHintsOptions
* @returns MiddlewareHandler
*/
const earlyHints = (options) => {
let warned = false;
return async (c, next) => {
const mode = c.req.header("Sec-Fetch-Mode");
const dest = c.req.header("Sec-Fetch-Dest");
if (mode && mode !== "navigate" || dest && dest !== "document") return next();
const env = c.env || {};
const outgoing = ("server" in env ? env.server : env)?.outgoing;
if (typeof outgoing?.writeEarlyHints !== "function") {
if (!warned) {
console.warn("Early Hints Middleware is not supported because writeEarlyHints is not defined.");
warned = true;
}
return await next();
}
if (!outgoing.headersSent) {
const link = typeof options.link === "function" ? options.link(c) : options.link;
if (link !== void 0 && (Array.isArray(link) ? link.length > 0 : Boolean(link))) outgoing.writeEarlyHints({ link });
}
await next();
};
};
//#endregion
exports.earlyHints = earlyHints;