| 863 | SC_TEST_EXPECT(httpServer.close()); |
| 864 | SC_TEST_EXPECT(loop.close()); |
| 865 | } |
| 866 | |
| 867 | void SC::HttpAsyncClientTest::requestOptions() |
| 868 | { |
| 869 | StringView webServerFolder = report.applicationRootDirectory.view(); |
| 870 | AsyncEventLoop loop; |
| 871 | SC_TEST_EXPECT(loop.create()); |
| 872 | |
| 873 | HttpAsyncFileServer::StreamQueue<2> streams[1]; |
| 874 | |
| 875 | ServerConnection connections[1]; |
| 876 | HttpAsyncServer httpServer; |
| 877 | HttpAsyncFileServer fileServer; |
| 878 | |
| 879 | const uint16_t port = report.mapPort(26118); |
| 880 | |
| 881 | ThreadPool threadPool; |
| 882 | if (loop.needsThreadPoolForFileOperations()) |
| 883 | { |
| 884 | SC_TEST_EXPECT(threadPool.create(2)); |
| 885 | } |
| 886 | SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections))); |
| 887 | SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port)); |
| 888 | SC_TEST_EXPECT(fileServer.init(threadPool, loop, webServerFolder)); |
| 889 | struct ServerContext |
| 890 | { |
| 891 | HttpAsyncFileServer& fileServer; |
| 892 | HttpAsyncFileServer::StreamQueue<2>* streams; |
| 893 | } serverCtx = {fileServer, streams}; |
| 894 | httpServer.onRequest = [this, &serverCtx](HttpConnection& connection) |
| 895 | { |
| 896 | StringSpan header; |
| 897 | SC_TEST_EXPECT(connection.request.getHeader("X-Upload-Mode", header)); |
| 898 | SC_TEST_EXPECT(header == "request-options"); |
| 899 | SC_TEST_EXPECT( |
| 900 | serverCtx.fileServer.handleRequest(serverCtx.streams[connection.getConnectionID().getIndex()], connection)); |
| 901 | }; |
| 902 | |
| 903 | ClientConnection clientStorage; |
| 904 | HttpAsyncClient client; |
| 905 | ResponseCollector collector; |
| 906 | TimeoutGuard timeout; |
| 907 | FileSystem fs; |
| 908 | |
| 909 | String url = StringEncoding::Ascii; |
| 910 | struct Context |
| 911 | { |
| 912 | ResponseCollector& collector; |
| 913 | HttpAsyncServer& httpServer; |
| 914 | FileSystem& fs; |
| 915 | } ctx = {collector, httpServer, fs}; |
| 916 | |
| 917 | SC_TEST_EXPECT(fs.init(webServerFolder)); |
| 918 | SC_TEST_EXPECT(client.init(clientStorage)); |
| 919 | SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/client-request-options.txt", port)); |
| 920 | |
| 921 | client.onResponse = [this, &ctx](HttpAsyncClientResponse& response) |
| 922 | { |
nothing calls this directly
no test coverage detected