Removed intendation monster

This commit is contained in:
ByteHamster 2019-12-02 10:37:19 +01:00
parent 26e91c0b81
commit 5789704c8f
1 changed files with 39 additions and 25 deletions

View File

@ -98,7 +98,7 @@ public class HTTPBin extends NanoHTTPD {
if (func.equalsIgnoreCase("status")) { if (func.equalsIgnoreCase("status")) {
try { try {
int code = Integer.parseInt(param); int code = Integer.parseInt(param);
return getStatus(code); return new Response(getStatus(code), MIME_HTML, "");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
e.printStackTrace(); e.printStackTrace();
return getInternalError(); return getInternalError();
@ -284,31 +284,45 @@ public class HTTPBin extends NanoHTTPD {
return response; return response;
} }
private Response getStatus(final int code) { private Response.IStatus getStatus(final int code) {
Response.IStatus status = (code == 200) ? Response.Status.OK : switch (code) {
(code == 201) ? Response.Status.CREATED : case 200:
(code == 206) ? Response.Status.PARTIAL_CONTENT : return Response.Status.OK;
(code == 301) ? Response.Status.REDIRECT : case 201:
(code == 304) ? Response.Status.NOT_MODIFIED : return Response.Status.CREATED;
(code == 400) ? Response.Status.BAD_REQUEST : case 206:
(code == 401) ? Response.Status.UNAUTHORIZED : return Response.Status.PARTIAL_CONTENT;
(code == 403) ? Response.Status.FORBIDDEN : case 301:
(code == 404) ? Response.Status.NOT_FOUND : return Response.Status.REDIRECT;
(code == 405) ? Response.Status.METHOD_NOT_ALLOWED : case 304:
(code == 416) ? Response.Status.RANGE_NOT_SATISFIABLE : return Response.Status.NOT_MODIFIED;
(code == 500) ? Response.Status.INTERNAL_ERROR : new Response.IStatus() { case 400:
@Override return Response.Status.BAD_REQUEST;
public int getRequestStatus() { case 401:
return code; return Response.Status.UNAUTHORIZED;
} case 403:
return Response.Status.FORBIDDEN;
@Override case 404:
public String getDescription() { return Response.Status.NOT_FOUND;
return "Unknown"; case 405:
} return Response.Status.METHOD_NOT_ALLOWED;
}; case 416:
return new Response(status, MIME_HTML, ""); 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) { private Response getRedirectResponse(int times) {