common/Util.cpp | 11 +++++++++++ common/Util.hpp | 3 +++ wsd/FileServer.cpp | 11 ++++++----- wsd/LOOLWSD.cpp | 16 ++++++++-------- 4 files changed, 28 insertions(+), 13 deletions(-)
New commits: commit 8e34705fe22f7efaf44619cf40685217e2216d4b Author: DarkByt31 <avihs...@gmail.com> AuthorDate: Mon May 20 11:10:12 2019 +0530 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Mon May 20 11:53:13 2019 +0200 tdf#107038 Poco::DateTimeFormatter with Util::getHttpTimeNow() Added a function to Util to get current time in HTTP format using std::chrono. Change-Id: I9e7a732f585c1758c9348c450a01713a66f1e7b7 Reviewed-on: https://gerrit.libreoffice.org/72585 Reviewed-by: Michael Meeks <michael.me...@collabora.com> Tested-by: Michael Meeks <michael.me...@collabora.com> diff --git a/common/Util.cpp b/common/Util.cpp index 9acd82735..9185e04c4 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -728,6 +728,17 @@ namespace Util return base + Util::anonymize(filename) + ext + params; } + + std::string getHttpTimeNow() + { + char time_now[50]; + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + std::time_t now_c = std::chrono::system_clock::to_time_t(now); + std::tm now_tm = *std::gmtime(&now_c); + strftime(time_now, 50, "%a, %d %b %Y %T", &now_tm); + + return time_now; + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/common/Util.hpp b/common/Util.hpp index d493cdf74..7c967784c 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -858,6 +858,9 @@ int main(int argc, char**argv) _value = value; } }; + + //// Return current time in HTTP format. + std::string getHttpTimeNow(); } // end namespace Util #endif diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index 07ee9c4cd..1e549018c 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -46,6 +46,7 @@ #include "LOOLWSD.hpp" #include <Log.hpp> #include <Protocol.hpp> +#include <Util.hpp> using Poco::Net::HTMLForm; using Poco::Net::HTTPBasicCredentials; @@ -369,7 +370,7 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M } response.set("User-Agent", HTTP_AGENT_STRING); - response.set("Date", Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT)); + response.set("Date", Util::getHttpTimeNow()); bool gzip = request.hasToken("Accept-Encoding", "gzip"); const std::string *content; @@ -438,7 +439,7 @@ void FileServerRequestHandler::sendError(int errorCode, const Poco::Net::HTTPReq std::ostringstream oss; oss << "HTTP/1.1 " << errorCode << "\r\n" << "Content-Type: text/html charset=UTF-8\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << extraHeader << "\r\n"; @@ -659,8 +660,8 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco:: std::ostringstream oss; oss << "HTTP/1.1 200 OK\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" - << "Last-Modified: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" + << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Cache-Control:max-age=11059200\r\n" << "ETag: \"" LOOLWSD_VERSION_HASH "\"\r\n" @@ -829,7 +830,7 @@ void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request,co response.add("Referrer-Policy", "no-referrer"); response.add("X-Content-Type-Options", "nosniff"); response.set("User-Agent", HTTP_AGENT_STRING); - response.set("Date", Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT)); + response.set("Date", Util::getHttpTimeNow()); response.setContentType("text/html"); response.setChunkedTransferEncoding(false); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 79a908fb4..2bb4b37dc 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -2034,7 +2034,7 @@ private: LOG_ERR("Looks like SSL/TLS traffic on plain http port"); std::ostringstream oss; oss << "HTTP/1.1 400\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: 0\r\n" << "\r\n"; @@ -2133,7 +2133,7 @@ private: // Bad request. std::ostringstream oss; oss << "HTTP/1.1 400\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: 0\r\n" << "\r\n"; @@ -2148,7 +2148,7 @@ private: // Bad request. std::ostringstream oss; oss << "HTTP/1.1 400\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: LOOLWSD WOPI Agent\r\n" << "Content-Length: 0\r\n" << "\r\n"; @@ -2197,7 +2197,7 @@ private: std::ostringstream oss; oss << "HTTP/1.1 200 OK\r\n" - << "Last-Modified: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: " << responseString.size() << "\r\n" << "Content-Type: " << mimeType << "\r\n" @@ -2241,7 +2241,7 @@ private: // TODO: Refactor this to some common handler. std::ostringstream oss; oss << "HTTP/1.1 200 OK\r\n" - << "Last-Modified: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: " << xml.size() << "\r\n" << "Content-Type: text/xml\r\n" @@ -2263,7 +2263,7 @@ private: std::ostringstream oss; oss << "HTTP/1.1 200 OK\r\n" - << "Last-Modified: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: " << capabilities.size() << "\r\n" << "Content-Type: application/json\r\n" @@ -2285,7 +2285,7 @@ private: std::ostringstream oss; oss << "HTTP/1.1 200 OK\r\n" - << "Last-Modified: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: " << responseString.size() << "\r\n" << "Content-Type: " << mimeType << "\r\n" @@ -2345,7 +2345,7 @@ private: LOG_TRC("Conversion not allowed from this address"); std::ostringstream oss; oss << "HTTP/1.1 403\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << HTTP_AGENT_STRING << "\r\n" << "Content-Length: 0\r\n" << "\r\n"; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits