'Generic Commit'
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 1m21s
Build-Test-Publish / build (linux/arm64) (push) Successful in 2m20s
Build-Test-Publish / create-manifest (push) Successful in 17s

This commit is contained in:
Your Name
2025-06-15 16:32:29 +12:00
parent eedd39a533
commit a4d9e3ebb5
6 changed files with 56 additions and 26 deletions

View File

@@ -23,6 +23,7 @@
namespace simple_object_storage {
Server* Server::instance_ = nullptr;
std::mutex Server::instance_mutex_;
bool Server::init_db() {
@@ -145,6 +146,11 @@ bool Server::start() {
drogon::app().addListener(config_.host, config_.port);
drogon::app().setThreadNum(16);
// Set security limits (allowing for 1GB+ files for testing)
drogon::app().setClientMaxBodySize(2ULL * 1024 * 1024 * 1024); // 2GB max body size
drogon::app().setClientMaxMemoryBodySize(100 * 1024 * 1024); // 100MB max memory body (keep this lower)
drogon::app().enableGzip(true); // Enable compression
// Start the server
try {
drogon::app().run();
@@ -165,9 +171,11 @@ void Server::stop() {
}
void Server::setup_routes() {
// Configure global filters for CORS
// Configure CORS only for requests with Origin header
drogon::app().registerPostHandlingAdvice([this](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) {
add_cors_headers(req, resp);
if (!req->getHeader("Origin").empty()) {
add_cors_headers(req, resp);
}
});
// Handle OPTIONS requests for CORS preflight
@@ -175,6 +183,7 @@ void Server::setup_routes() {
std::function<void(const drogon::HttpResponsePtr &)> &&callback) {
handle_cors_preflight(req, std::move(callback));
}, {}, "OPTIONS");
}
void Server::handle_cors_preflight(const drogon::HttpRequestPtr& req, std::function<void(const drogon::HttpResponsePtr &)>&& callback) {