Allow to set file chunk size to the server.
This commit is contained in:
+1
-1
@@ -131,7 +131,7 @@ private:
|
||||
// the memory.
|
||||
class FileBody : public Body {
|
||||
public:
|
||||
explicit FileBody(const Path& path, std::size_t chunk_size = 1024);
|
||||
FileBody(const Path& path, std::size_t chunk_size);
|
||||
|
||||
std::size_t GetSize() const override {
|
||||
return size_;
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ bool Decompress(const std::string& input, std::string* output) {
|
||||
stream.zalloc = Z_NULL;
|
||||
stream.zfree = Z_NULL;
|
||||
|
||||
// About the windowBits paramter:
|
||||
// About the windowBits parameter:
|
||||
// (https://stackoverflow.com/a/1838702)
|
||||
// (http://www.zlib.net/manual.html)
|
||||
// windowBits can also be greater than 15 for optional gzip decoding. Add 32
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ using tcp = boost::asio::ip::tcp;
|
||||
namespace webcc {
|
||||
|
||||
Server::Server(std::uint16_t port, const Path& doc_root)
|
||||
: port_(port), doc_root_(doc_root), running_(false),
|
||||
: port_(port), doc_root_(doc_root), file_chunk_size_(1024), running_(false),
|
||||
acceptor_(io_context_), signals_(io_context_) {
|
||||
AddSignals();
|
||||
}
|
||||
@@ -352,7 +352,7 @@ bool Server::ServeStatic(ConnectionPtr connection) {
|
||||
Path p = doc_root_ / path;
|
||||
|
||||
try {
|
||||
auto body = std::make_shared<FileBody>(p);
|
||||
auto body = std::make_shared<FileBody>(p, file_chunk_size_);
|
||||
|
||||
auto response = std::make_shared<Response>(Status::kOK);
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ public:
|
||||
Server(const Server&) = delete;
|
||||
Server& operator=(const Server&) = delete;
|
||||
|
||||
void set_file_chunk_size(std::size_t file_chunk_size) {
|
||||
file_chunk_size_ = file_chunk_size;
|
||||
}
|
||||
|
||||
// Route a URL to a view.
|
||||
// The URL should start with "/". E.g., "/instances".
|
||||
bool Route(const std::string& url, ViewPtr view,
|
||||
@@ -109,6 +113,10 @@ private:
|
||||
// The directory with the static files to be served.
|
||||
Path doc_root_;
|
||||
|
||||
// The size of the chunk loaded into memory each time when serving a
|
||||
// static file.
|
||||
std::size_t file_chunk_size_;
|
||||
|
||||
// Is the server running?
|
||||
bool running_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user