Skip to content

Commit 9f2d2d4

Browse files
committed
Add reason phrase to HttpResponse with default values
1 parent d26bb89 commit 9f2d2d4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

sources/net.sf.j2s.java.core/src/javajs/http/HttpClient.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,64 @@ public interface HttpResponse extends Closeable {
179179
*/
180180
public int getStatusCode();
181181

182+
/**
183+
* Get the reason phrase for the response code.
184+
* Implementations should use the reason returned by the server.
185+
* Default implementation uses phrases defined by RFC 2616 and RFC 4918
186+
*
187+
* @return status line reason phrase
188+
*/
189+
public default String getReasonPhrase() {
190+
switch (getStatusCode()) {
191+
case 100: return "Continue";
192+
case 101: return "Switching Protocols";
193+
case 200: return "OK";
194+
case 201: return "Created";
195+
case 202: return "Accepted";
196+
case 203: return "Non-Authoritative Information";
197+
case 204: return "No Content";
198+
case 205: return "Reset Content";
199+
case 206: return "Partial Content";
200+
case 207: return "Multi-status";
201+
case 300: return "Multiple Choices";
202+
case 301: return "Moved Permanently";
203+
case 302: return "Found";
204+
case 303: return "See Other";
205+
case 304: return "Not Modified";
206+
case 305: return "Use Proxy";
207+
case 307: return "Temporary Redirect";
208+
case 400: return "Bad Request";
209+
case 401: return "Unauthorized";
210+
case 402: return "Payment Required";
211+
case 403: return "Forbidden";
212+
case 404: return "Not Found";
213+
case 405: return "Method Not Allowed";
214+
case 406: return "Not Acceptable";
215+
case 407: return "Proxy Authentication Required";
216+
case 408: return "Request Timeout";
217+
case 409: return "Conflict";
218+
case 410: return "Gone";
219+
case 411: return "Length Required";
220+
case 412: return "Precondition Failed";
221+
case 413: return "Request Entity Too Large";
222+
case 414: return "Request-URI Too Long";
223+
case 415: return "Unsupported Media Type";
224+
case 416: return "Requested Range Not Satisfiable";
225+
case 417: return "Expectation Failed";
226+
case 422: return "Unprocessable Entity";
227+
case 423: return "Locked";
228+
case 424: return "Failed Dependency";
229+
case 500: return "Internal Server Error";
230+
case 501: return "Not Implemented";
231+
case 502: return "Bad Gateway";
232+
case 503: return "Service Unavailable";
233+
case 504: return "Gateway Timeout";
234+
case 505: return "HTTP Version Not Supported";
235+
case 507: return "Insufficient Storage";
236+
default: return "";
237+
}
238+
}
239+
182240
/**
183241
* Get the response headers, combining same-name headers with commas, preserving
184242
* order, as per RFC 2616

0 commit comments

Comments
 (0)