#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(); }