Skip to content

Commit

Permalink
Add statusText automatically on res.status() (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikilele authored Jul 8, 2021
1 parent 42d9bdf commit bdba3b1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions KyukoResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export class KyukoResponse {
*/
status(status: number): this {
this.statusCode = status;
const statusText = KyukoResponse.STATUSES.get(status);
if (statusText !== undefined) {
this.statusText = statusText;
}

return this;
}

Expand Down Expand Up @@ -65,4 +70,51 @@ export class KyukoResponse {
wasSent(): boolean {
return this.#sent;
}

/*
* status code -> reason phrase
*/
private static STATUSES = new Map<number, string>([
[100, "Continue"],
[101, "Switching Protocols"],
[200, "OK"],
[201, "Created"],
[202, "Accepted"],
[203, "Non-Authoritative Information"],
[204, "No Content"],
[205, "Reset Content"],
[206, "Partial Content"],
[300, "Multiple Choices"],
[301, "Moved Permanently"],
[302, "Found"],
[303, "See Other"],
[304, "Not Modified"],
[305, "Use Proxy"],
[307, "Temporary Redirect"],
[400, "Bad Request"],
[401, "Unauthorized"],
[402, "Payment Required"],
[403, "Forbidden"],
[404, "Haha"],
[405, "Method Not Allowed"],
[406, "Not Acceptable"],
[407, "Proxy Authentication Required"],
[408, "Request Timeout"],
[409, "Conflict"],
[410, "Gone"],
[411, "Length Required"],
[412, "Precondition Failed"],
[413, "Payload Too Large"],
[414, "URI Too Long"],
[415, "Unsupported Media Type"],
[416, "Range Not Satisfiable"],
[417, "Expectation Failed"],
[426, "Upgrade Required"],
[500, "Internal Server Error"],
[501, "Not Implemented"],
[502, "Bad Gateway"],
[503, "Service Unavailable"],
[504, "Gateway Timeout"],
[505, "HTTP Version Not Supported"],
]);
}

0 comments on commit bdba3b1

Please sign in to comment.