mirror of
https://github.com/sbrl/powahroot.git
synced 2024-11-21 14:13:01 +00:00
Server: add html_string and .string to ctx.send
This commit is contained in:
parent
e9242a929b
commit
f4016857cd
1 changed files with 24 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue