105 route tests, matrix crawl, spec and README updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
35 lines
2.1 KiB
C++
35 lines
2.1 KiB
C++
// Route: GET/POST /conditional/doc (ETag, 304, Range, If-Match)
|
|
#include "support/Assert.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
using molo::example::fw::Method;
|
|
|
|
int main() {
|
|
Fixture f;
|
|
auto full = f.client->get("/conditional/doc");
|
|
std::string etag = full.headers.get("ETag");
|
|
check(full.status == 200 && !etag.empty(), "200 with etag");
|
|
check(full.headers.get("Accept-Ranges") == "bytes", "accept-ranges");
|
|
auto nm = f.client->request(Method::Get, "/conditional/doc", "", {{"If-None-Match", etag}});
|
|
check(nm.status == 304 && nm.body.empty(), "304 on matching etag");
|
|
auto weak = f.client->request(Method::Get, "/conditional/doc", "", {{"If-None-Match", "W/" + etag}});
|
|
check(weak.status == 304, "weak tag matches");
|
|
auto part = f.client->request(Method::Get, "/conditional/doc", "", {{"Range", "bytes=0-9"}});
|
|
check(part.status == 206 && part.body == full.body.substr(0, 10), "206 partial body");
|
|
check(part.headers.get("Content-Range") == "bytes 0-9/" + std::to_string(full.body.size()), "content-range");
|
|
auto suffix = f.client->request(Method::Get, "/conditional/doc", "", {{"Range", "bytes=-4"}});
|
|
check(suffix.body == full.body.substr(full.body.size() - 4), "suffix range");
|
|
auto bad = f.client->request(Method::Get, "/conditional/doc", "", {{"Range", "bytes=99999-"}});
|
|
check(bad.status == 416, "416 unsatisfiable");
|
|
auto stale = f.client->request(Method::Post, "/conditional/doc", "new text", {{"If-Match", "\"nope\""}});
|
|
check(stale.status == 412, "412 on stale If-Match");
|
|
auto ok = f.client->request(Method::Post, "/conditional/doc", "new text", {{"If-Match", etag}});
|
|
check(ok.status == 200, "update with matching If-Match");
|
|
auto after = f.client->get("/conditional/doc");
|
|
check(after.body == "new text" && after.headers.get("ETag") != etag, "side effect: new body and etag");
|
|
check(f.client->request(Method::Post, "/conditional/doc", "").status == 422, "empty body 422");
|
|
check(f.client->request(Method::Post, "/conditional/doc", std::string(5000, 'x')).status == 413, "over cap 413");
|
|
check(f.client->request(Method::Delete, "/conditional/doc").status == 405, "delete is 405");
|
|
return finish("conditional/doc");
|
|
}
|