fix(libhttp): 请求体大小限制可配置并超限返回 413 (P1-1)

This commit is contained in:
qing committed 2026-08-03 23:57:00 +08:00
1 parent b37bf255d9
commit da4957c52d
4 files changed
+36 -13

No files matched your search

+6
View File
@@ -115,6 +115,10 @@ public:
void setPrivateKeyPassword(const std::string& password);
// 请求体大小上限(字节)。默认 10MB,与 WAF 对齐;超限返回 413。
void setMaxBodySize(std::size_t bytes) { max_body_size_ = bytes; }
std::size_t getMaxBodySize() const { return max_body_size_; }
class debug {
public:
static void print_all_header_fields(const http::request<http::string_body>& req);
@@ -129,6 +133,8 @@ private:
unsigned int threads_;
std::atomic<bool> running_{false};
std::size_t max_body_size_ = 10 * 1024 * 1024; // 默认 10MB,与 WAF 对齐
bool ssl_enabled_{false};
std::string cert_file_;
std::string key_file_;
+2
View File
@@ -6,6 +6,7 @@
#include <fstream>
#include <sstream>
#include <iomanip>
#include <optional>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <boost/beast/websocket/ssl.hpp>
@@ -112,6 +113,7 @@ private:
beast::flat_buffer buffer_;
beast::flat_buffer ws_buffer_;
http::request<http::string_body> request_;
std::optional<http::request_parser<http::string_body>> parser_;
HttpServer* server_;
bool ssl_enabled_;