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 requestedrangenotsatisfiable = 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 Continue = continue_, /// deprecated 64 SwitchingProtocols = switchingProtocols, /// deprecated 65 OK = ok, /// deprecated 66 Created = created, /// deprecated 67 Accepted = accepted, /// deprecated 68 NonAuthoritativeInformation = nonAuthoritativeInformation, /// deprecated 69 NoContent = noContent, /// deprecated 70 ResetContent = resetContent, /// deprecated 71 PartialContent = partialContent, /// deprecated 72 MultipleChoices = multipleChoices, /// deprecated 73 MovedPermanently = movedPermanently, /// deprecated 74 Found = found, /// deprecated 75 SeeOther = seeOther, /// deprecated 76 NotModified = notModified, /// deprecated 77 UseProxy = useProxy, /// deprecated 78 TemporaryRedirect = temporaryRedirect, /// deprecated 79 BadRequest = badRequest, /// deprecated 80 Unauthorized = unauthorized, /// deprecated 81 PaymentRequired = paymentRequired, /// deprecated 82 Forbidden = forbidden, /// deprecated 83 NotFound = notFound, /// deprecated 84 MethodNotAllowed = methodNotAllowed, /// deprecated 85 NotAcceptable = notAcceptable, /// deprecated 86 ProxyAuthenticationRequired = proxyAuthenticationRequired, /// deprecated 87 RequestTimeout = requestTimeout, /// deprecated 88 Conflict = conflict, /// deprecated 89 Gone = gone, /// deprecated 90 LengthRequired = lengthRequired, /// deprecated 91 PreconditionFailed = preconditionFailed, /// deprecated 92 RequestEntityTooLarge = requestEntityTooLarge, /// deprecated 93 RequestURITooLarge = requestURITooLarge, /// deprecated 94 UnsupportedMediaType = unsupportedMediaType, /// deprecated 95 Requestedrangenotsatisfiable = requestedrangenotsatisfiable, /// deprecated 96 ExpectationFailed = expectationFailed, /// deprecated 97 InternalServerError = internalServerError, /// deprecated 98 NotImplemented = notImplemented, /// deprecated 99 BadGateway = badGateway, /// deprecated 100 ServiceUnavailable = serviceUnavailable, /// deprecated 101 GatewayTimeout = gatewayTimeout, /// deprecated 102 HTTPVersionNotSupported = httpVersionNotSupported, /// deprecated 103 } 104 105 106 @safe nothrow @nogc pure: 107 108 /** 109 Returns a standard text description of the specified HTTP status code. 110 */ 111 string httpStatusText(int code) 112 { 113 switch(code) 114 { 115 default: break; 116 case HTTPStatus.continue_ : return "Continue"; 117 case HTTPStatus.switchingProtocols : return "Switching Protocols"; 118 case HTTPStatus.ok : return "OK"; 119 case HTTPStatus.created : return "Created"; 120 case HTTPStatus.accepted : return "Accepted"; 121 case HTTPStatus.nonAuthoritativeInformation : return "Non-Authoritative Information"; 122 case HTTPStatus.noContent : return "No Content"; 123 case HTTPStatus.resetContent : return "Reset Content"; 124 case HTTPStatus.partialContent : return "Partial Content"; 125 case HTTPStatus.multipleChoices : return "Multiple Choices"; 126 case HTTPStatus.movedPermanently : return "Moved Permanently"; 127 case HTTPStatus.found : return "Found"; 128 case HTTPStatus.seeOther : return "See Other"; 129 case HTTPStatus.notModified : return "Not Modified"; 130 case HTTPStatus.useProxy : return "Use Proxy"; 131 case HTTPStatus.temporaryRedirect : return "Temporary Redirect"; 132 case HTTPStatus.badRequest : return "Bad Request"; 133 case HTTPStatus.unauthorized : return "Unauthorized"; 134 case HTTPStatus.paymentRequired : return "Payment Required"; 135 case HTTPStatus.forbidden : return "Forbidden"; 136 case HTTPStatus.notFound : return "Not Found"; 137 case HTTPStatus.methodNotAllowed : return "Method Not Allowed"; 138 case HTTPStatus.notAcceptable : return "Not Acceptable"; 139 case HTTPStatus.proxyAuthenticationRequired : return "Proxy Authentication Required"; 140 case HTTPStatus.requestTimeout : return "Request Time-out"; 141 case HTTPStatus.conflict : return "Conflict"; 142 case HTTPStatus.gone : return "Gone"; 143 case HTTPStatus.lengthRequired : return "Length Required"; 144 case HTTPStatus.preconditionFailed : return "Precondition Failed"; 145 case HTTPStatus.requestEntityTooLarge : return "Request Entity Too Large"; 146 case HTTPStatus.requestURITooLarge : return "Request-URI Too Large"; 147 case HTTPStatus.unsupportedMediaType : return "Unsupported Media Type"; 148 case HTTPStatus.requestedrangenotsatisfiable : return "Requested range not satisfiable"; 149 case HTTPStatus.expectationFailed : return "Expectation Failed"; 150 case HTTPStatus.unavailableForLegalReasons : return "Unavailable For Legal Reasons"; 151 case HTTPStatus.internalServerError : return "Internal Server Error"; 152 case HTTPStatus.notImplemented : return "Not Implemented"; 153 case HTTPStatus.badGateway : return "Bad Gateway"; 154 case HTTPStatus.serviceUnavailable : return "Service Unavailable"; 155 case HTTPStatus.gatewayTimeout : return "Gateway Time-out"; 156 case HTTPStatus.httpVersionNotSupported : return "HTTP Version not supported"; 157 // WebDAV 158 case HTTPStatus.multiStatus : return "Multi-Status"; 159 case HTTPStatus.unprocessableEntity : return "Unprocessable Entity"; 160 case HTTPStatus.locked : return "Locked"; 161 case HTTPStatus.failedDependency : return "Failed Dependency"; 162 case HTTPStatus.insufficientStorage : return "Insufficient Storage"; 163 } 164 if( code >= 600 ) return "Unknown"; 165 if( code >= 500 ) return "Unknown server error"; 166 if( code >= 400 ) return "Unknown error"; 167 if( code >= 300 ) return "Unknown redirection"; 168 if( code >= 200 ) return "Unknown success"; 169 if( code >= 100 ) return "Unknown information"; 170 return "Unknown"; 171 } 172 173 /** 174 Determines if the given status code justifies closing the connection (e.g. evil big request bodies) 175 */ 176 bool justifiesConnectionClose(int status) 177 { 178 switch(status) { 179 default: return false; 180 case HTTPStatus.requestEntityTooLarge: 181 case HTTPStatus.requestURITooLarge: 182 case HTTPStatus.requestTimeout: 183 return true; 184 } 185 } 186 187 /** 188 Determines if status code is generally successful (>= 200 && < 300) 189 */ 190 bool isSuccessCode(HTTPStatus status) 191 { 192 return status >= 200 && status < 300; 193 } 194