Skip to content

Instantly share code, notes, and snippets.

@pszals
Created October 3, 2013 21:03
The visible burden of technical debt, a.k.a. "ball of mud"
public HashMap respondToRequest() throws IOException {
readHead();
String request = getHead();
if ((getState() != null) && (getState().get("state") != null)) {
setBody((byte[]) getState().get("state"));
}
parseRequest(request);
if (headerFields.containsKey("Content-Length")) {
setBody((addSpacesAroundEqualsSigns(readBody(Integer.parseInt(headerFields.get("Content-Length").toString())))).getBytes());
}
HashMap output = new HashMap();
if (headerFields.containsKey("Authorization") || ("/logs".equals(getRoute()))){
output.put("Authorization", headerFields.get("Authorization"));
if(!(output.get("Authorization") != null && output.get("Authorization").equals("Basic YWRtaW46aHVudGVyMg=="))){
setBody(" 401\r\n\r\nAuthentication required".getBytes());
} else if(output.get("Authorization").equals("Basic YWRtaW46aHVudGVyMg==")){
setBody(" 200 OK\r\n\r\nGET /log HTTP/1.1\nPUT /these HTTP/1.1\nHEAD /requests HTTP/1.1".getBytes());
}
}
String route = getRoute();
String method = getHttpMethod();
byte[] body = getBody();
Router router = new Router();
byte[] outputMessage = router.respondToRouteRequest(method, route, body);
HashMap newState = new HashMap();
newState.put("state", body);
newState.put("requests", request);
output.put("message", outputMessage);
output.put("state", newState);
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment