From 7206231ede0c07d6fc776783080c40f7998cd418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dagef=C3=B6rde?= Date: Mon, 26 Oct 2020 13:48:35 +0100 Subject: [PATCH] Rewrite FileServerRequestHandler::sendError to rely on generic sendError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Dageförde Change-Id: Ib19f95868b61fa43375bf4b19372d9f3f68691dd --- wsd/FileServer.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index d724ec2dd..894515803 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -45,6 +45,7 @@ #include #include #include +#include using Poco::Net::HTMLForm; using Poco::Net::HTTPBasicCredentials; @@ -494,24 +495,19 @@ void FileServerRequestHandler::sendError(int errorCode, const Poco::Net::HTTPReq const std::string& shortMessage, const std::string& longMessage, const std::string& extraHeader) { - Poco::URI requestUri(request.getURI()); - const std::string& path = requestUri.getPath(); - std::ostringstream oss; - oss << "HTTP/1.1 " << errorCode << "\r\n" - "Content-Type: text/html charset=UTF-8\r\n" - "Date: " << Util::getHttpTimeNow() << "\r\n" - "User-Agent: " << WOPI_AGENT_STRING << "\r\n" - << extraHeader - << "\r\n"; + std::string body; + std::string headers = extraHeader; if (!shortMessage.empty()) { + Poco::URI requestUri(request.getURI()); std::string pathSanitized; - Poco::URI::encode(path, "", pathSanitized); - oss << "

Error: " << shortMessage << "

" - "

" << longMessage << ' ' << pathSanitized << "

" + Poco::URI::encode(requestUri.getPath(), "", pathSanitized); + headers += "Content-Type: text/html charset=UTF-8\r\n"; + body = "

Error: " + shortMessage + "

" + + "

" + longMessage + ' ' + pathSanitized + "

" + "

Please contact your system administrator.

"; } - socket->send(oss.str()); + HttpHelper::sendError(errorCode, socket, body, headers); } void FileServerRequestHandler::readDirToHash(const std::string &basePath, const std::string &path, const std::string &prefix)