Files
moloapp/tests/example/compress/demo_test.cpp
T
retoorandClaude Sonnet 5.5 62fdd08da8 feat(workflow): example covers security, platform, enterprise and resilience features
105 route tests, matrix crawl, spec and README updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 02:19:52 +02:00

26 lines
1.5 KiB
C++

// Route: GET /compress/demo (gzip negotiated by Accept-Encoding)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto plain = f.client->get("/compress/demo?size=1000");
check(plain.status == 200 && plain.body.size() == 1000, "identity body");
check(!plain.headers.has("Content-Encoding"), "no encoding without header");
auto gz = f.client->request(Method::Get, "/compress/demo?size=1000", "", {{"Accept-Encoding", "br, gzip;q=0.8"}});
check(gz.headers.get("Content-Encoding") == "gzip", "content-encoding gzip");
check(gz.body.size() > 2 && (unsigned char)gz.body[0] == 0x1f && (unsigned char)gz.body[1] == 0x8b, "gzip magic");
check(gz.headers.get("Vary") == "Accept-Encoding", "vary");
check(gz.headers.get("X-Original-Length") == "1000", "original length header");
auto refused = f.client->request(Method::Get, "/compress/demo?size=1000", "", {{"Accept-Encoding", "gzip;q=0"}});
check(!refused.headers.has("Content-Encoding"), "q=0 refuses gzip");
auto tiny = f.client->request(Method::Get, "/compress/demo?size=10", "", {{"Accept-Encoding", "gzip"}});
check(!tiny.headers.has("Content-Encoding"), "tiny bodies stay identity");
check(f.client->get("/compress/demo?size=x").status == 422, "bad size 422");
check(f.client->get("/compress/demo?size=9999999").status == 422, "size cap 422");
check(f.client->request(Method::Post, "/compress/demo").status == 405, "post is 405");
return finish("compress/demo");
}