MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / putStreamBody

Method putStreamBody

Tests/Libraries/Http/HttpAsyncClientTest.cpp:957–1041  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

955 {
956 SC_TEST_EXPECT(threadPool.create(2));
957 }
958 SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections)));
959 SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port));
960 SC_TEST_EXPECT(fileServer.init(threadPool, loop, webServerFolder));
961 struct ServerContext
962 {
963 HttpAsyncFileServer& fileServer;
964 HttpAsyncFileServer::StreamQueue<2>* streams;
965 } serverCtx = {fileServer, streams};
966 httpServer.onRequest = [this, &serverCtx](HttpConnection& connection)
967 {
968 SC_TEST_EXPECT(
969 serverCtx.fileServer.handleRequest(serverCtx.streams[connection.getConnectionID().getIndex()], connection));
970 };
971
972 ClientConnection clientStorage;
973 HttpAsyncClient client;
974 ResponseCollector collector;
975 ChunkedBodyStream bodyStream;
976 TimeoutGuard timeout;
977
978 FileSystem fs;
979 struct Context
980 {
981 ResponseCollector& collector;
982 HttpAsyncServer& httpServer;
983 FileSystem& fs;
984 } ctx = {collector, httpServer, fs};
985
986 SC_TEST_EXPECT(fs.init(webServerFolder));
987 SC_TEST_EXPECT(client.init(clientStorage));
988 String url = StringEncoding::Ascii;
989 SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/client-put-stream.txt", port));
990 SC_TEST_EXPECT(bodyStream.init(clientStorage.buffersPool, StringSpan("ChunkedBody").toCharSpan(), 3));
991
992 //! [HttpAsyncClientStreamSnippet]
993 client.onPrepareRequest = [this, &bodyStream](HttpAsyncClientRequest& request)
994 {
995 request.setBody(bodyStream, 11);
996 SC_TEST_EXPECT(request.sendHeaders());
997 };
998
999 client.onResponse = [this, &ctx](HttpAsyncClientResponse& response)
1000 {
1001 ctx.collector.attach(response,
1002 [this, &ctx](HttpAsyncClientResponse& completedResponse)
1003 {
1004 ctx.collector.detach();
1005 SC_TEST_EXPECT(completedResponse.getParser().statusCode == 201);
1006 String content;
1007 SC_TEST_EXPECT(ctx.fs.read("client-put-stream.txt", content));
1008 SC_TEST_EXPECT(content == "ChunkedBody");
1009 SC_TEST_EXPECT(ctx.fs.removeFile("client-put-stream.txt"));
1010 SC_TEST_EXPECT(ctx.httpServer.stop());
1011 });
1012 };
1013 client.onError = [this](Result result) { SC_TEST_EXPECT(result); };
1014

Callers

nothing calls this directly

Calls 15

StringSpanFunction · 0.85
mapPortMethod · 0.80
setBodyMethod · 0.80
sendHeadersMethod · 0.80
formatFunction · 0.50
viewMethod · 0.45
createMethod · 0.45
initMethod · 0.45
startMethod · 0.45
handleRequestMethod · 0.45
attachMethod · 0.45

Tested by

no test coverage detected