@@ -468,82 +468,85 @@ namespace http
468468
469469// ----------------------------------------------------------------------------------------------------------------
470470
471- std::string_view status_label (const status_type v)
472- {
473- switch (v)
474- {
471+ constexpr std::pair<status_type, std::string_view> STATUS_LABELS[] = {
475472 // 1xx
476- case status_type::continue_: return " Continue" ;
477- case status_type::switching_protocols: return " Switching Protocols" ;
478- case status_type::processing: return " Processing" ;
479- case status_type::early_hints: return " Early Hints" ;
473+ { status_type::continue_, " Continue" },
474+ { status_type::switching_protocols, " Switching Protocols" },
475+ { status_type::processing, " Processing" },
476+ { status_type::early_hints, " Early Hints" },
480477
481478 // 2xx
482- case status_type::ok: return " OK" ;
483- case status_type::created: return " Created" ;
484- case status_type::accepted: return " Accepted" ;
485- case status_type::non_authoritative_information: return " Non-Authoritative Information" ;
486- case status_type::no_content: return " No Content" ;
487- case status_type::reset_content: return " Reset Content" ;
488- case status_type::partial_content: return " Partial Content" ;
489- case status_type::multi_status: return " Multi-Status" ;
490- case status_type::already_reported: return " Already Reported" ;
491- case status_type::im_used: return " IM Used" ;
479+ { status_type::ok, " OK" },
480+ { status_type::created, " Created" },
481+ { status_type::accepted, " Accepted" },
482+ { status_type::non_authoritative_information, " Non-Authoritative Information" },
483+ { status_type::no_content, " No Content" },
484+ { status_type::reset_content, " Reset Content" },
485+ { status_type::partial_content, " Partial Content" },
486+ { status_type::multi_status, " Multi-Status" },
487+ { status_type::already_reported, " Already Reported" },
488+ { status_type::im_used, " IM Used" },
492489
493490 // 3xx
494- case status_type::multiple_choices: return " Multiple Choices" ;
495- case status_type::moved_permanently: return " Moved Permanently" ;
496- case status_type::found: return " Found" ;
497- case status_type::see_other: return " See Other" ;
498- case status_type::not_modified: return " Not Modified" ;
499- case status_type::use_proxy: return " Use Proxy" ;
500- case status_type::temporary_redirect: return " Temporary Redirect" ;
501- case status_type::permanent_redirect: return " Permanent Redirect" ;
491+ { status_type::multiple_choices, " Multiple Choices" },
492+ { status_type::moved_permanently, " Moved Permanently" },
493+ { status_type::found, " Found" },
494+ { status_type::see_other, " See Other" },
495+ { status_type::not_modified, " Not Modified" },
496+ { status_type::use_proxy, " Use Proxy" },
497+ { status_type::temporary_redirect, " Temporary Redirect" },
498+ { status_type::permanent_redirect, " Permanent Redirect" },
502499
503500 // 4xx
504- case status_type::bad_request: return " Bad Request" ;
505- case status_type::unauthorized: return " Unauthorized" ;
506- case status_type::payment_required: return " Payment Required" ;
507- case status_type::forbidden: return " Forbidden" ;
508- case status_type::not_found: return " Not Found" ;
509- case status_type::method_not_allowed: return " Method Not Allowed" ;
510- case status_type::not_acceptable: return " Not Acceptable" ;
511- case status_type::proxy_authentication_required: return " Proxy Authentication Required" ;
512- case status_type::request_timeout: return " Request Timeout" ;
513- case status_type::conflict: return " Conflict" ;
514- case status_type::gone: return " Gone" ;
515- case status_type::length_required: return " Length Required" ;
516- case status_type::precondition_failed: return " Precondition Failed" ;
517- case status_type::payload_too_large: return " Payload Too Large" ;
518- case status_type::uri_too_long: return " URI Too Long" ;
519- case status_type::unsupported_media_type: return " Unsupported Media Type" ;
520- case status_type::range_not_satisfiable: return " Range Not Satisfiable" ;
521- case status_type::expectation_failed: return " Expectation Failed" ;
522- case status_type::i_am_a_teapot: return " I'm a teapot" ;
523- case status_type::misdirected_request: return " Misdirected Request" ;
524- case status_type::unprocessable_entity: return " Unprocessable Entity" ;
525- case status_type::locked: return " Locked" ;
526- case status_type::failed_dependency: return " Failed Dependency" ;
527- case status_type::too_early: return " Too Early" ;
528- case status_type::upgrade_required: return " Upgrade Required" ;
529- case status_type::precondition_required: return " Precondition Required" ;
530- case status_type::too_many_requests: return " Too Many Requests" ;
531- case status_type::request_header_fields_too_large: return " Request Header Fields Too Large" ;
532- case status_type::unavailable_for_legal_reasons: return " Unavailable For Legal Reasons" ;
501+ {status_type::bad_request, " Bad Request" },
502+ {status_type::unauthorized, " Unauthorized" },
503+ {status_type::payment_required, " Payment Required" },
504+ {status_type::forbidden, " Forbidden" },
505+ {status_type::not_found, " Not Found" },
506+ {status_type::method_not_allowed, " Method Not Allowed" },
507+ {status_type::not_acceptable, " Not Acceptable" },
508+ {status_type::proxy_authentication_required, " Proxy Authentication Required" },
509+ {status_type::request_timeout, " Request Timeout" },
510+ {status_type::conflict, " Conflict" },
511+ {status_type::gone, " Gone" },
512+ {status_type::length_required, " Length Required" },
513+ {status_type::precondition_failed, " Precondition Failed" },
514+ {status_type::payload_too_large, " Payload Too Large" },
515+ {status_type::uri_too_long, " URI Too Long" },
516+ {status_type::unsupported_media_type, " Unsupported Media Type" },
517+ {status_type::range_not_satisfiable, " Range Not Satisfiable" },
518+ {status_type::expectation_failed, " Expectation Failed" },
519+ {status_type::i_am_a_teapot, " I'm a teapot" },
520+ {status_type::misdirected_request, " Misdirected Request" },
521+ {status_type::unprocessable_entity, " Unprocessable Entity" },
522+ {status_type::locked, " Locked" },
523+ {status_type::failed_dependency, " Failed Dependency" },
524+ {status_type::too_early, " Too Early" },
525+ {status_type::upgrade_required, " Upgrade Required" },
526+ {status_type::precondition_required, " Precondition Required" },
527+ {status_type::too_many_requests, " Too Many Requests" },
528+ {status_type::request_header_fields_too_large, " Request Header Fields Too Large" },
529+ {status_type::unavailable_for_legal_reasons, " Unavailable For Legal Reasons" },
530+
533531 // 5xx
534- case status_type::internal_server_error: return " Internal Server Error" ;
535- case status_type::not_implemented: return " Not Implemented" ;
536- case status_type::bad_gateway: return " Bad Gateway" ;
537- case status_type::service_unavailable: return " Service Unavailable" ;
538- case status_type::gateway_timeout: return " Gateway Timeout" ;
539- case status_type::http_version_not_supported: return " HTTP Version Not Supported" ;
540- case status_type::variant_also_negotiates: return " Variant Also Negotiates" ;
541- case status_type::insufficient_storage: return " Insufficient Storage" ;
542- case status_type::loop_detected: return " Loop Detected" ;
543- case status_type::not_extended: return " Not Extended" ;
544- case status_type::network_authentication_required: return " Network Authentication Required" ;
545- default : break ;
546- }
532+ {status_type::internal_server_error, " Internal Server Error" },
533+ {status_type::not_implemented, " Not Implemented" },
534+ {status_type::bad_gateway, " Bad Gateway" },
535+ {status_type::service_unavailable, " Service Unavailable" },
536+ {status_type::gateway_timeout, " Gateway Timeout" },
537+ {status_type::http_version_not_supported, " HTTP Version Not Supported" },
538+ {status_type::variant_also_negotiates, " Variant Also Negotiates" },
539+ {status_type::insufficient_storage, " Insufficient Storage" },
540+ {status_type::loop_detected, " Loop Detected" },
541+ {status_type::not_extended, " Not Extended" },
542+ {status_type::network_authentication_required, " Network Authentication Required" },
543+ };
544+
545+ std::string_view status_label (const status_type s)
546+ {
547+ for (auto [k,l] : STATUS_LABELS)
548+ if (k == s)
549+ return l;
547550 return " <unknown-status>" ;
548551 }
549552
0 commit comments