Skip to content

Commit afb0674

Browse files
committed
1 parent ee62523 commit afb0674

File tree

1 file changed

+74
-72
lines changed

1 file changed

+74
-72
lines changed

httplib.h

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ using SocketOptions = std::function<void(socket_t sock)>;
668668

669669
void default_socket_options(socket_t sock);
670670

671+
const char *status_message(int status);
672+
671673
namespace detail {
672674

673675
class MatcherBase {
@@ -1776,6 +1778,76 @@ inline void default_socket_options(socket_t sock) {
17761778
#endif
17771779
}
17781780

1781+
inline const char *status_message(int status) {
1782+
switch (status) {
1783+
case 100: return "Continue";
1784+
case 101: return "Switching Protocol";
1785+
case 102: return "Processing";
1786+
case 103: return "Early Hints";
1787+
case 200: return "OK";
1788+
case 201: return "Created";
1789+
case 202: return "Accepted";
1790+
case 203: return "Non-Authoritative Information";
1791+
case 204: return "No Content";
1792+
case 205: return "Reset Content";
1793+
case 206: return "Partial Content";
1794+
case 207: return "Multi-Status";
1795+
case 208: return "Already Reported";
1796+
case 226: return "IM Used";
1797+
case 300: return "Multiple Choice";
1798+
case 301: return "Moved Permanently";
1799+
case 302: return "Found";
1800+
case 303: return "See Other";
1801+
case 304: return "Not Modified";
1802+
case 305: return "Use Proxy";
1803+
case 306: return "unused";
1804+
case 307: return "Temporary Redirect";
1805+
case 308: return "Permanent Redirect";
1806+
case 400: return "Bad Request";
1807+
case 401: return "Unauthorized";
1808+
case 402: return "Payment Required";
1809+
case 403: return "Forbidden";
1810+
case 404: return "Not Found";
1811+
case 405: return "Method Not Allowed";
1812+
case 406: return "Not Acceptable";
1813+
case 407: return "Proxy Authentication Required";
1814+
case 408: return "Request Timeout";
1815+
case 409: return "Conflict";
1816+
case 410: return "Gone";
1817+
case 411: return "Length Required";
1818+
case 412: return "Precondition Failed";
1819+
case 413: return "Payload Too Large";
1820+
case 414: return "URI Too Long";
1821+
case 415: return "Unsupported Media Type";
1822+
case 416: return "Range Not Satisfiable";
1823+
case 417: return "Expectation Failed";
1824+
case 418: return "I'm a teapot";
1825+
case 421: return "Misdirected Request";
1826+
case 422: return "Unprocessable Entity";
1827+
case 423: return "Locked";
1828+
case 424: return "Failed Dependency";
1829+
case 425: return "Too Early";
1830+
case 426: return "Upgrade Required";
1831+
case 428: return "Precondition Required";
1832+
case 429: return "Too Many Requests";
1833+
case 431: return "Request Header Fields Too Large";
1834+
case 451: return "Unavailable For Legal Reasons";
1835+
case 501: return "Not Implemented";
1836+
case 502: return "Bad Gateway";
1837+
case 503: return "Service Unavailable";
1838+
case 504: return "Gateway Timeout";
1839+
case 505: return "HTTP Version Not Supported";
1840+
case 506: return "Variant Also Negotiates";
1841+
case 507: return "Insufficient Storage";
1842+
case 508: return "Loop Detected";
1843+
case 510: return "Not Extended";
1844+
case 511: return "Network Authentication Required";
1845+
1846+
default:
1847+
case 500: return "Internal Server Error";
1848+
}
1849+
}
1850+
17791851
template <class Rep, class Period>
17801852
inline Server &
17811853
Server::set_read_timeout(const std::chrono::duration<Rep, Period> &duration) {
@@ -3180,76 +3252,6 @@ find_content_type(const std::string &path,
31803252
}
31813253
}
31823254

3183-
inline const char *status_message(int status) {
3184-
switch (status) {
3185-
case 100: return "Continue";
3186-
case 101: return "Switching Protocol";
3187-
case 102: return "Processing";
3188-
case 103: return "Early Hints";
3189-
case 200: return "OK";
3190-
case 201: return "Created";
3191-
case 202: return "Accepted";
3192-
case 203: return "Non-Authoritative Information";
3193-
case 204: return "No Content";
3194-
case 205: return "Reset Content";
3195-
case 206: return "Partial Content";
3196-
case 207: return "Multi-Status";
3197-
case 208: return "Already Reported";
3198-
case 226: return "IM Used";
3199-
case 300: return "Multiple Choice";
3200-
case 301: return "Moved Permanently";
3201-
case 302: return "Found";
3202-
case 303: return "See Other";
3203-
case 304: return "Not Modified";
3204-
case 305: return "Use Proxy";
3205-
case 306: return "unused";
3206-
case 307: return "Temporary Redirect";
3207-
case 308: return "Permanent Redirect";
3208-
case 400: return "Bad Request";
3209-
case 401: return "Unauthorized";
3210-
case 402: return "Payment Required";
3211-
case 403: return "Forbidden";
3212-
case 404: return "Not Found";
3213-
case 405: return "Method Not Allowed";
3214-
case 406: return "Not Acceptable";
3215-
case 407: return "Proxy Authentication Required";
3216-
case 408: return "Request Timeout";
3217-
case 409: return "Conflict";
3218-
case 410: return "Gone";
3219-
case 411: return "Length Required";
3220-
case 412: return "Precondition Failed";
3221-
case 413: return "Payload Too Large";
3222-
case 414: return "URI Too Long";
3223-
case 415: return "Unsupported Media Type";
3224-
case 416: return "Range Not Satisfiable";
3225-
case 417: return "Expectation Failed";
3226-
case 418: return "I'm a teapot";
3227-
case 421: return "Misdirected Request";
3228-
case 422: return "Unprocessable Entity";
3229-
case 423: return "Locked";
3230-
case 424: return "Failed Dependency";
3231-
case 425: return "Too Early";
3232-
case 426: return "Upgrade Required";
3233-
case 428: return "Precondition Required";
3234-
case 429: return "Too Many Requests";
3235-
case 431: return "Request Header Fields Too Large";
3236-
case 451: return "Unavailable For Legal Reasons";
3237-
case 501: return "Not Implemented";
3238-
case 502: return "Bad Gateway";
3239-
case 503: return "Service Unavailable";
3240-
case 504: return "Gateway Timeout";
3241-
case 505: return "HTTP Version Not Supported";
3242-
case 506: return "Variant Also Negotiates";
3243-
case 507: return "Insufficient Storage";
3244-
case 508: return "Loop Detected";
3245-
case 510: return "Not Extended";
3246-
case 511: return "Network Authentication Required";
3247-
3248-
default:
3249-
case 500: return "Internal Server Error";
3250-
}
3251-
}
3252-
32533255
inline bool can_compress_content_type(const std::string &content_type) {
32543256
using udl::operator""_t;
32553257

@@ -5692,7 +5694,7 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
56925694
detail::BufferStream bstrm;
56935695

56945696
if (!bstrm.write_format("HTTP/1.1 %d %s\r\n", res.status,
5695-
detail::status_message(res.status))) {
5697+
status_message(res.status))) {
56965698
return false;
56975699
}
56985700

@@ -6328,7 +6330,7 @@ Server::process_request(Stream &strm, bool close_connection,
63286330
case 100:
63296331
case 417:
63306332
strm.write_format("HTTP/1.1 %d %s\r\n\r\n", status,
6331-
detail::status_message(status));
6333+
status_message(status));
63326334
break;
63336335
default: return write_response(strm, close_connection, req, res);
63346336
}

0 commit comments

Comments
 (0)