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