Server: add html_string and .string to ctx.send

This commit is contained in:
Starbeamrainbowlabs 2022-02-07 17:24:15 +00:00
parent e9242a929b
commit f4016857cd
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 24 additions and 0 deletions

View File

@ -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.