Fix 404 server reply

This commit is contained in:
Dmitry Isaenko 2019-12-16 12:51:11 +03:00
parent 9be451e05e
commit 8c81b86188

View file

@ -291,6 +291,7 @@ public class NETCommunications extends Task<Void> { // todo: thows IOException?
else else
tcpPacket.add(line); // Otherwise collect data tcpPacket.add(line); // Otherwise collect data
} }
//System.out.println("<Socket Closed>");
// and reopen client sock // and reopen client sock
clientSocket.close(); clientSocket.close();
} }
@ -312,10 +313,18 @@ public class NETCommunications extends Task<Void> { // todo: thows IOException?
//private boolean handleRequest(LinkedList<String> packet, OutputStreamWriter pw){ //private boolean handleRequest(LinkedList<String> packet, OutputStreamWriter pw){
File requestedFile; File requestedFile;
String reqFileName = packet.get(0).replaceAll("(^[A-z\\s]+/)|(\\s+?.*$)", ""); String reqFileName = packet.get(0).replaceAll("(^[A-z\\s]+/)|(\\s+?.*$)", "");
if (! nspFileSizes.containsKey(reqFileName)){
currSockPW.write(NETPacket.getCode404());
currSockPW.flush();
logPrinter.print("NET: File "+reqFileName+" doesn't exists or have 0 size. Returning 404", EMsgType.FAIL);
return true;
}
long reqFileSize = nspFileSizes.get(reqFileName); long reqFileSize = nspFileSizes.get(reqFileName);
requestedFile = nspMap.get(reqFileName); requestedFile = nspMap.get(reqFileName);
if (!requestedFile.exists() || reqFileSize == 0){ // well.. tell 404 if file exists with 0 length is against standard, but saves time if (! requestedFile.exists() || reqFileSize == 0){ // well.. tell 404 if file exists with 0 length is against standard, but saves time
currSockPW.write(NETPacket.getCode404()); currSockPW.write(NETPacket.getCode404());
currSockPW.flush(); currSockPW.flush();
logPrinter.print("NET: File "+requestedFile.getName()+" doesn't exists or have 0 size. Returning 404", EMsgType.FAIL); logPrinter.print("NET: File "+requestedFile.getName()+" doesn't exists or have 0 size. Returning 404", EMsgType.FAIL);