From 63bf9a132917d9089f3a847144d8ad6b01885777 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 16 Oct 2015 15:47:39 +0200 Subject: [PATCH] loolwsd: invert this condition, so it's possible to add other cases --- loolwsd/LOOLWSD.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 3cc510c4a..6b13c8b44 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -201,26 +201,29 @@ public: { // The user might request a file to download StringTokenizer tokens(request.getURI(), "/"); - if (tokens.count() != 4) + if (tokens.count() == 4) { - response.setStatus(HTTPResponse::HTTP_BAD_REQUEST); - response.setContentLength(0); - response.send(); - } - std::string dirPath = LOOLWSD::childRoot + "/" + tokens[1] + LOOLSession::jailDocumentURL + "/" + tokens[2]; - std::string filePath = dirPath + "/" + tokens[3]; - std::cout << Util::logPrefix() << "HTTP request for: " << filePath << std::endl; - File file(filePath); - if (file.exists()) - { - response.set("Access-Control-Allow-Origin", "*"); - response.sendFile(filePath, "application/octet-stream"); - File dir(dirPath); - dir.remove(true); + std::string dirPath = LOOLWSD::childRoot + "/" + tokens[1] + LOOLSession::jailDocumentURL + "/" + tokens[2]; + std::string filePath = dirPath + "/" + tokens[3]; + std::cout << Util::logPrefix() << "HTTP request for: " << filePath << std::endl; + File file(filePath); + if (file.exists()) + { + response.set("Access-Control-Allow-Origin", "*"); + response.sendFile(filePath, "application/octet-stream"); + File dir(dirPath); + dir.remove(true); + } + else + { + response.setStatus(HTTPResponse::HTTP_NOT_FOUND); + response.setContentLength(0); + response.send(); + } } else { - response.setStatus(HTTPResponse::HTTP_NOT_FOUND); + response.setStatus(HTTPResponse::HTTP_BAD_REQUEST); response.setContentLength(0); response.send(); }