26 lines
1.5 KiB
C++
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");
|
||
|
|
}
|