001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.mina.http.api;
021
022/**
023 * An <code>Enumeration</code> of all known HTTP status codes.
024 */
025public enum HttpStatus {
026
027    /**
028     * 100 - Continue
029     */
030    INFORMATIONAL_CONTINUE(100, "HTTP/1.1 100 Continue"),
031    /**
032     * 101 - Switching Protocols
033     */
034    INFORMATIONAL_SWITCHING_PROTOCOLS(101, "HTTP/1.1 101 Swtiching Protocols"),
035    /**
036     * 200 - OK
037     */
038    SUCCESS_OK(200, "HTTP/1.1 200 OK"),
039    /**
040     * 201 - Created
041     */
042    SUCCESS_CREATED(201, "HTTP/1.1 201 Created"),
043    /**
044     * 202 - Accepted
045     */
046    SUCCESS_ACCEPTED(202, "HTTP/1.1 202 Accepted"),
047    /**
048     * 203 - Non-Authoritative Information
049     */
050    SUCCESS_NON_AUTHORATIVE_INFORMATION(203, "HTTP/1.1 203 Non-Authoritative Information"),
051    /**
052     * 204 - No Content
053     */
054    SUCCESS_NO_CONTENT(204, "HTTP/1.1 204 No Content"),
055    /**
056     * 205 - Reset Content
057     */
058    SUCCESS_RESET_CONTENT(205, "HTTP/1.1 205 Reset Content"),
059    /**
060     * 206 - Created
061     */
062    SUCCESS_PARTIAL_CONTENT(206, "HTTP/1.1 206 Partial Content"),
063
064    /**
065     * 300 - Multiple Choices
066     */
067    REDIRECTION_MULTIPLE_CHOICES(300, "HTTP/1.1 300 Multiple Choices"),
068    /**
069     * 301 - Moved Permanently
070     */
071    REDIRECTION_MOVED_PERMANENTLY(301, "HTTP/1.1 301 Moved Permanently"),
072    /**
073     * 302 - Found / Moved Temporarily
074     */
075    REDIRECTION_FOUND(302, "HTTP/1.1 302 Found"),
076    /**
077     * 303 - See Others
078     */
079    REDIRECTION_SEE_OTHER(303, "HTTP/1.1 303 See Other"),
080    /**
081     * 304 - Not Modified
082     */
083    REDIRECTION_NOT_MODIFIED(304, "HTTP/1.1 304 Not Modified"),
084    /**
085     * 305 - Use Proxy
086     */
087    REDIRECTION_USE_PROXY(305, "HTTP/1.1 305 Use Proxy"),
088    /**
089     * 307 - Temporary Redirect
090     */
091    REDIRECTION_TEMPORARILY_REDIRECT(307, "HTTP/1.1 307 Temporary Redirect"),
092
093    /**
094     * 400 - Bad Request
095     */
096    CLIENT_ERROR_BAD_REQUEST(400, "HTTP/1.1 400 Bad Request"),
097    /**
098     * 401 - Unauthorized
099     */
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}