|
1 |
| -# This directory is a Python package. |
| 1 | +from enum import IntEnum |
| 2 | + |
| 3 | +__all__ = ['HTTPStatus'] |
| 4 | + |
| 5 | +class HTTPStatus(IntEnum): |
| 6 | + """HTTP status codes and reason phrases |
| 7 | +
|
| 8 | + Status codes from the following RFCs are all observed: |
| 9 | +
|
| 10 | + * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616 |
| 11 | + * RFC 6585: Additional HTTP Status Codes |
| 12 | + * RFC 3229: Delta encoding in HTTP |
| 13 | + * RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518 |
| 14 | + * RFC 5842: Binding Extensions to WebDAV |
| 15 | + * RFC 7238: Permanent Redirect |
| 16 | + * RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) |
| 17 | + * RFC 2295: Transparent Content Negotiation in HTTP |
| 18 | + * RFC 2774: An HTTP Extension Framework |
| 19 | +
|
| 20 | + Non-standard vendor codes include: |
| 21 | +
|
| 22 | + * Spring framework: 420 |
| 23 | + * Nginx: 444, 494, 495, 496, 497, 499 |
| 24 | + * Microsoft: 440, 449, 450 |
| 25 | + * Cloudflare: 520, 521, 522, 523, 524, 598, 599 |
| 26 | + """ |
| 27 | + def __new__(cls, value, phrase, description=''): |
| 28 | + obj = int.__new__(cls, value) |
| 29 | + obj._value_ = value |
| 30 | + |
| 31 | + obj.phrase = phrase |
| 32 | + obj.description = description |
| 33 | + return obj |
| 34 | + |
| 35 | + # informational |
| 36 | + CONTINUE = 100, 'Continue', 'Request received, please continue' |
| 37 | + SWITCHING_PROTOCOLS = (101, 'Switching Protocols', |
| 38 | + 'Switching to new protocol; obey Upgrade header') |
| 39 | + PROCESSING = 102, 'Processing' |
| 40 | + |
| 41 | + # success |
| 42 | + OK = 200, 'OK', 'Request fulfilled, document follows' |
| 43 | + CREATED = 201, 'Created', 'Document created, URL follows' |
| 44 | + ACCEPTED = (202, 'Accepted', |
| 45 | + 'Request accepted, processing continues off-line') |
| 46 | + NON_AUTHORITATIVE_INFORMATION = (203, |
| 47 | + 'Non-Authoritative Information', 'Request fulfilled from cache') |
| 48 | + NO_CONTENT = 204, 'No Content', 'Request fulfilled, nothing follows' |
| 49 | + RESET_CONTENT = 205, 'Reset Content', 'Clear input form for further input' |
| 50 | + PARTIAL_CONTENT = 206, 'Partial Content', 'Partial content follows' |
| 51 | + MULTI_STATUS = 207, 'Multi-Status' |
| 52 | + ALREADY_REPORTED = 208, 'Already Reported' |
| 53 | + IM_USED = 226, 'IM Used' |
| 54 | + |
| 55 | + # redirection |
| 56 | + MULTIPLE_CHOICES = (300, 'Multiple Choices', |
| 57 | + 'Object has several resources -- see URI list') |
| 58 | + MOVED_PERMANENTLY = (301, 'Moved Permanently', |
| 59 | + 'Object moved permanently -- see URI list') |
| 60 | + FOUND = 302, 'Found', 'Object moved temporarily -- see URI list' |
| 61 | + SEE_OTHER = 303, 'See Other', 'Object moved -- see Method and URL list' |
| 62 | + NOT_MODIFIED = (304, 'Not Modified', |
| 63 | + 'Document has not changed since given time') |
| 64 | + USE_PROXY = (305, 'Use Proxy', |
| 65 | + 'You must use proxy specified in Location to access this resource') |
| 66 | + SWITCH_PROXY = 306, 'Switch Proxy' |
| 67 | + TEMPORARY_REDIRECT = (307, 'Temporary Redirect', |
| 68 | + 'Object moved temporarily -- see URI list') |
| 69 | + PERMANENT_REDIRECT = (308, 'Permanent Redirect', |
| 70 | + 'Object moved temporarily -- see URI list') |
| 71 | + |
| 72 | + # client error |
| 73 | + BAD_REQUEST = (400, 'Bad Request', |
| 74 | + 'Bad request syntax or unsupported method') |
| 75 | + UNAUTHORIZED = (401, 'Unauthorized', |
| 76 | + 'No permission -- see authorization schemes') |
| 77 | + PAYMENT_REQUIRED = (402, 'Payment Required', |
| 78 | + 'No payment -- see charging schemes') |
| 79 | + FORBIDDEN = (403, 'Forbidden', |
| 80 | + 'Request forbidden -- authorization will not help') |
| 81 | + NOT_FOUND = (404, 'Not Found', |
| 82 | + 'Nothing matches the given URI') |
| 83 | + METHOD_NOT_ALLOWED = (405, 'Method Not Allowed', |
| 84 | + 'Specified method is invalid for this resource') |
| 85 | + NOT_ACCEPTABLE = (406, 'Not Acceptable', |
| 86 | + 'URI not available in preferred format') |
| 87 | + PROXY_AUTHENTICATION_REQUIRED = (407, |
| 88 | + 'Proxy Authentication Required', |
| 89 | + 'You must authenticate with this proxy before proceeding') |
| 90 | + REQUEST_TIMEOUT = (408, 'Request Timeout', |
| 91 | + 'Request timed out; try again later') |
| 92 | + CONFLICT = 409, 'Conflict', 'Request conflict' |
| 93 | + GONE = (410, 'Gone', |
| 94 | + 'URI no longer exists and has been permanently removed') |
| 95 | + LENGTH_REQUIRED = (411, 'Length Required', |
| 96 | + 'Client must specify Content-Length') |
| 97 | + PRECONDITION_FAILED = (412, 'Precondition Failed', |
| 98 | + 'Precondition in headers is false') |
| 99 | + REQUEST_ENTITY_TOO_LARGE = (413, 'Request Entity Too Large', |
| 100 | + 'Entity is too large') |
| 101 | + REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long', |
| 102 | + 'URI is too long') |
| 103 | + UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type', |
| 104 | + 'Entity body in unsupported format') |
| 105 | + REQUEST_RANGE_NOT_SATISFIABLE = (416, |
| 106 | + 'Request Range Not Satisfiable', |
| 107 | + 'Cannot satisfy request range') |
| 108 | + EXPECTATION_FAILED = (417, 'Expectation Failed', |
| 109 | + 'Expect condition could not be satisfied') |
| 110 | + IM_A_TEAPOT = 418, 'I\'m a teapot' |
| 111 | + AUTHENTICATION_TIMEOUT = 419, 'Authentication Timeout' |
| 112 | + METHOD_FAILURE = 420, 'Method Failure' # Spring framework |
| 113 | + UNPROCESSABLE_ENTITY = 422, 'Unprocessable Entity' |
| 114 | + LOCKED = 423, 'Locked' |
| 115 | + FAILED_DEPENDENCY = 424, 'Failed Dependency' |
| 116 | + UPGRADE_REQUIRED = 426, 'Upgrade Required' |
| 117 | + PRECONDITION_REQUIRED = (428, 'Precondition Required', |
| 118 | + 'The origin server requires the request to be conditional') |
| 119 | + TOO_MANY_REQUESTS = (429, 'Too Many Requests', |
| 120 | + 'The user has sent too many requests in ' |
| 121 | + 'a given amount of time ("rate limiting")') |
| 122 | + REQUEST_HEADER_FIELD_TOO_LARGE = (431, |
| 123 | + 'Request Header Field Too Large', |
| 124 | + 'The server is unwilling to process the request because its header ' |
| 125 | + 'fields are too large') |
| 126 | + LOGIN_TIMEOUT = 440, 'Login Timeout' # microsoft |
| 127 | + NO_RESPONSE = 444, 'No Response' # nginx |
| 128 | + RETRY_WITH = 449, 'Retry With' # microsoft |
| 129 | + BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = (450, |
| 130 | + 'Blocked By Windows Parental Controls') # microsoft |
| 131 | + REQUEST_HEADER_TOO_LARGE = 494, 'Request Header Too Large' # nginx |
| 132 | + CERT_ERROR = 495, 'Cert Error' # nginx |
| 133 | + NO_CERT = 496, 'No Cert' # nginx |
| 134 | + HTTP_TO_HTTPS = 497, 'HTTP To HTTPS' # nginx |
| 135 | + CLIENT_CLOSED_REQUEST = 499, 'Client Closed Request' # nginx |
| 136 | + |
| 137 | + # server errors |
| 138 | + INTERNAL_SERVER_ERROR = (500, 'Internal Server Error', |
| 139 | + 'Server got itself in trouble') |
| 140 | + NOT_IMPLEMENTED = (501, 'Not Implemented', |
| 141 | + 'Server does not support this operation') |
| 142 | + BAD_GATEWAY = (502, 'Bad Gateway', |
| 143 | + 'Invalid responses from another server/proxy') |
| 144 | + SERVICE_UNAVAILABLE = (503, 'Service Unavailable', |
| 145 | + 'The server cannot process the request due to a high load') |
| 146 | + GATEWAY_TIMEOUT = (504, 'Gateway Timeout', |
| 147 | + 'The gateway server did not receive a timely response') |
| 148 | + HTTP_VERSION_NOT_SUPPORTED = (505, 'HTTP Version Not Supported', |
| 149 | + 'Cannot fulfill request') |
| 150 | + VARIANT_ALSO_NEGOTIATES = 506, 'Variant Also Negotiates' |
| 151 | + INSUFFICIENT_STORAGE = 507, 'Insufficient Storage' |
| 152 | + LOOP_DETECTED = 508, 'Loop Detected' |
| 153 | + BANDWIDTH_LIMIT_EXCEEDED = 509, 'Bandwidth Limit Exceeded' |
| 154 | + NOT_EXTENDED = 510, 'Not Extended' |
| 155 | + NETWORK_AUTHENTICATION_REQUIRED = (511, |
| 156 | + 'Network Authentication Required', |
| 157 | + 'The client needs to authenticate to gain network access') |
| 158 | + ORIGIN_ERROR = 520, 'Origin Error' # cloudflare |
| 159 | + WEB_SERVER_IS_DOWN = 521, 'Web Server Is Down' # cloudflare |
| 160 | + CONNECTON_TIMED_OUT = 522, 'Connection Timed Out' # cloudflare |
| 161 | + PROXY_DECLINED_REQUEST = 523, 'Proxy Declined Request' # cloudflare |
| 162 | + A_TIMEOUT_OCCURRED = 524, 'A Timeout Occurred', '' # cloudflare |
| 163 | + NETWORK_READ_TIMEOUT_ERROR = 598, 'Network Read Timeout Error' |
| 164 | + NETWORK_CONNECT_TIMEOUT_ERROR = 599, 'Network Connect Timeout Error' |
0 commit comments