1from enum import IntEnum 2 3__all__ = ['HTTPStatus'] 4 5class 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 2295: Transparent Content Negotiation in HTTP 17 * RFC 2774: An HTTP Extension Framework 18 * RFC 7725: An HTTP Status Code to Report Legal Obstacles 19 * RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2) 20 * RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) 21 * RFC 8297: An HTTP Status Code for Indicating Hints 22 * RFC 8470: Using Early Data in HTTP 23 """ 24 def __new__(cls, value, phrase, description=''): 25 obj = int.__new__(cls, value) 26 obj._value_ = value 27 28 obj.phrase = phrase 29 obj.description = description 30 return obj 31 32 # informational 33 CONTINUE = 100, 'Continue', 'Request received, please continue' 34 SWITCHING_PROTOCOLS = (101, 'Switching Protocols', 35 'Switching to new protocol; obey Upgrade header') 36 PROCESSING = 102, 'Processing' 37 EARLY_HINTS = 103, 'Early Hints' 38 39 # success 40 OK = 200, 'OK', 'Request fulfilled, document follows' 41 CREATED = 201, 'Created', 'Document created, URL follows' 42 ACCEPTED = (202, 'Accepted', 43 'Request accepted, processing continues off-line') 44 NON_AUTHORITATIVE_INFORMATION = (203, 45 'Non-Authoritative Information', 'Request fulfilled from cache') 46 NO_CONTENT = 204, 'No Content', 'Request fulfilled, nothing follows' 47 RESET_CONTENT = 205, 'Reset Content', 'Clear input form for further input' 48 PARTIAL_CONTENT = 206, 'Partial Content', 'Partial content follows' 49 MULTI_STATUS = 207, 'Multi-Status' 50 ALREADY_REPORTED = 208, 'Already Reported' 51 IM_USED = 226, 'IM Used' 52 53 # redirection 54 MULTIPLE_CHOICES = (300, 'Multiple Choices', 55 'Object has several resources -- see URI list') 56 MOVED_PERMANENTLY = (301, 'Moved Permanently', 57 'Object moved permanently -- see URI list') 58 FOUND = 302, 'Found', 'Object moved temporarily -- see URI list' 59 SEE_OTHER = 303, 'See Other', 'Object moved -- see Method and URL list' 60 NOT_MODIFIED = (304, 'Not Modified', 61 'Document has not changed since given time') 62 USE_PROXY = (305, 'Use Proxy', 63 'You must use proxy specified in Location to access this resource') 64 TEMPORARY_REDIRECT = (307, 'Temporary Redirect', 65 'Object moved temporarily -- see URI list') 66 PERMANENT_REDIRECT = (308, 'Permanent Redirect', 67 'Object moved permanently -- see URI list') 68 69 # client error 70 BAD_REQUEST = (400, 'Bad Request', 71 'Bad request syntax or unsupported method') 72 UNAUTHORIZED = (401, 'Unauthorized', 73 'No permission -- see authorization schemes') 74 PAYMENT_REQUIRED = (402, 'Payment Required', 75 'No payment -- see charging schemes') 76 FORBIDDEN = (403, 'Forbidden', 77 'Request forbidden -- authorization will not help') 78 NOT_FOUND = (404, 'Not Found', 79 'Nothing matches the given URI') 80 METHOD_NOT_ALLOWED = (405, 'Method Not Allowed', 81 'Specified method is invalid for this resource') 82 NOT_ACCEPTABLE = (406, 'Not Acceptable', 83 'URI not available in preferred format') 84 PROXY_AUTHENTICATION_REQUIRED = (407, 85 'Proxy Authentication Required', 86 'You must authenticate with this proxy before proceeding') 87 REQUEST_TIMEOUT = (408, 'Request Timeout', 88 'Request timed out; try again later') 89 CONFLICT = 409, 'Conflict', 'Request conflict' 90 GONE = (410, 'Gone', 91 'URI no longer exists and has been permanently removed') 92 LENGTH_REQUIRED = (411, 'Length Required', 93 'Client must specify Content-Length') 94 PRECONDITION_FAILED = (412, 'Precondition Failed', 95 'Precondition in headers is false') 96 REQUEST_ENTITY_TOO_LARGE = (413, 'Request Entity Too Large', 97 'Entity is too large') 98 REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long', 99 'URI is too long') 100 UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type', 101 'Entity body in unsupported format') 102 REQUESTED_RANGE_NOT_SATISFIABLE = (416, 103 'Requested Range Not Satisfiable', 104 'Cannot satisfy request range') 105 EXPECTATION_FAILED = (417, 'Expectation Failed', 106 'Expect condition could not be satisfied') 107 IM_A_TEAPOT = (418, 'I\'m a Teapot', 108 'Server refuses to brew coffee because it is a teapot.') 109 MISDIRECTED_REQUEST = (421, 'Misdirected Request', 110 'Server is not able to produce a response') 111 UNPROCESSABLE_ENTITY = 422, 'Unprocessable Entity' 112 LOCKED = 423, 'Locked' 113 FAILED_DEPENDENCY = 424, 'Failed Dependency' 114 TOO_EARLY = 425, 'Too Early' 115 UPGRADE_REQUIRED = 426, 'Upgrade Required' 116 PRECONDITION_REQUIRED = (428, 'Precondition Required', 117 'The origin server requires the request to be conditional') 118 TOO_MANY_REQUESTS = (429, 'Too Many Requests', 119 'The user has sent too many requests in ' 120 'a given amount of time ("rate limiting")') 121 REQUEST_HEADER_FIELDS_TOO_LARGE = (431, 122 'Request Header Fields Too Large', 123 'The server is unwilling to process the request because its header ' 124 'fields are too large') 125 UNAVAILABLE_FOR_LEGAL_REASONS = (451, 126 'Unavailable For Legal Reasons', 127 'The server is denying access to the ' 128 'resource as a consequence of a legal demand') 129 130 # server errors 131 INTERNAL_SERVER_ERROR = (500, 'Internal Server Error', 132 'Server got itself in trouble') 133 NOT_IMPLEMENTED = (501, 'Not Implemented', 134 'Server does not support this operation') 135 BAD_GATEWAY = (502, 'Bad Gateway', 136 'Invalid responses from another server/proxy') 137 SERVICE_UNAVAILABLE = (503, 'Service Unavailable', 138 'The server cannot process the request due to a high load') 139 GATEWAY_TIMEOUT = (504, 'Gateway Timeout', 140 'The gateway server did not receive a timely response') 141 HTTP_VERSION_NOT_SUPPORTED = (505, 'HTTP Version Not Supported', 142 'Cannot fulfill request') 143 VARIANT_ALSO_NEGOTIATES = 506, 'Variant Also Negotiates' 144 INSUFFICIENT_STORAGE = 507, 'Insufficient Storage' 145 LOOP_DETECTED = 508, 'Loop Detected' 146 NOT_EXTENDED = 510, 'Not Extended' 147 NETWORK_AUTHENTICATION_REQUIRED = (511, 148 'Network Authentication Required', 149 'The client needs to authenticate to gain network access') 150