Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "cloneResponse", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return cloneResponse;
|
|
}
|
|
});
|
|
const noop = ()=>{};
|
|
let registry;
|
|
if (globalThis.FinalizationRegistry) {
|
|
registry = new FinalizationRegistry((weakRef)=>{
|
|
const stream = weakRef.deref();
|
|
if (stream && !stream.locked) {
|
|
stream.cancel('Response object has been garbage collected').then(noop);
|
|
}
|
|
});
|
|
}
|
|
function cloneResponse(original) {
|
|
// If the response has no body, then we can just return the original response
|
|
// twice because it's immutable.
|
|
if (!original.body) {
|
|
return [
|
|
original,
|
|
original
|
|
];
|
|
}
|
|
const [body1, body2] = original.body.tee();
|
|
const cloned1 = new Response(body1, {
|
|
status: original.status,
|
|
statusText: original.statusText,
|
|
headers: original.headers
|
|
});
|
|
Object.defineProperty(cloned1, 'url', {
|
|
value: original.url,
|
|
// How the original response.url behaves
|
|
configurable: true,
|
|
enumerable: true,
|
|
writable: false
|
|
});
|
|
const cloned2 = new Response(body2, {
|
|
status: original.status,
|
|
statusText: original.statusText,
|
|
headers: original.headers
|
|
});
|
|
Object.defineProperty(cloned2, 'url', {
|
|
value: original.url,
|
|
// How the original response.url behaves
|
|
configurable: true,
|
|
enumerable: true,
|
|
writable: false
|
|
});
|
|
// The Fetch Standard allows users to skip consuming the response body by
|
|
// relying on garbage collection to release connection resources.
|
|
// https://github.com/nodejs/undici?tab=readme-ov-file#garbage-collection
|
|
//
|
|
// To cancel the stream you then need to cancel both resulting branches.
|
|
// Teeing a stream will generally lock it for the duration, preventing other
|
|
// readers from locking it.
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee
|
|
if (registry) {
|
|
if (cloned1.body) {
|
|
registry.register(cloned1, new WeakRef(cloned1.body));
|
|
}
|
|
if (cloned2.body) {
|
|
registry.register(cloned2, new WeakRef(cloned2.body));
|
|
}
|
|
}
|
|
return [
|
|
cloned1,
|
|
cloned2
|
|
];
|
|
}
|
|
|
|
//# sourceMappingURL=clone-response.js.map
|