UNPKG

1.63 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.BufferedHTMLResponse = exports.HTMLResponse = void 0;
4const stream_response_1 = require("@worker-tools/stream-response");
5const CONTENT_TYPE = 'Content-Type';
6/**
7 * TBD
8 */
9class HTMLResponse extends stream_response_1.StreamResponse {
10 constructor(html, { headers: _headers, ...init } = {}) {
11 const headers = new Headers(_headers);
12 if (!headers.has(CONTENT_TYPE))
13 headers.set(CONTENT_TYPE, HTMLResponse.contentType);
14 super(html, { headers, ...init });
15 }
16}
17exports.HTMLResponse = HTMLResponse;
18Object.defineProperty(HTMLResponse, "contentType", {
19 enumerable: true,
20 configurable: true,
21 writable: true,
22 value: 'text/html;charset=UTF-8'
23});
24/**
25 * If for any reason you don't want to use streaming response bodies,
26 * you can use this class instead, which will buffer the entire body before releasing it to the network.
27 * Note that headers will still be sent immediately.
28 */
29class BufferedHTMLResponse extends stream_response_1.BufferedStreamResponse {
30 constructor(html, { headers: _headers, ...init } = {}) {
31 const headers = new Headers(_headers);
32 if (!headers.has(CONTENT_TYPE))
33 headers.set(CONTENT_TYPE, BufferedHTMLResponse.contentType);
34 super(html, { headers, ...init });
35 }
36}
37exports.BufferedHTMLResponse = BufferedHTMLResponse;
38Object.defineProperty(BufferedHTMLResponse, "contentType", {
39 enumerable: true,
40 configurable: true,
41 writable: true,
42 value: 'text/html;charset=UTF-8'
43});
44//# sourceMappingURL=html-response.js.map
\No newline at end of file