astro-ghostcms/.pnpm-store/v3/files/bf/e1037d3bc830dfb8f38785c6dc6...

41 lines
1.1 KiB
Plaintext

const clientAddressSymbol = Symbol.for("astro.clientAddress");
const clientLocalsSymbol = Symbol.for("astro.locals");
function createRequest({
url,
headers,
clientAddress,
method = "GET",
body = void 0,
logger,
ssr,
locals
}) {
let headersObj = headers instanceof Headers ? headers : new Headers(Object.entries(headers));
const request = new Request(url.toString(), {
method,
headers: headersObj,
body
});
if (!ssr) {
const _headers = request.headers;
const headersDesc = Object.getOwnPropertyDescriptor(request, "headers") || {};
Object.defineProperty(request, "headers", {
...headersDesc,
get() {
logger.warn(
null,
`\`Astro.request.headers\` is not available in "static" output mode. To enable header access: set \`output: "server"\` or \`output: "hybrid"\` in your config file.`
);
return _headers;
}
});
} else if (clientAddress) {
Reflect.set(request, clientAddressSymbol, clientAddress);
}
Reflect.set(request, clientLocalsSymbol, locals ?? {});
return request;
}
export {
createRequest
};