diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
| commit | 6232d13f5321b87ddf12a1aa36b4545da45f173d (patch) | |
| tree | 23f3316470a14136debd9d02f9e920ca2b06f4cc /src/send_file.cc | |
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in
memroy.
Diffstat (limited to 'src/send_file.cc')
| -rw-r--r-- | src/send_file.cc | 45 |
1 files changed, 45 insertions, 0 deletions
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<Transport::Response> create_ok_file( + Transport* transport, + std::filesystem::path const& full_path, std::string_view relative_path, + std::string_view etag, std::optional<uint64_t> 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> SendFile::create() { + return std::make_unique<SendFileImpl>(); +} |
