Files

27 lines
1.0 KiB
C++
Raw Permalink Normal View History

// Route: GET /formats/data (content negotiation)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
auto def = f.client->get("/formats/data");
check(contains(def.headers.get("Content-Type"), "application/json"),
"default is json");
auto xml = f.client->request(Method::Get, "/formats/data", "",
{{"Accept", "application/xml"}});
check(contains(xml.headers.get("Content-Type"), "application/xml"),
"xml negotiated");
check(contains(xml.body, "<value>42</value>"), "xml body");
auto weighted = f.client->request(
Method::Get, "/formats/data", "",
{{"Accept", "text/html;q=0.2, text/plain;q=0.9"}});
check(contains(weighted.headers.get("Content-Type"), "text/plain"),
"q weights honored");
auto nope = f.client->request(Method::Get, "/formats/data", "",
{{"Accept", "image/png"}});
check(nope.status == 406, "no match is 406");
return finish("formats/data");
}