1 /** 2 List of all standard HTTP status codes. 3 4 Copyright: © 2012 RejectedSoftware e.K. 5 License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. 6 Authors: Jan Krüger 7 */ 8 module vibe.http.status; 9 10 /** 11 Definitions of all standard HTTP status codes. 12 */ 13 enum HTTPStatus { 14 continue_ = 100, 15 switchingProtocols = 101, 16 ok = 200, 17 created = 201, 18 accepted = 202, 19 nonAuthoritativeInformation = 203, 20 noContent = 204, 21 resetContent = 205, 22 partialContent = 206, 23 multipleChoices = 300, 24 movedPermanently = 301, 25 found = 302, 26 seeOther = 303, 27 notModified = 304, 28 useProxy = 305, 29 temporaryRedirect = 307, 30 badRequest = 400, 31 unauthorized = 401, 32 paymentRequired = 402, 33 forbidden = 403, 34 notFound = 404, 35 methodNotAllowed = 405, 36 notAcceptable = 406, 37 proxyAuthenticationRequired = 407, 38 requestTimeout = 408, 39 conflict = 409, 40 gone = 410, 41 lengthRequired = 411, 42 preconditionFailed = 412, 43 requestEntityTooLarge = 413, 44 requestURITooLarge = 414, 45 unsupportedMediaType = 415, 46 rangeNotSatisfiable = 416, 47 expectationFailed = 417, 48 tooManyRequests = 429, 49 unavailableForLegalReasons = 451, 50 internalServerError = 500, 51 notImplemented = 501, 52 badGateway = 502, 53 serviceUnavailable = 503, 54 gatewayTimeout = 504, 55 httpVersionNotSupported = 505, 56 // WebDAV status codes 57 multiStatus = 207, 58 unprocessableEntity = 422, 59 locked = 423, 60 failedDependency = 424, 61 insufficientStorage = 507, 62 63 requestedrangenotsatisfiable = rangeNotSatisfiable, /// deprecated 64 Continue = continue_, /// deprecated 65 SwitchingProtocols = switchingProtocols, /// deprecated 66 OK = ok, /// deprecated 67 Created = created, /// deprecated 68 Accepted = accepted, /// deprecated 69 NonAuthoritativeInformation = nonAuthoritativeInformation, /// deprecated 70 NoContent = noContent, /// deprecated 71 ResetContent = resetContent, /// deprecated 72 PartialContent = partialContent, /// deprecated 73 MultipleChoices = multipleChoices, /// deprecated 74 MovedPermanently = movedPermanently, /// deprecated 75 Found = found, /// deprecated 76 SeeOther = seeOther, /// deprecated 77 NotModified = notModified, /// deprecated 78 UseProxy = useProxy, /// deprecated 79 TemporaryRedirect = temporaryRedirect, /// deprecated 80 BadRequest = badRequest, /// deprecated 81 Unauthorized = unauthorized, /// deprecated 82 PaymentRequired = paymentRequired, /// deprecated 83 Forbidden = forbidden, /// deprecated 84 NotFound = notFound, /// deprecated 85 MethodNotAllowed = methodNotAllowed, /// deprecated 86 NotAcceptable = notAcceptable, /// deprecated 87 ProxyAuthenticationRequired = proxyAuthenticationRequired, /// deprecated 88 RequestTimeout = requestTimeout, /// deprecated 89 Conflict = conflict, /// deprecated 90 Gone = gone, /// deprecated 91 LengthRequired = lengthRequired, /// deprecated 92 PreconditionFailed = preconditionFailed, /// deprecated 93 RequestEntityTooLarge = requestEntityTooLarge, /// deprecated 94 RequestURITooLarge = requestURITooLarge, /// deprecated 95 UnsupportedMediaType = unsupportedMediaType, /// deprecated 96 Requestedrangenotsatisfiable = requestedrangenotsatisfiable, /// deprecated 97 ExpectationFailed = expectationFailed, /// deprecated 98 InternalServerError = internalServerError, /// deprecated 99 NotImplemented = notImplemented, /// deprecated 100 BadGateway = badGateway, /// deprecated 101 ServiceUnavailable = serviceUnavailable, /// deprecated 102 GatewayTimeout = gatewayTimeout, /// deprecated 103 HTTPVersionNotSupported = httpVersionNotSupported, /// deprecated 104 } 105 106 107 @safe nothrow @nogc pure: 108 109 /** 110 Returns a standard text description of the specified HTTP status code. 111 */ 112 string httpStatusText(int code) 113 { 114 switch(code) 115 { 116 default: break; 117 case HTTPStatus.continue_ : return "Continue"; 118 case HTTPStatus.switchingProtocols : return "Switching Protocols"; 119 case HTTPStatus.ok : return "OK"; 120 case HTTPStatus.created : return "Created"; 121 case HTTPStatus.accepted : return "Accepted"; 122 case HTTPStatus.nonAuthoritativeInformation : return "Non-Authoritative Information"; 123 case HTTPStatus.noContent : return "No Content"; 124 case HTTPStatus.resetContent : return "Reset Content"; 125 case HTTPStatus.partialContent : return "Partial Content"; 126 case HTTPStatus.multipleChoices : return "Multiple Choices"; 127 case HTTPStatus.movedPermanently : return "Moved Permanently"; 128 case HTTPStatus.found : return "Found"; 129 case HTTPStatus.seeOther : return "See Other"; 130 case HTTPStatus.notModified : return "Not Modified"; 131 case HTTPStatus.useProxy : return "Use Proxy"; 132 case HTTPStatus.temporaryRedirect : return "Temporary Redirect"; 133 case HTTPStatus.badRequest : return "Bad Request"; 134 case HTTPStatus.unauthorized : return "Unauthorized"; 135 case HTTPStatus.paymentRequired : return "Payment Required"; 136 case HTTPStatus.forbidden : return "Forbidden"; 137 case HTTPStatus.notFound : return "Not Found"; 138 case HTTPStatus.methodNotAllowed : return "Method Not Allowed"; 139 case HTTPStatus.notAcceptable : return "Not Acceptable"; 140 case HTTPStatus.proxyAuthenticationRequired : return "Proxy Authentication Required"; 141 case HTTPStatus.requestTimeout : return "Request Time-out"; 142 case HTTPStatus.conflict : return "Conflict"; 143 case HTTPStatus.gone : return "Gone"; 144 case HTTPStatus.lengthRequired : return "Length Required"; 145 case HTTPStatus.preconditionFailed : return "Precondition Failed"; 146 case HTTPStatus.requestEntityTooLarge : return "Request Entity Too Large"; 147 case HTTPStatus.requestURITooLarge : return "Request-URI Too Large"; 148 case HTTPStatus.unsupportedMediaType : return "Unsupported Media Type"; 149 case HTTPStatus.requestedrangenotsatisfiable : return "Requested range not satisfiable"; 150 case HTTPStatus.expectationFailed : return "Expectation Failed"; 151 case HTTPStatus.unavailableForLegalReasons : return "Unavailable For Legal Reasons"; 152 case HTTPStatus.internalServerError : return "Internal Server Error"; 153 case HTTPStatus.notImplemented : return "Not Implemented"; 154 case HTTPStatus.badGateway : return "Bad Gateway"; 155 case HTTPStatus.serviceUnavailable : return "Service Unavailable"; 156 case HTTPStatus.gatewayTimeout : return "Gateway Time-out"; 157 case HTTPStatus.httpVersionNotSupported : return "HTTP Version not supported"; 158 // WebDAV 159 case HTTPStatus.multiStatus : return "Multi-Status"; 160 case HTTPStatus.unprocessableEntity : return "Unprocessable Entity"; 161 case HTTPStatus.locked : return "Locked"; 162 case HTTPStatus.failedDependency : return "Failed Dependency"; 163 case HTTPStatus.insufficientStorage : return "Insufficient Storage"; 164 } 165 if( code >= 600 ) return "Unknown"; 166 if( code >= 500 ) return "Unknown server error"; 167 if( code >= 400 ) return "Unknown error"; 168 if( code >= 300 ) return "Unknown redirection"; 169 if( code >= 200 ) return "Unknown success"; 170 if( code >= 100 ) return "Unknown information"; 171 return "Unknown"; 172 } 173 174 /** 175 Determines if the given status code justifies closing the connection (e.g. evil big request bodies) 176 */ 177 bool justifiesConnectionClose(int status) 178 { 179 switch(status) { 180 default: return false; 181 case HTTPStatus.requestEntityTooLarge: 182 case HTTPStatus.requestURITooLarge: 183 case HTTPStatus.requestTimeout: 184 return true; 185 } 186 } 187 188 /** 189 Determines if status code is generally successful (>= 200 && < 300) 190 */ 191 bool isSuccessCode(HTTPStatus status) 192 { 193 return status >= 200 && status < 300; 194 } 195