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

Method requestOptions

Tests/Libraries/Http/HttpAsyncClientTest.cpp:865–955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

863 {
864 SC_TEST_EXPECT(threadPool.create(2));
865 }
866 SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections)));
867 SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port));
868 SC_TEST_EXPECT(fileServer.init(threadPool, loop, webServerFolder));
869 struct ServerContext
870 {
871 HttpAsyncFileServer& fileServer;
872 HttpAsyncFileServer::StreamQueue<2>* streams;
873 } serverCtx = {fileServer, streams};
874 httpServer.onRequest = [this, &serverCtx](HttpConnection& connection)
875 {
876 StringSpan header;
877 SC_TEST_EXPECT(connection.request.getHeader("X-Upload-Mode", header));
878 SC_TEST_EXPECT(header == "request-options");
879 SC_TEST_EXPECT(
880 serverCtx.fileServer.handleRequest(serverCtx.streams[connection.getConnectionID().getIndex()], connection));
881 };
882
883 ClientConnection clientStorage;
884 HttpAsyncClient client;
885 ResponseCollector collector;
886 TimeoutGuard timeout;
887 FileSystem fs;
888
889 String url = StringEncoding::Ascii;
890 struct Context
891 {
892 ResponseCollector& collector;
893 HttpAsyncServer& httpServer;
894 FileSystem& fs;
895 } ctx = {collector, httpServer, fs};
896
897 SC_TEST_EXPECT(fs.init(webServerFolder));
898 SC_TEST_EXPECT(client.init(clientStorage));
899 SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/client-request-options.txt", port));
900
901 client.onResponse = [this, &ctx](HttpAsyncClientResponse& response)
902 {
903 ctx.collector.attach(response,
904 [this, &ctx](HttpAsyncClientResponse& completedResponse)
905 {
906 ctx.collector.detach();
907 SC_TEST_EXPECT(completedResponse.getParser().statusCode == 201);
908 String content;
909 SC_TEST_EXPECT(ctx.fs.read("client-request-options.txt", content));
910 SC_TEST_EXPECT(content == "OptionsBody");
911 SC_TEST_EXPECT(ctx.fs.removeFile("client-request-options.txt"));
912 SC_TEST_EXPECT(ctx.httpServer.stop());
913 });
914 };
915 client.onError = [this](Result result) { SC_TEST_EXPECT(result); };
916
917 HttpAsyncClient::RequestOptions invalidOptions;
918 invalidOptions.method = HttpParser::Method::HttpPUT;
919 invalidOptions.url = url.view();
920 invalidOptions.bodyMode = HttpAsyncClient::RequestOptions::BodyMode::Stream;
921 invalidOptions.bodyLength = 11;
922 SC_TEST_EXPECT(resultMessageEquals(client.sendRequest(loop, invalidOptions),

Callers

nothing calls this directly

Calls 15

mapPortMethod · 0.80
sendRequestMethod · 0.80
setBodyMethod · 0.80
resultMessageEqualsFunction · 0.70
formatFunction · 0.50
viewMethod · 0.45
createMethod · 0.45
initMethod · 0.45
startMethod · 0.45
getHeaderMethod · 0.45
handleRequestMethod · 0.45

Tested by

no test coverage detected