From 6232d13f5321b87ddf12a1aa36b4545da45f173d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 17 Nov 2021 22:34:57 +0100 Subject: Travel3: Simple image and video display site Reads the images and videos from filesystem and builds a site in memroy. --- src/send_file.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/send_file.cc (limited to 'src/send_file.cc') diff --git a/src/send_file.cc b/src/send_file.cc new file mode 100644 index 0000000..8611b6f --- /dev/null +++ b/src/send_file.cc @@ -0,0 +1,45 @@ +#include "common.hh" + +#include "config.hh" +#include "send_file.hh" + +namespace { + +class SendFileImpl : public SendFile { +public: + bool setup(Logger*, Config* config, + std::string_view sendfile_header_name, + std::string_view sendfile_path_name) override { + header_ = config->get(std::string(sendfile_header_name), ""); + path_ = config->get(std::string(sendfile_path_name), ""); + return true; + } + + std::unique_ptr create_ok_file( + Transport* transport, + std::filesystem::path const& full_path, std::string_view relative_path, + std::string_view etag, std::optional size) override { + if (header_.empty()) { + auto resp = transport->create_ok_file(full_path); + if (!etag.empty()) + resp->add_header("ETag", std::string(etag)); + if (size.has_value()) + resp->add_header("Content-Length", std::to_string(size.value())); + return resp; + } + + auto resp = transport->create_ok_data(""); + resp->add_header(header_, path_ + std::string(relative_path)); + return resp; + } + +private: + std::string header_; + std::string path_; +}; + +} // namespace + +std::unique_ptr SendFile::create() { + return std::make_unique(); +} -- cgit v1.2.3-70-g09d2