From 934996c5b8f53d5ad0a84864f518891706a52c35 Mon Sep 17 00:00:00 2001 From: BennyFranciscus Date: Thu, 26 Mar 2026 07:57:41 +0000 Subject: [PATCH 1/3] fix(drogon): per-request JSON total + remove compression test --- frameworks/drogon/main.cc | 4 +--- frameworks/drogon/meta.json | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/frameworks/drogon/main.cc b/frameworks/drogon/main.cc index b90ee5ba..484466fa 100644 --- a/frameworks/drogon/main.cc +++ b/frameworks/drogon/main.cc @@ -19,7 +19,6 @@ struct DataItem { bool active; std::vector tags; Rating rating; - double total; }; static std::vector dataset; @@ -88,7 +87,6 @@ static void loadDataset() for (const auto &t : d["tags"]) item.tags.push_back(t.asString()); item.rating.score = d["rating"]["score"].asDouble(); item.rating.count = d["rating"]["count"].asInt64(); - item.total = std::round(item.price * item.quantity * 100.0) / 100.0; dataset.push_back(std::move(item)); } } @@ -204,7 +202,7 @@ class BenchmarkCtrl : public drogon::HttpController rating["score"] = d.rating.score; rating["count"] = static_cast(d.rating.count); item["rating"] = std::move(rating); - item["total"] = d.total; + item["total"] = std::round(d.price * d.quantity * 100.0) / 100.0; items.append(std::move(item)); } respJson["items"] = std::move(items); diff --git a/frameworks/drogon/meta.json b/frameworks/drogon/meta.json index e3cac843..472363fd 100644 --- a/frameworks/drogon/meta.json +++ b/frameworks/drogon/meta.json @@ -13,7 +13,6 @@ "limited-conn", "json", "upload", - "compression", "mixed", "baseline-h2", "static-h2" From 538946c2a9fc5a00b49c33c59c17d78c8329bafb Mon Sep 17 00:00:00 2001 From: BennyFranciscus <268274351+BennyFranciscus@users.noreply.github.com> Date: Thu, 26 Mar 2026 08:02:48 +0000 Subject: [PATCH 2/3] fix(drogon): use addHeader for JSON Content-Type to avoid charset suffix Drogon's setContentTypeCode(CT_APPLICATION_JSON) appends '; charset=utf-8' which fails the validate Content-Type check. Use addHeader("Content-Type", "application/json") instead. --- frameworks/drogon/main.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/drogon/main.cc b/frameworks/drogon/main.cc index 484466fa..e2fd6432 100644 --- a/frameworks/drogon/main.cc +++ b/frameworks/drogon/main.cc @@ -211,7 +211,7 @@ class BenchmarkCtrl : public drogon::HttpController wb["indentation"] = ""; auto resp = HttpResponse::newHttpResponse(); resp->setBody(Json::writeString(wb, respJson)); - resp->setContentTypeCode(CT_APPLICATION_JSON); + resp->addHeader("Content-Type", "application/json"); callback(resp); } else { auto resp = HttpResponse::newHttpResponse(); @@ -227,7 +227,7 @@ class BenchmarkCtrl : public drogon::HttpController if (!json_large_response.empty()) { auto resp = HttpResponse::newHttpResponse(); resp->setBody(json_large_response); - resp->setContentTypeCode(CT_APPLICATION_JSON); + resp->addHeader("Content-Type", "application/json"); callback(resp); } else { auto resp = HttpResponse::newHttpResponse(); @@ -278,7 +278,7 @@ class BenchmarkCtrl : public drogon::HttpController if (!db_available || !getDb() || !tl_stmt) { auto resp = HttpResponse::newHttpResponse(); resp->setBody("{\"items\":[],\"count\":0}"); - resp->setContentTypeCode(CT_APPLICATION_JSON); + resp->addHeader("Content-Type", "application/json"); callback(resp); return; } @@ -319,7 +319,7 @@ class BenchmarkCtrl : public drogon::HttpController wb["indentation"] = ""; auto resp = HttpResponse::newHttpResponse(); resp->setBody(Json::writeString(wb, respJson)); - resp->setContentTypeCode(CT_APPLICATION_JSON); + resp->addHeader("Content-Type", "application/json"); callback(resp); } From 7f33c52d0d5d89c47e994c6a9ebb3cacbf6ac558 Mon Sep 17 00:00:00 2001 From: BennyFranciscus <268274351+BennyFranciscus@users.noreply.github.com> Date: Thu, 26 Mar 2026 08:07:18 +0000 Subject: [PATCH 3/3] fix(drogon): use setContentTypeString instead of addHeader for Content-Type addHeader appends a second Content-Type header instead of replacing the default text/html one. setContentTypeString properly replaces the content type, fixing JSON and static file Content-Type validation. --- frameworks/drogon/main.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frameworks/drogon/main.cc b/frameworks/drogon/main.cc index e2fd6432..fefda789 100644 --- a/frameworks/drogon/main.cc +++ b/frameworks/drogon/main.cc @@ -211,7 +211,7 @@ class BenchmarkCtrl : public drogon::HttpController wb["indentation"] = ""; auto resp = HttpResponse::newHttpResponse(); resp->setBody(Json::writeString(wb, respJson)); - resp->addHeader("Content-Type", "application/json"); + resp->setContentTypeString("application/json"); callback(resp); } else { auto resp = HttpResponse::newHttpResponse(); @@ -227,7 +227,7 @@ class BenchmarkCtrl : public drogon::HttpController if (!json_large_response.empty()) { auto resp = HttpResponse::newHttpResponse(); resp->setBody(json_large_response); - resp->addHeader("Content-Type", "application/json"); + resp->setContentTypeString("application/json"); callback(resp); } else { auto resp = HttpResponse::newHttpResponse(); @@ -278,7 +278,7 @@ class BenchmarkCtrl : public drogon::HttpController if (!db_available || !getDb() || !tl_stmt) { auto resp = HttpResponse::newHttpResponse(); resp->setBody("{\"items\":[],\"count\":0}"); - resp->addHeader("Content-Type", "application/json"); + resp->setContentTypeString("application/json"); callback(resp); return; } @@ -319,7 +319,7 @@ class BenchmarkCtrl : public drogon::HttpController wb["indentation"] = ""; auto resp = HttpResponse::newHttpResponse(); resp->setBody(Json::writeString(wb, respJson)); - resp->addHeader("Content-Type", "application/json"); + resp->setContentTypeString("application/json"); callback(resp); } @@ -331,7 +331,7 @@ class BenchmarkCtrl : public drogon::HttpController if (it != static_files.end()) { auto resp = HttpResponse::newHttpResponse(); resp->setBody(it->second.data); - resp->addHeader("Content-Type", it->second.content_type); + resp->setContentTypeString(it->second.content_type); callback(resp); } else { auto resp = HttpResponse::newHttpResponse();