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 SC_TEST_EXPECT(httpServer.close());
956 SC_TEST_EXPECT(loop.close());
957}
958
959void SC::HttpAsyncClientTest::putStreamBody()
960{
961 StringView webServerFolder = report.applicationRootDirectory.view();
962 AsyncEventLoop loop;
963 SC_TEST_EXPECT(loop.create());
964
965 HttpAsyncFileServer::StreamQueue<2> streams[1];
966
967 ServerConnection connections[1];
968 HttpAsyncServer httpServer;
969 HttpAsyncFileServer fileServer;
970
971 const uint16_t port = report.mapPort(26102);
972
973 ThreadPool threadPool;
974 if (loop.needsThreadPoolForFileOperations())
975 {
976 SC_TEST_EXPECT(threadPool.create(2));
977 }
978 SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections)));
979 SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port));
980 SC_TEST_EXPECT(fileServer.init(threadPool, loop, webServerFolder));
981 struct ServerContext
982 {
983 HttpAsyncFileServer& fileServer;
984 HttpAsyncFileServer::StreamQueue<2>* streams;
985 } serverCtx = {fileServer, streams};
986 httpServer.onRequest = [this, &serverCtx](HttpConnection& connection)
987 {
988 SC_TEST_EXPECT(
989 serverCtx.fileServer.handleRequest(serverCtx.streams[connection.getConnectionID().getIndex()], connection));
990 };
991
992 ClientConnection clientStorage;
993 HttpAsyncClient client;
994 ResponseCollector collector;
995 ChunkedBodyStream bodyStream;
996 TimeoutGuard timeout;
997
998 FileSystem fs;
999 struct Context
1000 {
1001 ResponseCollector& collector;
1002 HttpAsyncServer& httpServer;
1003 FileSystem& fs;
1004 } ctx = {collector, httpServer, fs};
1005
1006 SC_TEST_EXPECT(fs.init(webServerFolder));
1007 SC_TEST_EXPECT(client.init(clientStorage));
1008 String url = StringEncoding::Ascii;
1009 SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/client-put-stream.txt", port));
1010 SC_TEST_EXPECT(bodyStream.init(clientStorage.buffersPool, StringSpan("ChunkedBody").toCharSpan(), 3));
1011
1012 //! [HttpAsyncClientStreamSnippet]
1013 client.onPrepareRequest = [this, &bodyStream](HttpAsyncClientRequest& request)
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