From f2bc58e778d14bc26def18a1c3f5f39cc0498c4c Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Wed, 8 Jan 2025 21:16:11 +0100 Subject: [PATCH] remove caching --- src/odr/http_server.cpp | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/odr/http_server.cpp b/src/odr/http_server.cpp index 83b78ed6..41ea51c6 100644 --- a/src/odr/http_server.cpp +++ b/src/odr/http_server.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -8,8 +7,6 @@ #include #include #include -#include -#include #include @@ -65,10 +62,8 @@ class HttpServer::Impl { HtmlConfig config; config.embed_resources = false; std::string output_path = "/tmp/" + id; - std::string cache_path = output_path + "/cache"; std::filesystem::create_directories(output_path); - std::filesystem::create_directories(cache_path); HtmlDocumentService html_service; @@ -92,14 +87,8 @@ class HttpServer::Impl { throw std::runtime_error("Unsupported file type"); } - std::string document_html_path = cache_path + "/document.html"; - HtmlResources resources; - { - std::ofstream ostream(document_html_path); - resources = html_service.write_document(ostream); - } - std::size_t document_html_size = - internal::util::file::size(document_html_path); + std::ofstream null; + HtmlResources resources = html_service.write_document(null); m_server.Get("/" + id, [id](const httplib::Request &req, httplib::Response &res) { @@ -108,25 +97,16 @@ class HttpServer::Impl { m_server.Get("/" + id + "/document.html", [=](const httplib::Request &req, httplib::Response &res) { - httplib::ContentProvider content_provider = - [document_html_path, - document_html_size](std::size_t offset, std::size_t length, - httplib::DataSink &sink) -> bool { + httplib::ContentProviderWithoutLength content_provider = + [html_service](std::size_t offset, httplib::DataSink &sink) -> bool { if (offset != 0) { throw std::runtime_error("Invalid offset: " + std::to_string(offset) + ". Must be 0."); } - if (length != document_html_size) { - throw std::runtime_error("Invalid length: " + std::to_string(length) + - ". Must be " + - std::to_string(document_html_size) + "."); - } - std::ifstream in(document_html_path); - internal::util::stream::pipe(in, sink.os); + html_service.write_document(sink.os); return false; }; - res.set_content_provider(document_html_size, "text/html", - content_provider); + res.set_content_provider("text/html", content_provider); }); for (const auto &[resource, location] : resources) {