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 public enum HttpStatus {
26
27 /**
28 * 100 - Continue
29 */
30 INFORMATIONAL_CONTINUE(100, "HTTP/1.1 100 Continue"),
31 /**
32 * 101 - Switching Protocols
33 */
34 INFORMATIONAL_SWITCHING_PROTOCOLS(101, "HTTP/1.1 101 Swtiching Protocols"),
35 /**
36 * 200 - OK
37 */
38 SUCCESS_OK(200, "HTTP/1.1 200 OK"),
39 /**
40 * 201 - Created
41 */
42 SUCCESS_CREATED(201, "HTTP/1.1 201 Created"),
43 /**
44 * 202 - Accepted
45 */
46 SUCCESS_ACCEPTED(202, "HTTP/1.1 202 Accepted"),
47 /**
48 * 203 - Non-Authoritative Information
49 */
50 SUCCESS_NON_AUTHORATIVE_INFORMATION(203, "HTTP/1.1 203 Non-Authoritative Information"),
51 /**
52 * 204 - No Content
53 */
54 SUCCESS_NO_CONTENT(204, "HTTP/1.1 204 No Content"),
55 /**
56 * 205 - Reset Content
57 */
58 SUCCESS_RESET_CONTENT(205, "HTTP/1.1 205 Reset Content"),
59 /**
60 * 206 - Created
61 */
62 SUCCESS_PARTIAL_CONTENT(206, "HTTP/1.1 206 Partial Content"),
63
64 /**
65 * 300 - Multiple Choices
66 */
67 REDIRECTION_MULTIPLE_CHOICES(300, "HTTP/1.1 300 Multiple Choices"),
68 /**
69 * 301 - Moved Permanently
70 */
71 REDIRECTION_MOVED_PERMANENTLY(301, "HTTP/1.1 301 Moved Permanently"),
72 /**
73 * 302 - Found / Moved Temporarily
74 */
75 REDIRECTION_FOUND(302, "HTTP/1.1 302 Found"),
76 /**
77 * 303 - See Others
78 */
79 REDIRECTION_SEE_OTHER(303, "HTTP/1.1 303 See Other"),
80 /**
81 * 304 - Not Modified
82 */
83 REDIRECTION_NOT_MODIFIED(304, "HTTP/1.1 304 Not Modified"),
84 /**
85 * 305 - Use Proxy
86 */
87 REDIRECTION_USE_PROXY(305, "HTTP/1.1 305 Use Proxy"),
88 /**
89 * 307 - Temporary Redirect
90 */
91 REDIRECTION_TEMPORARILY_REDIRECT(307, "HTTP/1.1 307 Temporary Redirect"),
92
93 /**
94 * 400 - Bad Request
95 */
96 CLIENT_ERROR_BAD_REQUEST(400, "HTTP/1.1 400 Bad Request"),
97 /**
98 * 401 - Unauthorized
99 */
100 CLIENT_ERROR_UNAUTHORIZED(401, "HTTP/1.1 401 Unauthorized"),
101 /**
102 * 403 - Forbidden
103 */
104 CLIENT_ERROR_FORBIDDEN(403, "HTTP/1.1 403 Forbidden"),
105 /**
106 * 404 - Not Found
107 */
108 CLIENT_ERROR_NOT_FOUND(404, "HTTP/1.1 404 Not Found"),
109 /**
110 * 405 - Method Not Allowed
111 */
112 CLIENT_ERROR_METHOD_NOT_ALLOWED(405, "HTTP/1.1 405 Method Not Allowed"),
113 /**
114 * 406 - Not Acceptable
115 */
116 CLIENT_ERROR_NOT_ACCEPTABLE(406, "HTTP/1.1 406 Not Acceptable"),
117 /**
118 * 407 - Proxy Authentication Required
119 */
120 CLIENT_ERROR_PROXY_AUTHENTICATION_REQUIRED(407, "HTTP/1.1 407 Proxy Authentication Required"),
121 /**
122 * 408 - Request Timeout
123 */
124 CLIENT_ERROR_REQUEST_TIMEOUT(408, "HTTP/1.1 408 Request Timeout"),
125 /**
126 * 409 - Conflict
127 */
128 CLIENT_ERROR_CONFLICT(409, "HTTP/1.1 409 Conflict"),
129 /**
130 * 410 - Gone
131 */
132 CLIENT_ERROR_GONE(410, "HTTP/1.1 410 Gone"),
133 /**
134 * 411 - Length Required
135 */
136 CLIENT_ERROR_LENGTH_REQUIRED(411, "HTTP/1.1 411 Length Required"),
137 /**
138 * 412 - Precondition Failed
139 */
140 CLIENT_ERROR_PRECONDITION_FAILED(412, "HTTP/1.1 412 Precondition Failed"),
141 /**
142 * 413 - Request Entity Too Large
143 */
144 CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE(413, "HTTP/1.1 413 Request Entity Too Large"),
145 /**
146 * 414 - Bad Request
147 */
148 CLIENT_ERROR_REQUEST_URI_TOO_LONG(414, "HTTP/1.1 414 Request-URI Too Long"),
149 /**
150 * 415 - Unsupported Media Type
151 */
152 CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE(415, "HTTP/1.1 415 Unsupported Media Type"),
153 /**
154 * 416 - Requested Range Not Satisfiable
155 */
156 CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE(416, "HTTP/1.1 416 Requested Range Not Satisfiable"),
157 /**
158 * 417 - Expectation Failed
159 */
160 CLIENT_ERROR_EXPECTATION_FAILED(417, "HTTP/1.1 417 Expectation Failed"),
161
162 /**
163 * 500 - Internal Server Error
164 */
165 SERVER_ERROR_INTERNAL_SERVER_ERROR(500, "HTTP/1.1 500 Internal Server Error"),
166 /**
167 * 501 - Not Implemented
168 */
169 SERVER_ERROR_NOT_IMPLEMENTED(501, "HTTP/1.1 501 Not Implemented"),
170 /**
171 * 502 - Bad Gateway
172 */
173 SERVER_ERROR_BAD_GATEWAY(502, "HTTP/1.1 502 Bad Gateway"),
174 /**
175 * 503 - Service Unavailable
176 */
177 SERVER_ERROR_SERVICE_UNAVAILABLE(503, "HTTP/1.1 503 Service Unavailable"),
178 /**
179 * 504 - Gateway Timeout
180 */
181 SERVER_ERROR_GATEWAY_TIMEOUT(504, "HTTP/1.1 504 Gateway Timeout"),
182 /**
183 * 505 - HTTP Version Not Supported
184 */
185 SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED(505, "HTTP/1.1 505 HTTP Version Not Supported");
186
187 /** The code associated with this status, for example "404" for "Not Found". */
188 private int code;
189
190 /**
191 * The line associated with this status, "HTTP/1.1 501 Not Implemented".
192 */
193 private String line;
194
195 /**
196 * Create an instance of this type.
197 *
198 * @param code the status code.
199 * @param phrase the associated phrase.
200 */
201 private HttpStatus(int code, String phrase) {
202 this.code = code;
203 line = phrase;
204 }
205
206 /**
207 * Retrieve the status code for this instance.
208 *
209 * @return the status code.
210 */
211 public int code() {
212 return code;
213 }
214
215 /**
216 * Retrieve the status line for this instance.
217 *
218 * @return the status line.
219 */
220 public String line() {
221 return line + "\r\n";
222 }
223 }