Merge request handler to server; add FileBody for serving static files.

This commit is contained in:
Chunting Gu
2019-07-12 16:05:01 +08:00
parent 91590b8ee8
commit 8b85248a34
12 changed files with 493 additions and 470 deletions
+30
View File
@@ -5,6 +5,8 @@
#include <string>
#include <utility>
#include "boost/filesystem/fstream.hpp"
#include "webcc/common.h"
namespace webcc {
@@ -122,6 +124,34 @@ private:
std::size_t index_ = 0;
};
// -----------------------------------------------------------------------------
// File body for server to serve a file without loading the whole of it into
// the memory.
class FileBody : public Body {
public:
explicit FileBody(const Path& path, std::size_t chunk_size = 1024);
std::size_t GetSize() const override {
return size_;
}
void InitPayload() override;
Payload NextPayload(bool free_previous = false) override;
void Dump(std::ostream& os, const std::string& prefix) const override;
private:
Path path_;
std::size_t chunk_size_;
std::size_t size_; // File size in bytes
boost::filesystem::ifstream stream_;
std::string chunk_;
};
} // namespace webcc
#endif // WEBCC_BODY_H_