From f4016857cd30a1831d252770da59717d930f2639 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 7 Feb 2022 17:24:15 +0000 Subject: [PATCH] Server: add html_string and .string to ctx.send --- Server/Sender.mjs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Server/Sender.mjs b/Server/Sender.mjs index c003226..f5acb10 100644 --- a/Server/Sender.mjs +++ b/Server/Sender.mjs @@ -28,6 +28,30 @@ class Sender { this.response.end(response_html); } + /** + * Sends a given string as a HTML response + * @param {number} status_code The status code to return. + * @param {string} html_string The string of HTML to send. + * @return {void} + */ + html_str(status_code, html_string) { + this.string(status_code, "text/html", html_string); + } + /** + * Sends a given string with a given content-type. + * @param {number} status_code The status code to return. + * @param {number} type The content-type header value to send. This should be a MIME type, such as "text/html". + * @param {string} str The string to send. + * @return {void} + */ + string(status_code, type, str) { + this.response.writeHead(status_code, { + "content-type": type, + "content-length": Buffer.byteLength(str, "utf8") + }); + this.response.end(str); + } + /** * Sends a plain text response. * @param {number} status_code The HTTP status code to return.