Removed intendation monster
This commit is contained in:
parent
26e91c0b81
commit
5789704c8f
|
@ -98,7 +98,7 @@ public class HTTPBin extends NanoHTTPD {
|
|||
if (func.equalsIgnoreCase("status")) {
|
||||
try {
|
||||
int code = Integer.parseInt(param);
|
||||
return getStatus(code);
|
||||
return new Response(getStatus(code), MIME_HTML, "");
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
return getInternalError();
|
||||
|
@ -284,31 +284,45 @@ public class HTTPBin extends NanoHTTPD {
|
|||
return response;
|
||||
}
|
||||
|
||||
private Response getStatus(final int code) {
|
||||
Response.IStatus status = (code == 200) ? Response.Status.OK :
|
||||
(code == 201) ? Response.Status.CREATED :
|
||||
(code == 206) ? Response.Status.PARTIAL_CONTENT :
|
||||
(code == 301) ? Response.Status.REDIRECT :
|
||||
(code == 304) ? Response.Status.NOT_MODIFIED :
|
||||
(code == 400) ? Response.Status.BAD_REQUEST :
|
||||
(code == 401) ? Response.Status.UNAUTHORIZED :
|
||||
(code == 403) ? Response.Status.FORBIDDEN :
|
||||
(code == 404) ? Response.Status.NOT_FOUND :
|
||||
(code == 405) ? Response.Status.METHOD_NOT_ALLOWED :
|
||||
(code == 416) ? Response.Status.RANGE_NOT_SATISFIABLE :
|
||||
(code == 500) ? Response.Status.INTERNAL_ERROR : new Response.IStatus() {
|
||||
@Override
|
||||
public int getRequestStatus() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Unknown";
|
||||
}
|
||||
};
|
||||
return new Response(status, MIME_HTML, "");
|
||||
private Response.IStatus getStatus(final int code) {
|
||||
switch (code) {
|
||||
case 200:
|
||||
return Response.Status.OK;
|
||||
case 201:
|
||||
return Response.Status.CREATED;
|
||||
case 206:
|
||||
return Response.Status.PARTIAL_CONTENT;
|
||||
case 301:
|
||||
return Response.Status.REDIRECT;
|
||||
case 304:
|
||||
return Response.Status.NOT_MODIFIED;
|
||||
case 400:
|
||||
return Response.Status.BAD_REQUEST;
|
||||
case 401:
|
||||
return Response.Status.UNAUTHORIZED;
|
||||
case 403:
|
||||
return Response.Status.FORBIDDEN;
|
||||
case 404:
|
||||
return Response.Status.NOT_FOUND;
|
||||
case 405:
|
||||
return Response.Status.METHOD_NOT_ALLOWED;
|
||||
case 416:
|
||||
return Response.Status.RANGE_NOT_SATISFIABLE;
|
||||
case 500:
|
||||
return Response.Status.INTERNAL_ERROR;
|
||||
default:
|
||||
return new Response.IStatus() {
|
||||
@Override
|
||||
public int getRequestStatus() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Unknown";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private Response getRedirectResponse(int times) {
|
||||
|
|
Loading…
Reference in New Issue