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