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 SC_TEST_EXPECT(httpServer.close());
2103 SC_TEST_EXPECT(loop.close());
2104}
2105
2106void SC::HttpAsyncClientTest::chunkedResponse()
2107{
2108 AsyncEventLoop loop;
2109 SC_TEST_EXPECT(loop.create());
2110
2111 ServerConnection connections[1];
2112 HttpAsyncServer httpServer;
2113 const uint16_t port = report.mapPort(26106);
2114 SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections)));
2115 SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port));
2116
2117 httpServer.onRequest = [this](HttpConnection& connection)
2118 {
2119 SC_TEST_EXPECT(connection.response.startResponse(200));
2120 SC_TEST_EXPECT(connection.response.setChunkedTransferEncoding());
2121 SC_TEST_EXPECT(connection.response.sendHeaders());
2122 SC_TEST_EXPECT(connection.response.getWritableStream().write("hello"));
2123 SC_TEST_EXPECT(connection.response.getWritableStream().write(" world"));
2124 SC_TEST_EXPECT(connection.response.end());
2125 };
2126
2127 ClientConnection clientStorage;
2128 HttpAsyncClient client;
2129 ResponseCollector collector;
2130 TimeoutGuard timeout;
2131 struct Context
2132 {
2133 ResponseCollector& collector;
2134 HttpAsyncServer& httpServer;
2135 } ctx = {collector, httpServer};
2136
2137 SC_TEST_EXPECT(client.init(clientStorage));
2138 String url = StringEncoding::Ascii;
2139 SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/chunked", port));
2140
2141 client.onResponse = [this, &ctx](HttpAsyncClientResponse& response)
2142 {
2143 SC_TEST_EXPECT(response.getBodyFramingKind() == HttpBodyFramingKind::Chunked);
2144 ctx.collector.attach(response,
2145 [this, &ctx](HttpAsyncClientResponse& completedResponse)
2146 {
2147 ctx.collector.detach();
2148 SC_TEST_EXPECT(completedResponse.getParser().statusCode == 200);
2149 SC_TEST_EXPECT(ctx.collector.view() == "hello world");
2150 SC_TEST_EXPECT(ctx.httpServer.stop());
2151 });
2152 };
2153 client.onError = [this](Result result) { SC_TEST_EXPECT(result); };
2154
2155 SC_TEST_EXPECT(timeout.start(loop, TimeMs{2000}));
2156 SC_TEST_EXPECT(client.get(loop, url.view()));
2157 SC_TEST_EXPECT(loop.run());
2158 SC_TEST_EXPECT(httpServer.close());
2159 SC_TEST_EXPECT(loop.close());
2160}
2161

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