Skip to content

Commit

Permalink
Status codes are IANA conforming
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtum authored and cmazakas committed Feb 9, 2024
1 parent 3de809f commit a8f7c92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 3 additions & 5 deletions include/boost/http_proto/status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ enum class status : unsigned short
code.
*/
switching_protocols = 101,

processing = 102,
early_hints = 103,

ok = 200,
created = 201,
Expand Down Expand Up @@ -83,13 +83,12 @@ enum class status : unsigned short
unprocessable_entity = 422,
locked = 423,
failed_dependency = 424,
too_early = 425,
upgrade_required = 426,
precondition_required = 428,
too_many_requests = 429,
request_header_fields_too_large = 431,
connection_closed_without_response = 444,
unavailable_for_legal_reasons = 451,
client_closed_request = 499,

internal_server_error = 500,
not_implemented = 501,
Expand All @@ -101,8 +100,7 @@ enum class status : unsigned short
insufficient_storage = 507,
loop_detected = 508,
not_extended = 510,
network_authentication_required = 511,
network_connect_timeout_error = 599
network_authentication_required = 511
};

/** Represents the class of a status-code.
Expand Down
11 changes: 5 additions & 6 deletions src/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int_to_status(unsigned v)
case status::continue_:
case status::switching_protocols:
case status::processing:
case status::early_hints:
BOOST_FALLTHROUGH;

// 2xx
Expand Down Expand Up @@ -72,13 +73,12 @@ int_to_status(unsigned v)
case status::unprocessable_entity:
case status::locked:
case status::failed_dependency:
case status::too_early:
case status::upgrade_required:
case status::precondition_required:
case status::too_many_requests:
case status::request_header_fields_too_large:
case status::connection_closed_without_response:
case status::unavailable_for_legal_reasons:
case status::client_closed_request:
BOOST_FALLTHROUGH;

// 5xx
Expand All @@ -93,7 +93,6 @@ int_to_status(unsigned v)
case status::loop_detected:
case status::not_extended:
case status::network_authentication_required:
case status::network_connect_timeout_error:
return static_cast<status>(v);

default:
Expand Down Expand Up @@ -134,6 +133,7 @@ obsolete_reason(
case status::continue_: return "Continue";
case status::switching_protocols: return "Switching Protocols";
case status::processing: return "Processing";
case status::early_hints: return "Early Hints";

// 2xx
case status::ok: return "OK";
Expand Down Expand Up @@ -180,13 +180,13 @@ obsolete_reason(
case status::unprocessable_entity: return "Unprocessable Entity";
case status::locked: return "Locked";
case status::failed_dependency: return "Failed Dependency";
case status::too_early: return "Too Early";
case status::upgrade_required: return "Upgrade Required";
case status::precondition_required: return "Precondition Required";
case status::too_many_requests: return "Too Many Requests";
case status::request_header_fields_too_large: return "Request Header Fields Too Large";
case status::connection_closed_without_response: return "Connection Closed Without Response";
case status::unavailable_for_legal_reasons: return "Unavailable For Legal Reasons";
case status::client_closed_request: return "Client Closed Request";

// 5xx
case status::internal_server_error: return "Internal Server Error";
case status::not_implemented: return "Not Implemented";
Expand All @@ -199,7 +199,6 @@ obsolete_reason(
case status::loop_detected: return "Loop Detected";
case status::not_extended: return "Not Extended";
case status::network_authentication_required: return "Network Authentication Required";
case status::network_connect_timeout_error: return "Network Connect Timeout Error";

default:
break;
Expand Down
7 changes: 4 additions & 3 deletions test/unit/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class status_test
check(status::continue_ ,100, status_class::informational);
check(status::switching_protocols ,101, status_class::informational);
check(status::processing ,102, status_class::informational);
check(status::early_hints ,103, status_class::informational);

check(status::ok ,200, status_class::successful);
check(status::created ,201, status_class::successful);
Expand Down Expand Up @@ -73,13 +74,12 @@ class status_test
check(status::unprocessable_entity ,422, status_class::client_error);
check(status::locked ,423, status_class::client_error);
check(status::failed_dependency ,424, status_class::client_error);
check(status::too_early ,425, status_class::client_error);
check(status::upgrade_required ,426, status_class::client_error);
check(status::precondition_required ,428, status_class::client_error);
check(status::too_many_requests ,429, status_class::client_error);
check(status::request_header_fields_too_large ,431, status_class::client_error);
check(status::connection_closed_without_response ,444, status_class::client_error);
check(status::unavailable_for_legal_reasons ,451, status_class::client_error);
check(status::client_closed_request ,499, status_class::client_error);

check(status::internal_server_error ,500, status_class::server_error);
check(status::not_implemented ,501, status_class::server_error);
Expand All @@ -92,7 +92,6 @@ class status_test
check(status::loop_detected ,508, status_class::server_error);
check(status::not_extended ,510, status_class::server_error);
check(status::network_authentication_required ,511, status_class::server_error);
check(status::network_connect_timeout_error ,599, status_class::server_error);

BOOST_TEST(to_status_class(1) == status_class::unknown);
BOOST_TEST(to_status_class(status::unknown) == status_class::unknown);
Expand All @@ -105,6 +104,7 @@ class status_test
good(status::continue_);
good(status::switching_protocols);
good(status::processing);
good(status::early_hints);
good(status::ok);
good(status::created);
good(status::accepted);
Expand Down Expand Up @@ -145,6 +145,7 @@ class status_test
good(status::unprocessable_entity);
good(status::locked);
good(status::failed_dependency);
good(status::too_early);
good(status::upgrade_required);
good(status::precondition_required);
good(status::too_many_requests);
Expand Down

0 comments on commit a8f7c92

Please sign in to comment.