@worker-tools/html
Version:
HTML templating and streaming response library for Worker Runtimes such as Cloudflare Workers.
44 lines • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.BufferedHTMLResponse = exports.HTMLResponse = void 0;
const stream_response_1 = require("@worker-tools/stream-response");
const CONTENT_TYPE = 'Content-Type';
/**
* TBD
*/
class HTMLResponse extends stream_response_1.StreamResponse {
constructor(html, { headers: _headers, ...init } = {}) {
const headers = new Headers(_headers);
if (!headers.has(CONTENT_TYPE))
headers.set(CONTENT_TYPE, HTMLResponse.contentType);
super(html, { headers, ...init });
}
}
exports.HTMLResponse = HTMLResponse;
Object.defineProperty(HTMLResponse, "contentType", {
enumerable: true,
configurable: true,
writable: true,
value: 'text/html;charset=UTF-8'
});
/**
* If for any reason you don't want to use streaming response bodies,
* you can use this class instead, which will buffer the entire body before releasing it to the network.
* Note that headers will still be sent immediately.
*/
class BufferedHTMLResponse extends stream_response_1.BufferedStreamResponse {
constructor(html, { headers: _headers, ...init } = {}) {
const headers = new Headers(_headers);
if (!headers.has(CONTENT_TYPE))
headers.set(CONTENT_TYPE, BufferedHTMLResponse.contentType);
super(html, { headers, ...init });
}
}
exports.BufferedHTMLResponse = BufferedHTMLResponse;
Object.defineProperty(BufferedHTMLResponse, "contentType", {
enumerable: true,
configurable: true,
writable: true,
value: 'text/html;charset=UTF-8'
});
//# sourceMappingURL=html-response.js.map
;