1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.mina.http.api;
21
22 /**
23 * An <code>Enumeration</code> of all known HTTP status codes.
24 *
25 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
26 */
27 public enum HttpStatus {
28
29 /**
30 * 200 - OK
31 */
32 SUCCESS_OK(200, "HTTP/1.1 200 OK"),
33 /**
34 * 201 - Created
35 */
36 SUCCESS_CREATED(201, "HTTP/1.1 201 Created"),
37 /**
38 * 202 - Accepted
39 */
40 SUCCESS_ACCEPTED(202, "HTTP/1.1 202 Accepted"),
41 /**
42 * 203 - Non-Authoritative Information
43 */
44 SUCCESS_NON_AUTHORATIVE_INFORMATION(203, "HTTP/1.1 203 Non-Authoritative Information"),
45 /**
46 * 204 - No Content
47 */
48 SUCCESS_NO_CONTENT(204, "HTTP/1.1 204 No Content"),
49 /**
50 * 205 - Reset Content
51 */
52 SUCCESS_RESET_CONTENT(205, "HTTP/1.1 205 Reset Content"),
53 /**
54 * 206 - Created
55 */
56 SUCCESS_PARTIAL_CONTENT(206, "HTTP/1.1 206 Partial Content"),
57
58 /**
59 * 300 - Multiple Choices
60 */
61 REDIRECTION_MULTIPLE_CHOICES(300, "HTTP/1.1 300 Multiple Choices"),
62 /**
63 * 301 - Moved Permanently
64 */
65 REDIRECTION_MOVED_PERMANENTLY(301, "HTTP/1.1 301 Moved Permanently"),
66 /**
67 * 302 - Found / Moved Temporarily
68 */
69 REDIRECTION_FOUND(302, "HTTP/1.1 302 Found"),
70 /**
71 * 303 - See Others
72 */
73 REDIRECTION_SEE_OTHER(303, "HTTP/1.1 303 See Other"),
74 /**
75 * 304 - Not Modified
76 */
77 REDIRECTION_NOT_MODIFIED(304, "HTTP/1.1 304 Not Modified"),
78 /**
79 * 305 - Use Proxy
80 */
81 REDIRECTION_USE_PROXY(305, "HTTP/1.1 305 Use Proxy"),
82 /**
83 * 307 - Temporary Redirect
84 */
85 REDIRECTION_TEMPORARILY_REDIRECT(307, "HTTP/1.1 307 Temporary Redirect"),
86
87 /**
88 * 400 - Bad Request
89 */
90 CLIENT_ERROR_BAD_REQUEST(400, "HTTP/1.1 400 Bad Request"),
91 /**
92 * 401 - Unauthorized
93 */
94 CLIENT_ERROR_UNAUTHORIZED(401, "HTTP/1.1 401 Unauthorized"),
95 /**
96 * 403 - Forbidden
97 */
98 CLIENT_ERROR_FORBIDDEN(403, "HTTP/1.1 403 Forbidden"),
99 /**
100 * 404 - Not Found
101 */
102 CLIENT_ERROR_NOT_FOUND(404, "HTTP/1.1 404 Not Found"),
103 /**
104 * 405 - Method Not Allowed
105 */
106 CLIENT_ERROR_METHOD_NOT_ALLOWED(405, "HTTP/1.1 405 Method Not Allowed"),
107 /**
108 * 406 - Not Acceptable
109 */
110 CLIENT_ERROR_NOT_ACCEPTABLE(406, "HTTP/1.1 406 Not Acceptable"),
111 /**
112 * 407 - Proxy Authentication Required
113 */
114 CLIENT_ERROR_PROXY_AUTHENTICATION_REQUIRED(407, "HTTP/1.1 407 Proxy Authentication Required"),
115 /**
116 * 408 - Request Timeout
117 */
118 CLIENT_ERROR_REQUEST_TIMEOUT(408, "HTTP/1.1 408 Request Timeout"),
119 /**
120 * 409 - Conflict
121 */
122 CLIENT_ERROR_CONFLICT(409, "HTTP/1.1 409 Conflict"),
123 /**
124 * 410 - Gone
125 */
126 CLIENT_ERROR_GONE(410, "HTTP/1.1 410 Gone"),
127 /**
128 * 411 - Length Required
129 */
130 CLIENT_ERROR_LENGTH_REQUIRED(411, "HTTP/1.1 411 Length Required"),
131 /**
132 * 412 - Precondition Failed
133 */
134 CLIENT_ERROR_PRECONDITION_FAILED(412, "HTTP/1.1 412 Precondition Failed"),
135 /**
136 * 413 - Request Entity Too Large
137 */
138 CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE(413, "HTTP/1.1 413 Request Entity Too Large"),
139 /**
140 * 414 - Bad Request
141 */
142 CLIENT_ERROR_REQUEST_URI_TOO_LONG(414, "HTTP/1.1 414 Request-URI Too Long"),
143 /**
144 * 415 - Unsupported Media Type
145 */
146 CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE(415, "HTTP/1.1 415 Unsupported Media Type"),
147 /**
148 * 416 - Requested Range Not Satisfiable
149 */
150 CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE(416, "HTTP/1.1 416 Requested Range Not Satisfiable"),
151 /**
152 * 417 - Expectation Failed
153 */
154 CLIENT_ERROR_EXPECTATION_FAILED(417, "HTTP/1.1 417 Expectation Failed"),
155
156 /**
157 * 500 - Internal Server Error
158 */
159 SERVER_ERROR_INTERNAL_SERVER_ERROR(500, "HTTP/1.1 500 Internal Server Error"),
160 /**
161 * 501 - Not Implemented
162 */
163 SERVER_ERROR_NOT_IMPLEMENTED(501, "HTTP/1.1 501 Not Implemented"),
164 /**
165 * 502 - Bad Gateway
166 */
167 SERVER_ERROR_BAD_GATEWAY(502, "HTTP/1.1 502 Bad Gateway"),
168 /**
169 * 503 - Service Unavailable
170 */
171 SERVER_ERROR_SERVICE_UNAVAILABLE(503, "HTTP/1.1 503 Service Unavailable"),
172 /**
173 * 504 - Gateway Timeout
174 */
175 SERVER_ERROR_GATEWAY_TIMEOUT(504, "HTTP/1.1 504 Gateway Timeout"),
176 /**
177 * 505 - HTTP Version Not Supported
178 */
179 SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED(505, "HTTP/1.1 505 HTTP Version Not Supported");
180
181 /** The code associated with this status, for example "404" for "Not Found". */
182 private int code;
183
184 /**
185 * The line associated with this status, "HTTP/1.1 501 Not Implemented".
186 */
187 private String line;
188
189 /**
190 * Create an instance of this type.
191 *
192 * @param code the status code.
193 * @param phrase the associated phrase.
194 */
195 private HttpStatus(int code, String phrase) {
196 this.code = code;
197 line = phrase;
198 }
199
200 /**
201 * Retrieve the status code for this instance.
202 *
203 * @return the status code.
204 */
205 public int code() {
206 return code;
207 }
208
209 /**
210 * Retrieve the status line for this instance.
211 *
212 * @return the status line.
213 */
214 public String line() {
215 return line + "\r\n";
216 }
217 }