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

Method multipartUpload

Tests/Libraries/Http/HttpAsyncClientTest.cpp:2104–2180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2102
2103 const uint16_t port = report.mapPort(26107);
2104
2105 ThreadPool threadPool;
2106 if (loop.needsThreadPoolForFileOperations())
2107 {
2108 SC_TEST_EXPECT(threadPool.create(2));
2109 }
2110 SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections)));
2111 SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port));
2112 SC_TEST_EXPECT(fileServer.init(threadPool, loop, webServerFolder));
2113 struct ServerContext
2114 {
2115 HttpAsyncFileServer& fileServer;
2116 HttpAsyncFileServer::StreamQueue<2>* streams;
2117 } serverCtx = {fileServer, streams};
2118
2119 httpServer.onRequest = [this, &serverCtx](HttpConnection& connection)
2120 {
2121 SC_TEST_EXPECT(
2122 serverCtx.fileServer.handleRequest(serverCtx.streams[connection.getConnectionID().getIndex()], connection));
2123 };
2124
2125 ClientConnection clientStorage;
2126 HttpAsyncClient client;
2127 ResponseCollector collector;
2128 TimeoutGuard timeout;
2129 FileSystem fs;
2130 struct Context
2131 {
2132 ResponseCollector& collector;
2133 HttpAsyncServer& httpServer;
2134 FileSystem& fs;
2135 } ctx = {collector, httpServer, fs};
2136
2137 SC_TEST_EXPECT(fs.init(webServerFolder));
2138 SC_TEST_EXPECT(client.init(clientStorage));
2139 String url = StringEncoding::Ascii;
2140 SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/upload", port));
2141 HttpMultipartWriter writer;
2142 SC_TEST_EXPECT(writer.setBoundary("----SCMultipartBoundary"));
2143 SC_TEST_EXPECT(writer.addFile("file", "multipart-public.txt", StringSpan("MultipartContent").toCharSpan()));
2144
2145 client.onResponse = [this, &ctx](HttpAsyncClientResponse& response)
2146 {
2147 ctx.collector.attach(response,
2148 [this, &ctx](HttpAsyncClientResponse& completedResponse)
2149 {
2150 ctx.collector.detach();
2151 SC_TEST_EXPECT(completedResponse.getParser().statusCode == 201);
2152 String content;
2153 SC_TEST_EXPECT(ctx.fs.read("multipart-public.txt", content));
2154 SC_TEST_EXPECT(content == "MultipartContent");
2155 SC_TEST_EXPECT(ctx.fs.removeFile("multipart-public.txt"));
2156 SC_TEST_EXPECT(ctx.httpServer.stop());
2157 });
2158 };
2159 client.onError = [this](Result result) { SC_TEST_EXPECT(result); };
2160
2161 SC_TEST_EXPECT(timeout.start(loop, TimeMs{2000}));

Callers

nothing calls this directly

Calls 15

StringSpanFunction · 0.85
mapPortMethod · 0.80
setBoundaryMethod · 0.80
addFileMethod · 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