View Javadoc

1   package com.atlassian.httpclient.api;
2   
3   /**
4    * HTTP Status code, for reference see:
5    * <ul>
6    * <li><a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">the wikipedia page.</a></li>
7    * <li>Hypertext Transfer Protocol -- HTTP/1.1, <a href="https://tools.ietf.org/html/rfc2616">RFC 2616</a></li>
8    * <li>HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV), <a href="https://tools.ietf.org/html/rfc4918">RFC 4918</a></li>
9    * <li>Binding Extensions to Web Distributed Authoring and Versioning (WebDAV), <a href="https://tools.ietf.org/html/rfc5842">RFC 5842</a></li>
10   * <li>Delta encoding in HTTP, <a href="https://tools.ietf.org/html/rfc3229">RFC 3229</a></li>
11   * </ul>
12   */
13  public enum HttpStatus {
14      /**
15       * <p>This means that the server has received the request headers, and that the client should proceed to send the
16       * request body (in the case of a request for which a body needs to be sent; for example, a POST request).
17       * <p>If the request body is large, sending it to a server when a request has already been rejected based upon
18       * inappropriate headers is inefficient. To have a server check if the request could be accepted based on the
19       * request's headers alone, a client must send Expect: 100-continue as a header in its initial request and check if
20       * a 100 Continue status code is received in response before continuing (or receive 417 Expectation Failed and not
21       * continue).
22       */
23      CONTINUE(100),
24  
25      /**
26       * This means the requester has asked the server to switch protocols and the server is acknowledging that it will
27       * do so.
28       */
29      SWITCHING_PROTOCOLS(101),
30  
31      /**
32       * <p>WebDAV: RFC 2518
33       * <p>As a WebDAV request may contain many sub-requests involving file operations, it may take a long time to complete
34       * the request. This code indicates that the server has received and is processing the request, but no response is
35       * available yet. This prevents the client from timing out and assuming the request was lost.
36       */
37      PROCESSING(102),
38  
39      /**
40       * Standard response for successful HTTP requests. The actual response will depend on the request method used. In a
41       * GET request, the response will contain an entity corresponding to the requested resource. In a POST request the
42       * response will contain an entity describing or containing the result of the action.
43       */
44      OK(200),
45  
46      /**
47       * The request has been fulfilled and resulted in a new resource being created.
48       */
49      CREATED(201),
50  
51      /**
52       * The request has been accepted for processing, but the processing has not been completed. The request might or
53       * might not eventually be acted upon, as it might be disallowed when processing actually takes place.
54       */
55      ACCEPTED(202),
56  
57      /**
58       * The server successfully processed the request, but is returning information that may be from another source.
59       */
60      NON_AUTHORITATIVE_INFORMATION(203),
61  
62      /**
63       * The server successfully processed the request, but is not returning any content.
64       */
65      NO_CONTENT(204),
66  
67      /**
68       * The server successfully processed the request, but is not returning any content. Unlike a 204 response, this
69       * response requires that the requester reset the document view.
70       */
71      RESET_CONTENT(205),
72  
73      /**
74       * The server is delivering only part of the resource due to a range header sent by the client. The range header is
75       * used by tools like wget to enable resuming of interrupted downloads, or split a download into multiple
76       * simultaneous streams.
77       */
78      PARTIAL_CONTENT(206),
79  
80      /**
81       * <p>WebDAV; RFC 4918
82       * <p>The message body that follows is an XML message and can contain a number of separate response codes, depending on
83       * how many sub-requests were made.
84       */
85      MULTI_STATUS(207),
86  
87      /**
88       * <p>WebDAV; RFC 5842
89       * <p>The members of a DAV binding have already been enumerated in a previous reply to this request, and are not
90       * being included again.
91       */
92      ALREADY_REPORTED(208),
93  
94      /**
95       * <p>RFC 3229
96       * <p>The server has fulfilled a GET request for the resource, and the response is a representation of the result of
97       * one or more instance-manipulations applied to the current instance.
98       */
99      IM_USED(226),
100 
101     /**
102      * Indicates multiple options for the resource that the client may follow. It, for instance, could be used to
103      * present different format options for video, list files with different extensions, or word sense disambiguation.
104      */
105     MULTIPLE_CHOICES(300),
106 
107     /**
108      * This and all future requests should be directed to the given URI.
109      */
110     MOVED_PERMANENTLY(301),
111 
112     /**
113      * This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945)
114      * required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"),
115      * but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status
116      * codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use
117      * the 302 status code as if it were the 303.
118      */
119     FOUND(302),
120 
121     /**
122      * The response to the request can be found under another URI using a GET method. When received in response to a
123      * POST (or PUT/DELETE), it should be assumed that the server has received the data and the redirect should be
124      * issued with a separate GET message.
125      */
126     SEE_OTHER(303),
127 
128     /**
129      * Indicates the resource has not been modified since last requested. Typically, the HTTP client provides a header
130      * like the If-Modified-Since header to provide a time against which to compare. Using this saves bandwidth and
131      * reprocessing on both the server and client, as only the header data must be sent and received in comparison to
132      * the entirety of the page being re-processed by the server, then sent again using more bandwidth of the server
133      * and client.
134      */
135     NOT_MODIFIED(304),
136 
137     /**
138      *
139      */
140     USE_PROXY(305),
141 
142     /**
143      * No longer used. Originally meant "Subsequent requests should use the specified proxy."
144      */
145     SWITCH_PROXY(306),
146 
147     /**
148      * In this case, the request should be repeated with another URI; however, future requests should still use the
149      * original URI. In contrast to how 302 was historically implemented, the request method is not allowed to be
150      * changed when reissuing the original request. For instance, a POST request repeated using another POST request.
151      */
152     TEMPORARY_REDIRECT(307),
153 
154     /**
155      * The request, and all future requests should be repeated using another URI. 307 and 308 (as proposed) parallel the
156      * behaviours of 302 and 301, but do not allow the HTTP method to change. So, for example, submitting a form to a
157      * permanently redirected resource may continue smoothly.
158      */
159     PERMANENT_REDIRECT(308),
160 
161     /**
162      * The request cannot be fulfilled due to bad syntax.
163      */
164     BAD_REQUEST(400),
165 
166     /**
167      * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet
168      * been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to
169      * the requested resource.
170      */
171     UNAUTHORIZED(401),
172 
173     /**
174      * Reserved for future use. The original intention was that this code might be used as part of some form of digital
175      * cash or micropayment scheme, but that has not happened, and this code is not usually used. As an example of its
176      * use, however, Apple's MobileMe service generates a 402 error if the MobileMe account is delinquent.
177      */
178     PAYMENT_REQUIRED(402),
179 
180     /**
181      * The request was a valid request, but the server is refusing to respond to it. Unlike a 401 Unauthorized response,
182      * authenticating will make no difference. On servers where authentication is required, this commonly means that the
183      * provided credentials were successfully authenticated but that the credentials still do not grant the client
184      * permission to access the resource (e.g. a recognized user attempting to access restricted content).
185      */
186     FORBIDDEN(403),
187 
188     /**
189      * The requested resource could not be found but may be available again in the future. Subsequent requests by the
190      * client are permissible.
191      */
192     NOT_FOUND(404),
193 
194     /**
195      * A request was made of a resource using a request method not supported by that resource; for example, using GET on
196      * a form which requires data to be presented via POST, or using PUT on a read-only resource.
197      */
198     METHOD_NOT_ALLOWED(405),
199 
200     /**
201      * The requested resource is only capable of generating content not acceptable according to the Accept headers sent
202      * in the request.
203      */
204     NOT_ACCEPTABLE(406),
205 
206     /**
207      * The client must first authenticate itself with the proxy.
208      */
209     PROXY_AUTHENTICATION_REQUIRED(407),
210 
211     /**
212      * The server timed out waiting for the request. According to W3 HTTP specifications: "The client did not produce a
213      * request within the time that the server was prepared to wait. The client MAY repeat the request without
214      * modifications at any later time."
215      */
216     REQUEST_TIMEOUT(408),
217 
218     /**
219      * Indicates that the request could not be processed because of conflict in the request, such as an edit conflict.
220      */
221     CONFLICT(409),
222 
223     /**
224      * Indicates that the resource requested is no longer available and will not be available again. This should be used
225      * when a resource has been intentionally removed and the resource should be purged. Upon receiving a 410 status code,
226      * the client should not request the resource again in the future. Clients such as search engines should remove the
227      * resource from their indices. Most use cases do not require clients and search engines to purge the resource, and
228      * a "404 Not Found" may be used instead.
229      */
230     GONE(410),
231 
232     /**
233      * The request did not specify the length of its content, which is required by the requested resource.
234      */
235     LENGTH_REQUIRED(411),
236 
237     /**
238      * The server does not meet one of the preconditions that the requester put on the request.
239      */
240     PRECONDITION_FAILED(412),
241 
242     /**
243      * The request is larger than the server is willing or able to process.
244      */
245     REQUEST_ENTITY_TOO_LARGE(413),
246 
247     /**
248      * The URI provided was too long for the server to process.
249      */
250     REQUEST_URI_TOO_LONG(414),
251 
252     /**
253      * The request entity has a media type which the server or resource does not support. For example, the client uploads
254      * an image as image/svg+xml, but the server requires that images use a different format.
255      */
256     UNSUPPORTED_MEDIA_TYPE(415),
257 
258     /**
259      * The client has asked for a portion of the file, but the server cannot supply that portion. For example, if the
260      * client asked for a part of the file that lies beyond the end of the file.
261      */
262     REQUEST_RANGE_NOT_SATISFIABLE(416),
263 
264     /**
265      * The server cannot meet the requirements of the Expect request-header field.
266      */
267     EXPECTATION_FAILED(417),
268 
269     /**
270      * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee
271      * Pot Control Protocol, and is not expected to be implemented by actual HTTP servers.
272      */
273     I_M_A_TEAPOT(418),
274 
275     /**
276      * Not part of the HTTP standard, but returned by the Twitter Search and Trends API when the client is being rate
277      * limited. Other services may wish to implement the 429 Too Many Requests response code instead.
278      */
279     ENHANCE_YOUR_CALM(420),
280 
281     /**
282      * The request was well-formed but was unable to be followed due to semantic errors.
283      */
284     UNPROCESSABLE_ENTITY(422),
285 
286     /**
287      * The resource that is being accessed is locked.
288      */
289     LOCKED(423),
290 
291     /**
292      * Indicates the method was not executed on a particular resource within its scope because some part of the method's
293      * execution failed causing the entire method to be aborted.
294      */
295     METHOD_FAILURE(424),
296 
297     /**
298      * Defined in drafts of "WebDAV Advanced Collections Protocol",[15] but not present in "Web Distributed Authoring
299      * and Versioning (WebDAV) Ordered Collections Protocol".[16]
300      */
301     UNORDERED_COLLECTION(425),
302 
303     /**
304      * The client should switch to a different protocol such as TLS/1.0.
305      */
306     UPGRADE_REQUIRED(426),
307 
308     /**
309      * The origin server requires the request to be conditional. Intended to prevent "the 'lost update' problem, where
310      * a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has
311      * modified the state on the server, leading to a conflict."
312      */
313     PRECONDITION_REQUIRED(428),
314 
315     /**
316      * The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes.
317      */
318     TOO_MANY_REQUESTS(429),
319 
320     /**
321      * The server is unwilling to process the request because either an individual header field, or all the header
322      * fields collectively, are too large.[18]
323      */
324     REQUEST_HEADER_FIELDS_TOO_LARGE(431),
325 
326     /**
327      * Used in Nginx logs to indicate that the server has returned no information to the client and closed the connection (useful as a deterrent for malware).
328      */
329     NO_RESPONSE(444),
330 
331     /**
332      * A Microsoft extension. The request should be retried after performing the appropriate action.
333      */
334     RETRY_WITH(449),
335 
336     /**
337      * A Microsoft extension. This error is given when Windows Parental Controls are turned on and are blocking access to the given webpage.
338      */
339     BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS(450),
340 
341     /**
342      * Defined in the internet draft "A New HTTP Status Code for Legally-restricted Resources". Intended to be used when
343      * resource access is denied for legal reasons, e.g. censorship or government-mandated blocked access. A reference
344      * to the 1953 dystopian novel Fahrenheit 451, where books are outlawed.
345      */
346     UNAVAILABLE_FOR_LEGAL_REASONS(451),
347     //    REDIRECT(451),
348 
349     /**
350      * Nginx internal code similar to 431 but it was introduced earlier.
351      */
352     REQUEST_HEADER_TOO_LARGE(494),
353 
354     /**
355      * Nginx internal code used when SSL client certificate error occured to distinguish it from 4XX in a log and an
356      * error page redirection.
357      */
358     CERT_ERROR(495),
359 
360     /**
361      * Nginx internal code used when client didn't provide certificate to distinguish it from 4XX in a log and an error
362      * page redirection.
363      */
364     NO_CERT(496),
365 
366     /**
367      * Nginx internal code used for the plain HTTP requests that are sent to HTTPS port to distinguish it from 4XX in a
368      * log and an error page redirection.
369      */
370     HTTP_TO_HTTPS(497),
371 
372     /**
373      * Used in Nginx logs to indicate when the connection has been closed by client while the server is still processing
374      * its request, making server unable to send a status code back.
375      */
376     CLIENT_CLOSED_REQUEST(499),
377 
378     /**
379      * A generic error message, given when no more specific message is suitable
380      */
381     INTERNAL_SERVER_ERROR(500),
382 
383     /**
384      * The server either does not recognize the request method, or it lacks the ability to fulfill the request.
385      */
386     NOT_IMPLEMENTED(501),
387 
388     /**
389      * The server was acting as a gateway or proxy and received an invalid response from the upstream server.
390      */
391     BAD_GATEWAY(502),
392 
393     /**
394      * The server is currently unavailable (because it is overloaded or down for maintenance).Generally, this is a
395      * temporary state.
396      */
397     SERVICE_UNAVAILABLE(503),
398 
399     /**
400      * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
401      */
402     GATEWAY_TIMEOUT(504),
403 
404     /**
405      * The server does not support the HTTP protocol version used in the request.
406      */
407     HTTP_VERSION_NOT_SUPPORTED(505),
408 
409     /**
410      * <p>RFC 2295
411      * <p>Transparent content negotiation for the request results in a circular reference.
412      */
413     VARIANT_ALSO_NEGOTIATES(506),
414 
415     /**
416      * <p>WebDAV; RFC 4918
417      * <p>The server is unable to store the representation needed to complete the request.[4]
418      */
419     INSUFFICIENT_STORAGE(507),
420 
421     /**
422      * <p>WebDAV; RFC 5842
423      * <p>The server detected an infinite loop while processing the request (sent in lieu of 208).
424      */
425     LOOP_DETECTED(508),
426 
427     /**
428      * This status code, while used by many servers, is not specified in any RFCs.
429      */
430     BANDWIDTH_LIMIT_EXCEEDED(509),
431 
432     /**
433      * <p>RFC 2774
434      * <p>Further extensions to the request are required for the server to fulfill it.
435      */
436     NOT_EXTENDED(510),
437 
438     /**
439      * <p>RFC 6585
440      * <p>The client needs to authenticate to gain network access. Intended for use by intercepting proxies used to control
441      * access to the network (e.g. "captive portals" used to require agreement to Terms of Service before granting full
442      * Internet access via a Wi-Fi hotspot).
443      */
444     NETWORK_AUTHENTICATION_REQUIRED(511),
445 
446     /**
447      * This status code is not specified in any RFCs, but is used by Microsoft Corp. HTTP proxies to signal a network
448      * read timeout behind the proxy to a client in front of the proxy.
449      */
450     NETWORK_READ_TIMEOUT_ERROR(598),
451 
452     /**
453      * This status code is not specified in any RFCs, but is used by Microsoft Corp. HTTP proxies to signal a network
454      * connect timeout behind the proxy to a client in front of the proxy.
455      */
456     NETWORK_CONNECT_TIMEOUT_ERROR(599);
457 
458     public final int code;
459 
460     private HttpStatus(int code) {
461         this.code = code;
462     }
463 
464     static HttpStatus fromCode(int code) {
465         for (HttpStatus status : values()) {
466             if (status.code == code) {
467                 return status;
468             }
469         }
470         throw new IllegalArgumentException("No HTTP status for code " + code);
471     }
472 
473     @Override
474     public String toString() {
475         return name() + "(" + code + ")";
476     }
477 }