Added chunked transfer tests

This commit is contained in:
eidheim 2017-11-19 06:49:55 +01:00
commit c126eb76b9

View file

@ -124,6 +124,14 @@ int main() {
response->write(request->query_string); response->write(request->query_string);
}; };
server.resource["^/chunked$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
assert(request->path == "/chunked");
assert(request->content.string() == "SimpleWeb in\r\n\r\nchunks.");
response->write("6\r\nSimple\r\n3\r\nWeb\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n", {{"Transfer-Encoding", "chunked"}});
};
thread server_thread([&server]() { thread server_thread([&server]() {
// Start server // Start server
server.start(); server.start();
@ -153,7 +161,6 @@ int main() {
} }
{ {
stringstream output;
auto r = client.request("POST", "/string", "A string"); auto r = client.request("POST", "/string", "A string");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
assert(r->content.string() == "A string"); assert(r->content.string() == "A string");
@ -208,6 +215,10 @@ int main() {
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "123"); assert(output.str() == "123");
} }
{
auto r = client.request("POST", "/chunked", "6\r\nSimple\r\n3\r\nWeb\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n", {{"Transfer-Encoding", "chunked"}});
assert(r->content.string() == "SimpleWeb in\r\n\r\nchunks.");
}
} }
{ {
HttpClient client("localhost:8080"); HttpClient client("localhost:8080");