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,6 +313,14 @@ 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);