From d02e8d0dce5d63d2fa690d04939ab9efdc1edb86 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 4 May 2019 00:02:17 +0200 Subject: [PATCH] httpgateway: set new max payload length config value --- config.cpp | 15 +++++++++++++++ config.h | 4 ++++ gateway/httpgateway.cpp | 4 +++- gateway/httpgateway.h | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config.cpp b/config.cpp index 43d34a0..a87ea56 100644 --- a/config.cpp +++ b/config.cpp @@ -53,6 +53,19 @@ int Config::optional(const std::string &key, int defaultvalue) return defaultvalue; } +uint64_t Config::optional(const std::string &key, uint64_t defaultvalue) +{ + auto it = this->configmap.find(key); + if(it != this->configmap.end()) + { + std::string str = it->second; + return static_cast(std::stoull(str)); + } + return defaultvalue; +} + + + Config::Config(const std::map &map) { @@ -95,6 +108,8 @@ Config::Config(const std::map &map) this->templateprefix = "{qswiki:"; + this->max_payload_length = optional("max_payload_length", 10 *1024*1024); + } diff --git a/config.h b/config.h index 723bc9c..4b99f21 100644 --- a/config.h +++ b/config.h @@ -14,6 +14,7 @@ private: std::string optional(const std::string &key, std::string defaultvalue = ""); int optional(const std::string &key, int defaulvalue); + uint64_t optional(const std::string &key, uint64_t defaultvalue); public: Config(const std::map &map ); @@ -51,6 +52,9 @@ public: int session_max_lifetime; int max_pagename_length; int threadscount; + + uint64_t max_payload_length; + Permissions anon_permissions; std::string getConfig(const std::string &key) const diff --git a/gateway/httpgateway.cpp b/gateway/httpgateway.cpp index 3e7016b..4e846e6 100644 --- a/gateway/httpgateway.cpp +++ b/gateway/httpgateway.cpp @@ -33,6 +33,8 @@ HttpGateway::HttpGateway(const Config &config) throw new std::runtime_error("No http.listenport in config file"); } this->listenport = std::stoi(listenport); + + this->maxPayloadLength = config.max_payload_length; } bool HttpGateway::keepReading() @@ -91,7 +93,7 @@ httplib::Response HttpGateway::convertResponse(Response response) void HttpGateway::work(RequestWorker &worker) { httplib::Server server; - + server.set_payload_max_length(this->maxPayloadLength); auto handler = [&](const httplib::Request& req, httplib::Response& res) { Request wikiRequest = convertRequest(req); Logger::debug() << "httpgateway: received request " << wikiRequest; diff --git a/gateway/httpgateway.h b/gateway/httpgateway.h index dba65df..3f0d4e4 100644 --- a/gateway/httpgateway.h +++ b/gateway/httpgateway.h @@ -16,6 +16,7 @@ private: std::string listenaddr; int listenport; + uint64_t maxPayloadLength; public: HttpGateway(const Config &config); bool keepReading() override;