]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/http/HttpStatus.java
1 package org
.argeo
.cms
.http
;
4 * Standard HTTP response status codes (including WebDav ones).
6 * @see "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status"
8 public enum HttpStatus
{
9 // Successful responses (200–299)
11 NO_CONTENT(204, "No Content"), //
12 MULTI_STATUS(207, "Multi-Status"), // WebDav
13 // Client error responses (400–499)
14 UNAUTHORIZED(401, "Unauthorized"), //
15 FORBIDDEN(403, "Forbidden"), //
16 NOT_FOUND(404, "Not Found"), //
17 // Server error responses (500-599)
18 INTERNAL_SERVER_ERROR(500, "Internal Server Error"), //
19 NOT_IMPLEMENTED(501, "Not Implemented"), //
22 private final int code
;
23 private final String reasonPhrase
;
25 HttpStatus(int statusCode
, String reasonPhrase
) {
26 this.code
= statusCode
;
27 this.reasonPhrase
= reasonPhrase
;
30 public int getCode() {
34 public String
getReasonPhrase() {
39 * The status line, as defined by RFC2616.
41 * @see "https://www.rfc-editor.org/rfc/rfc2616#section-6.1"
43 public String
getStatusLine(String httpVersion
) {
44 return httpVersion
+ " " + code
+ " " + reasonPhrase
;
47 public static HttpStatus
parseStatusLine(String statusLine
) {
49 String
[] arr
= statusLine
.split(" ");
50 int code
= Integer
.parseInt(arr
[1]);
51 for (HttpStatus status
: values()) {
52 if (status
.getCode() == code
)
55 } catch (Exception e
) {
56 throw new IllegalArgumentException("Invalid status line: " + statusLine
, e
);
58 throw new IllegalArgumentException("Unkown status code: " + statusLine
);
62 public String
toString() {
63 return code
+ " " + reasonPhrase
;