1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.mortbay.jetty;
16
17 import org.mortbay.io.Buffer;
18 import org.mortbay.io.BufferCache;
19 import org.mortbay.io.ByteArrayBuffer;
20
21
22
23
24
25 public class HttpStatus
26 {
27 public final static String Continue= "Continue",
28 Switching_Protocols= "Switching Protocols",
29 Processing= "Processing",
30 OK= "OK",
31 Created= "Created",
32 Accepted= "Accepted",
33 Non_Authoritative_Information= "Non Authoritative Information",
34 No_Content= "No Content",
35 Reset_Content= "Reset Content",
36 Partial_Content= "Partial Content",
37 Multi_Status= "Multi Status",
38 Multiple_Choices= "Multiple Choices",
39 Moved_Permanently= "Moved Permanently",
40 Moved_Temporarily= "Moved Temporarily",
41 Found= "Found",
42 See_Other= "See Other",
43 Not_Modified= "Not Modified",
44 Use_Proxy= "Use Proxy",
45 Bad_Request= "Bad Request",
46 Unauthorized= "Unauthorized",
47 Payment_Required= "Payment Required",
48 Forbidden= "Forbidden",
49 Not_Found= "Not Found",
50 Method_Not_Allowed= "Method Not Allowed",
51 Not_Acceptable= "Not Acceptable",
52 Proxy_Authentication_Required= "Proxy Authentication Required",
53 Request_Timeout= "Request Timeout",
54 Conflict= "Conflict",
55 Gone= "Gone",
56 Length_Required= "Length Required",
57 Precondition_Failed= "Precondition Failed",
58 Request_Entity_Too_Large= "Request Entity Too Large",
59 Request_URI_Too_Large= "Request URI Too Large",
60 Unsupported_Media_Type= "Unsupported Media Type",
61 Requested_Range_Not_Satisfiable= "Requested Range Not Satisfiable",
62 Expectation_Failed= "Expectation Failed",
63 Unprocessable_Entity= "Unprocessable Entity",
64 Locked= "Locked",
65 Failed_Dependency= "Failed Dependency",
66 Internal_Server_Error= "Internal Server Error",
67 Not_Implemented= "Not Implemented",
68 Bad_Gateway= "Bad Gateway",
69 Service_Unavailable= "Service Unavailable",
70 Gateway_Timeout= "Gateway Timeout",
71 HTTP_Version_Not_Supported= "HTTP Version Not Supported",
72 Insufficient_Storage= "Insufficient Storage",
73 Unknown="Unknown";
74
75 public final static int
76 ORDINAL_100_Continue= 100,
77 ORDINAL_101_Switching_Protocols= 101,
78 ORDINAL_102_Processing= 102,
79 ORDINAL_200_OK= 200,
80 ORDINAL_201_Created= 201,
81 ORDINAL_202_Accepted= 202,
82 ORDINAL_203_Non_Authoritative_Information= 203,
83 ORDINAL_204_No_Content= 204,
84 ORDINAL_205_Reset_Content= 205,
85 ORDINAL_206_Partial_Content= 206,
86 ORDINAL_207_Multi_Status= 207,
87 ORDINAL_300_Multiple_Choices= 300,
88 ORDINAL_301_Moved_Permanently= 301,
89 ORDINAL_302_Moved_Temporarily= 302,
90 ORDINAL_302_Found= 302,
91 ORDINAL_303_See_Other= 303,
92 ORDINAL_304_Not_Modified= 304,
93 ORDINAL_305_Use_Proxy= 305,
94 ORDINAL_400_Bad_Request= 400,
95 ORDINAL_401_Unauthorized= 401,
96 ORDINAL_402_Payment_Required= 402,
97 ORDINAL_403_Forbidden= 403,
98 ORDINAL_404_Not_Found= 404,
99 ORDINAL_405_Method_Not_Allowed= 405,
100 ORDINAL_406_Not_Acceptable= 406,
101 ORDINAL_407_Proxy_Authentication_Required= 407,
102 ORDINAL_408_Request_Timeout= 408,
103 ORDINAL_409_Conflict= 409,
104 ORDINAL_410_Gone= 410,
105 ORDINAL_411_Length_Required= 411,
106 ORDINAL_412_Precondition_Failed= 412,
107 ORDINAL_413_Request_Entity_Too_Large= 413,
108 ORDINAL_414_Request_URI_Too_Large= 414,
109 ORDINAL_415_Unsupported_Media_Type= 415,
110 ORDINAL_416_Requested_Range_Not_Satisfiable= 416,
111 ORDINAL_417_Expectation_Failed= 417,
112 ORDINAL_422_Unprocessable_Entity= 422,
113 ORDINAL_423_Locked= 423,
114 ORDINAL_424_Failed_Dependency= 424,
115 ORDINAL_500_Internal_Server_Error= 500,
116 ORDINAL_501_Not_Implemented= 501,
117 ORDINAL_502_Bad_Gateway= 502,
118 ORDINAL_503_Service_Unavailable= 503,
119 ORDINAL_504_Gateway_Timeout= 504,
120 ORDINAL_505_HTTP_Version_Not_Supported= 505,
121 ORDINAL_507_Insufficient_Storage= 507,
122 ORDINAL_999_Unknown = 999;
123
124 public static final BufferCache CACHE = new BufferCache();
125
126 public static final Buffer
127 Continue_BUFFER=CACHE.add(Continue,ORDINAL_100_Continue),
128 Switching_Protocols_BUFFER=CACHE.add(Switching_Protocols,ORDINAL_101_Switching_Protocols),
129 Processing_BUFFER=CACHE.add(Processing,ORDINAL_102_Processing),
130 OK_BUFFER=CACHE.add(OK,ORDINAL_200_OK),
131 Created_BUFFER=CACHE.add(Created,ORDINAL_201_Created),
132 Accepted_BUFFER=CACHE.add(Accepted,ORDINAL_202_Accepted),
133 Non_Authoritative_Information_BUFFER=CACHE.add(Non_Authoritative_Information,ORDINAL_203_Non_Authoritative_Information),
134 No_Content_BUFFER=CACHE.add(No_Content,ORDINAL_204_No_Content),
135 Reset_Content_BUFFER=CACHE.add(Reset_Content,ORDINAL_205_Reset_Content),
136 Partial_Content_BUFFER=CACHE.add(Partial_Content,ORDINAL_206_Partial_Content),
137 Multi_Status_BUFFER=CACHE.add(Multi_Status,ORDINAL_207_Multi_Status),
138 Multiple_Choices_BUFFER=CACHE.add(Multiple_Choices,ORDINAL_300_Multiple_Choices),
139 Moved_Permanently_BUFFER=CACHE.add(Moved_Permanently,ORDINAL_301_Moved_Permanently),
140 Moved_Temporarily_BUFFER=CACHE.add(Moved_Temporarily,ORDINAL_302_Moved_Temporarily),
141 Found_BUFFER=CACHE.add(Found,ORDINAL_302_Found),
142 See_Other_BUFFER=CACHE.add(See_Other,ORDINAL_303_See_Other),
143 Not_Modified_BUFFER=CACHE.add(Not_Modified,ORDINAL_304_Not_Modified),
144 Use_Proxy_BUFFER=CACHE.add(Use_Proxy,ORDINAL_305_Use_Proxy),
145 Bad_Request_BUFFER=CACHE.add(Bad_Request,ORDINAL_400_Bad_Request),
146 Unauthorized_BUFFER=CACHE.add(Unauthorized,ORDINAL_401_Unauthorized),
147 Payment_Required_BUFFER=CACHE.add(Payment_Required,ORDINAL_402_Payment_Required),
148 Forbidden_BUFFER=CACHE.add(Forbidden,ORDINAL_403_Forbidden),
149 Not_Found_BUFFER=CACHE.add(Not_Found,ORDINAL_404_Not_Found),
150 Method_Not_Allowed_BUFFER=CACHE.add(Method_Not_Allowed,ORDINAL_405_Method_Not_Allowed),
151 Not_Acceptable_BUFFER=CACHE.add(Not_Acceptable,ORDINAL_406_Not_Acceptable),
152 Proxy_Authentication_Required_BUFFER=CACHE.add(Proxy_Authentication_Required,ORDINAL_407_Proxy_Authentication_Required),
153 Request_Timeout_BUFFER=CACHE.add(Request_Timeout,ORDINAL_408_Request_Timeout),
154 Conflict_BUFFER=CACHE.add(Conflict,ORDINAL_409_Conflict),
155 Gone_BUFFER=CACHE.add(Gone,ORDINAL_410_Gone),
156 Length_Required_BUFFER=CACHE.add(Length_Required,ORDINAL_411_Length_Required),
157 Precondition_Failed_BUFFER=CACHE.add(Precondition_Failed,ORDINAL_412_Precondition_Failed),
158 Request_Entity_Too_Large_BUFFER=CACHE.add(Request_Entity_Too_Large,ORDINAL_413_Request_Entity_Too_Large),
159 Request_URI_Too_Large_BUFFER=CACHE.add(Request_URI_Too_Large,ORDINAL_414_Request_URI_Too_Large),
160 Unsupported_Media_Type_BUFFER=CACHE.add(Unsupported_Media_Type,ORDINAL_415_Unsupported_Media_Type),
161 Requested_Range_Not_Satisfiable_BUFFER=CACHE.add(Requested_Range_Not_Satisfiable,ORDINAL_416_Requested_Range_Not_Satisfiable),
162 Expectation_Failed_BUFFER=CACHE.add(Expectation_Failed,ORDINAL_417_Expectation_Failed),
163 Unprocessable_Entity_BUFFER=CACHE.add(Unprocessable_Entity,ORDINAL_422_Unprocessable_Entity),
164 Locked_BUFFER=CACHE.add(Locked,ORDINAL_423_Locked),
165 Failed_Dependency_BUFFER=CACHE.add(Failed_Dependency,ORDINAL_424_Failed_Dependency),
166 Internal_Server_Error_BUFFER=CACHE.add(Internal_Server_Error,ORDINAL_500_Internal_Server_Error),
167 Not_Implemented_BUFFER=CACHE.add(Not_Implemented,ORDINAL_501_Not_Implemented),
168 Bad_Gateway_BUFFER=CACHE.add(Bad_Gateway,ORDINAL_502_Bad_Gateway),
169 Service_Unavailable_BUFFER=CACHE.add(Service_Unavailable,ORDINAL_503_Service_Unavailable),
170 Gateway_Timeout_BUFFER=CACHE.add(Gateway_Timeout,ORDINAL_504_Gateway_Timeout),
171 HTTP_Version_Not_Supported_BUFFER=CACHE.add(HTTP_Version_Not_Supported,ORDINAL_505_HTTP_Version_Not_Supported),
172 Insufficient_Storage_BUFFER=CACHE.add(Insufficient_Storage,ORDINAL_507_Insufficient_Storage),
173 Unknown_BUFFER=CACHE.add(Unknown,ORDINAL_999_Unknown);
174
175
176
177 private static Buffer[] __responseLine = new Buffer[600];
178 static
179 {
180 int versionLength=HttpVersions.HTTP_1_1_BUFFER.length();
181
182 for (int i=0;i<__responseLine.length;i++)
183 {
184 Buffer reason = CACHE.get(i);
185 if (reason==null)
186 continue;
187
188 byte[] bytes=new byte[versionLength+5+reason.length()+2];
189 HttpVersions.HTTP_1_1_BUFFER.peek(0,bytes, 0, versionLength);
190 bytes[versionLength+0]=' ';
191 bytes[versionLength+1]=(byte)('0'+i/100);
192 bytes[versionLength+2]=(byte)('0'+(i%100)/10);
193 bytes[versionLength+3]=(byte)('0'+(i%10));
194 bytes[versionLength+4]=' ';
195 reason.peek(0, bytes, versionLength+5, reason.length());
196 bytes[versionLength+5+reason.length()]=HttpTokens.CARRIAGE_RETURN;
197 bytes[versionLength+6+reason.length()]=HttpTokens.LINE_FEED;
198 __responseLine[i]=new ByteArrayBuffer(bytes,0,bytes.length,Buffer.IMMUTABLE);
199 }
200 }
201
202
203
204
205
206
207 public static Buffer getResponseLine(int status)
208 {
209 if (status>=__responseLine.length)
210 return null;
211 return __responseLine[status];
212 }
213 }