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