112 lines
3.3 KiB
Hare
112 lines
3.3 KiB
Hare
// A semantic HTTP error and its status code.
|
|
export type httperror = !uint;
|
|
|
|
// Checks if an HTTP status code is semantically considered an error, returning
|
|
// [[httperror]] if so, or otherwise returning the original status code.
|
|
export fn check(status: uint) (uint | httperror) = {
|
|
if (status >= 400 && status < 600) {
|
|
return status: httperror;
|
|
};
|
|
return status;
|
|
};
|
|
|
|
// Converts a standard HTTP status code into the reason text typically
|
|
// associated with this status code (or "Unknown Status" if the status code is
|
|
// not known to net::http).
|
|
export fn status_reason(status: uint) const str = {
|
|
switch (status) {
|
|
case STATUS_CONTINUE =>
|
|
return "Continue";
|
|
case STATUS_SWITCHING_PROTOCOLS =>
|
|
return "Switching Protocols";
|
|
case STATUS_OK =>
|
|
return "Continue";
|
|
case STATUS_CREATED =>
|
|
return "Continue";
|
|
case STATUS_ACCEPTED =>
|
|
return "Accepted";
|
|
case STATUS_NONAUTHORITATIVE_INFO =>
|
|
return "Non-Authoritative Information";
|
|
case STATUS_NO_CONTENT =>
|
|
return "No Content";
|
|
case STATUS_RESET_CONTENT =>
|
|
return "Reset Content";
|
|
case STATUS_PARTIAL_CONTENT =>
|
|
return "Partial Content";
|
|
case STATUS_MULTIPLE_CHOICES =>
|
|
return "Multiple Choices";
|
|
case STATUS_MOVED_PERMANENTLY =>
|
|
return "Moved Permanently";
|
|
case STATUS_FOUND =>
|
|
return "Found";
|
|
case STATUS_SEE_OTHER =>
|
|
return "See Other";
|
|
case STATUS_NOT_MODIFIED =>
|
|
return "Not Modified";
|
|
case STATUS_USE_PROXY =>
|
|
return "Use Proxy";
|
|
case STATUS_TEMPORARY_REDIRECT =>
|
|
return "Temporary Redirect";
|
|
case STATUS_PERMANENT_REDIRECT =>
|
|
return "Permanent Redirect";
|
|
case STATUS_BAD_REQUEST =>
|
|
return "Bad Request";
|
|
case STATUS_UNAUTHORIZED =>
|
|
return "Unauthorized";
|
|
case STATUS_PAYMENT_REQUIRED =>
|
|
return "Payment Required";
|
|
case STATUS_FORBIDDEN =>
|
|
return "Forbidden";
|
|
case STATUS_NOT_FOUND =>
|
|
return "Not Found";
|
|
case STATUS_METHOD_NOT_ALLOWED =>
|
|
return "Method Not Allowed";
|
|
case STATUS_NOT_ACCEPTABLE =>
|
|
return "Not Acceptable";
|
|
case STATUS_PROXY_AUTH_REQUIRED =>
|
|
return "Proxy Authentication Required";
|
|
case STATUS_REQUEST_TIMEOUT =>
|
|
return "Request Timeout";
|
|
case STATUS_CONFLICT =>
|
|
return "Conflict";
|
|
case STATUS_GONE =>
|
|
return "Gone";
|
|
case STATUS_LENGTH_REQUIRED =>
|
|
return "Length Required";
|
|
case STATUS_PRECONDITION_FAILED =>
|
|
return "Precondition Failed";
|
|
case STATUS_REQUEST_ENTITY_TOO_LARGE =>
|
|
return "Request Entity Too Large";
|
|
case STATUS_REQUEST_URI_TOO_LONG =>
|
|
return "Request URI Too Long";
|
|
case STATUS_UNSUPPORTED_MEDIA_TYPE =>
|
|
return "Unsupported Media Type";
|
|
case STATUS_REQUESTED_RANGE_NOT_SATISFIABLE =>
|
|
return "Requested Range Not Satisfiable";
|
|
case STATUS_EXPECTATION_FAILED =>
|
|
return "Expectation Failed";
|
|
case STATUS_TEAPOT =>
|
|
return "I'm A Teapot";
|
|
case STATUS_MISDIRECTED_REQUEST =>
|
|
return "Misdirected Request";
|
|
case STATUS_UNPROCESSABLE_ENTITY =>
|
|
return "Unprocessable Entity";
|
|
case STATUS_UPGRADE_REQUIRED =>
|
|
return "Upgrade Required";
|
|
case STATUS_INTERNAL_SERVER_ERROR =>
|
|
return "Internal Server Error";
|
|
case STATUS_NOT_IMPLEMENTED =>
|
|
return "Not Implemented";
|
|
case STATUS_BAD_GATEWAY =>
|
|
return "Bad Gateway";
|
|
case STATUS_SERVICE_UNAVAILABLE =>
|
|
return "Service Unavailable";
|
|
case STATUS_GATEWAY_TIMEOUT =>
|
|
return "Gateway Timeout";
|
|
case STATUS_HTTP_VERSION_NOT_SUPPORTED =>
|
|
return "HTTP Version Not Supported";
|
|
case =>
|
|
return "Unknown status";
|
|
};
|
|
};
|