diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2024-06-09 19:44:50 +0300 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2024-06-09 19:44:50 +0300 |
| commit | e1096cae18c5b0f9eb6a707cef8004eccb9e22dd (patch) | |
| tree | af9d1f23f8acf2217b693919b864775a9f58e323 /src/http_types.rs | |
| parent | 56561283d64d44edb0e8d8623ea18206c712f33d (diff) | |
| download | tiny-server-e1096cae18c5b0f9eb6a707cef8004eccb9e22dd.tar.xz tiny-server-e1096cae18c5b0f9eb6a707cef8004eccb9e22dd.zip | |
feat: Added extra Http StatusCodes
Diffstat (limited to 'src/http_types.rs')
| -rw-r--r-- | src/http_types.rs | 137 |
1 files changed, 133 insertions, 4 deletions
diff --git a/src/http_types.rs b/src/http_types.rs index 44a9039..7a48760 100644 --- a/src/http_types.rs +++ b/src/http_types.rs @@ -2,13 +2,76 @@ use itertools::Itertools; use std::collections::HashMap; pub enum StatusCode { + // 1xx Informational + Continue, // 100 + SwitchingProtocols, // 101 + Processing, // 102 + // 2xx Success - Ok, - Created, + Ok, // 200 + Created, // 201 + Accepted, // 202 + NonAuthoritativeInformation, // 203 + NoContent, // 204 + ResetContent, // 205 + PartialContent, // 206 + MultiStatus, // 207 + AlreadyReported, // 208 + ImUsed, // 226 + + // 3xx Redirection + MultipleChoices, // 300 + MovedPermanently, // 301 + Found, // 302 + SeeOther, // 303 + NotModified, // 304 + UseProxy, // 305 + TemporaryRedirect, // 307 + PermanentRedirect, // 308 // 4xx Client Error - BadRequest, - NotFound, + BadRequest, // 400 + Unauthorized, // 401 + PaymentRequired, // 402 + Forbidden, // 403 + NotFound, // 404 + MethodNotAllowed, // 405 + NotAcceptable, // 406 + ProxyAuthenticationRequired, // 407 + RequestTimeout, // 408 + Conflict, // 409 + Gone, // 410 + LengthRequired, // 411 + PreconditionFailed, // 412 + PayloadTooLarge, // 413 + UriTooLong, // 414 + UnsupportedMediaType, // 415 + RangeNotSatisfiable, // 416 + ExpectationFailed, // 417 + ImaTeapot, // 418 + MisdirectedRequest, // 421 + UnprocessableEntity, // 422 + Locked, // 423 + FailedDependency, // 424 + TooEarly, // 425 + UpgradeRequired, // 426 + PreconditionRequired, // 428 + TooManyRequests, // 429 + RequestHeaderFieldsTooLarge, // 431 + UnavailableForLegalReasons, // 451 + + // 5xx Server Error + InternalServerError, // 500 + NotImplemented, // 501 + BadGateway, // 502 + ServiceUnavailable, // 503 + GatewayTimeout, // 504 + HttpVersionNotSupported, // 505 + VariantAlsoNegotiates, // 506 + InsufficientStorage, // 507 + LoopDetected, // 508 + NotExtended, // 510 + NetworkAuthenticationRequired, // 511 } type Route = String; @@ -63,10 +126,76 @@ impl From<StatusCode> for String { fn from(val: StatusCode) -> Self { use StatusCode::*; match val { + // 1xx Informational + Continue => "100 Continue".to_string(), + SwitchingProtocols => "101 Switching Protocols".to_string(), + Processing => "102 Processing".to_string(), + + // 2xx Success Ok => "200 OK".to_string(), Created => "201 Created".to_string(), + Accepted => "202 Accepted".to_string(), + NonAuthoritativeInformation => "203 Non-Authoritative Information".to_string(), + NoContent => "204 No Content".to_string(), + ResetContent => "205 Reset Content".to_string(), + PartialContent => "206 Partial Content".to_string(), + MultiStatus => "207 Multi-Status".to_string(), + AlreadyReported => "208 Already Reported".to_string(), + ImUsed => "226 IM Used".to_string(), + + // 3xx Redirection + MultipleChoices => "300 Multiple Choices".to_string(), + MovedPermanently => "301 Moved Permanently".to_string(), + Found => "302 Found".to_string(), + SeeOther => "303 See Other".to_string(), + NotModified => "304 Not Modified".to_string(), + UseProxy => "305 Use Proxy".to_string(), + TemporaryRedirect => "307 Temporary Redirect".to_string(), + PermanentRedirect => "308 Permanent Redirect".to_string(), + + // 4xx Client Error BadRequest => "400 Bad Request".to_string(), + Unauthorized => "401 Unauthorized".to_string(), + PaymentRequired => "402 Payment Required".to_string(), + Forbidden => "403 Forbidden".to_string(), NotFound => "404 Not Found".to_string(), + MethodNotAllowed => "405 Method Not Allowed".to_string(), + NotAcceptable => "406 Not Acceptable".to_string(), + ProxyAuthenticationRequired => "407 Proxy Authentication Required".to_string(), + RequestTimeout => "408 Request Timeout".to_string(), + Conflict => "409 Conflict".to_string(), + Gone => "410 Gone".to_string(), + LengthRequired => "411 Length Required".to_string(), + PreconditionFailed => "412 Precondition Failed".to_string(), + PayloadTooLarge => "413 Payload Too Large".to_string(), + UriTooLong => "414 URI Too Long".to_string(), + UnsupportedMediaType => "415 Unsupported Media Type".to_string(), + RangeNotSatisfiable => "416 Range Not Satisfiable".to_string(), + ExpectationFailed => "417 Expectation Failed".to_string(), + ImaTeapot => "418 I'm a teapot".to_string(), + MisdirectedRequest => "421 Misdirected Request".to_string(), + UnprocessableEntity => "422 Unprocessable Entity".to_string(), + Locked => "423 Locked".to_string(), + FailedDependency => "424 Failed Dependency".to_string(), + TooEarly => "425 Too Early".to_string(), + UpgradeRequired => "426 Upgrade Required".to_string(), + PreconditionRequired => "428 Precondition Required".to_string(), + TooManyRequests => "429 Too Many Requests".to_string(), + RequestHeaderFieldsTooLarge => "431 Request Header Fields Too Large".to_string(), + UnavailableForLegalReasons => "451 Unavailable For Legal Reasons".to_string(), + + // 5xx Server Error + InternalServerError => "500 Internal Server Error".to_string(), + NotImplemented => "501 Not Implemented".to_string(), + BadGateway => "502 Bad Gateway".to_string(), + ServiceUnavailable => "503 Service Unavailable".to_string(), + GatewayTimeout => "504 Gateway Timeout".to_string(), + HttpVersionNotSupported => "505 HTTP Version Not Supported".to_string(), + VariantAlsoNegotiates => "506 Variant Also Negotiates".to_string(), + InsufficientStorage => "507 Insufficient Storage".to_string(), + LoopDetected => "508 Loop Detected".to_string(), + NotExtended => "510 Not Extended".to_string(), + NetworkAuthenticationRequired => "511 Network Authentication Required".to_string(), } } } |
