| 14 | #include <iostream> |
| 15 | |
| 16 | int main(int argc, char** argv) |
| 17 | { |
| 18 | // HTTP server address |
| 19 | std::string address = "127.0.0.1"; |
| 20 | if (argc > 1) |
| 21 | address = argv[1]; |
| 22 | // HTTP server port |
| 23 | int port = 8443; |
| 24 | if (argc > 2) |
| 25 | port = std::atoi(argv[2]); |
| 26 | |
| 27 | std::cout << "HTTPS server address: " << address << std::endl; |
| 28 | std::cout << "HTTPS server port: " << port << std::endl; |
| 29 | |
| 30 | std::cout << std::endl; |
| 31 | |
| 32 | // Create a new Asio service |
| 33 | auto service = std::make_shared<AsioService>(); |
| 34 | |
| 35 | // Start the Asio service |
| 36 | std::cout << "Asio service starting..."; |
| 37 | service->Start(); |
| 38 | std::cout << "Done!" << std::endl; |
| 39 | |
| 40 | // Create and prepare a new SSL client context |
| 41 | auto context = std::make_shared<CppServer::Asio::SSLContext>(asio::ssl::context::tlsv13); |
| 42 | context->set_default_verify_paths(); |
| 43 | context->set_root_certs(); |
| 44 | context->set_verify_mode(asio::ssl::verify_peer | asio::ssl::verify_fail_if_no_peer_cert); |
| 45 | context->load_verify_file("../tools/certificates/ca.pem"); |
| 46 | |
| 47 | // Create a new HTTP client |
| 48 | auto client = std::make_shared<CppServer::HTTP::HTTPSClientEx>(service, context, address, port); |
| 49 | |
| 50 | std::cout << "Press Enter to stop the client or '!' to reconnect the client..." << std::endl; |
| 51 | |
| 52 | try |
| 53 | { |
| 54 | // Perform text input |
| 55 | std::string line; |
| 56 | while (getline(std::cin, line)) |
| 57 | { |
| 58 | if (line.empty()) |
| 59 | break; |
| 60 | |
| 61 | // Reconnect the client |
| 62 | if (line == "!") |
| 63 | { |
| 64 | std::cout << "Client reconnecting..."; |
| 65 | client->IsConnected() ? client->ReconnectAsync() : client->ConnectAsync(); |
| 66 | std::cout << "Done!" << std::endl; |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | auto commands = CppCommon::StringUtils::Split(line, ' ', true); |
| 71 | if (commands.size() < 2) |
| 72 | { |
| 73 | std::cout << "HTTP method and URL must be entered!" << std::endl; |
nothing calls this directly
no test coverage detected