| 212 | //------------------------------------------------------------------------------ |
| 213 | |
| 214 | int main(int argc, char** argv) |
| 215 | { |
| 216 | // Check command line arguments. |
| 217 | if(argc != 4 && argc != 5) |
| 218 | { |
| 219 | std::cerr << |
| 220 | "Usage: http-client-async-ssl <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" << |
| 221 | "Example:\n" << |
| 222 | " http-client-async-ssl www.example.com 443 /\n" << |
| 223 | " http-client-async-ssl www.example.com 443 / 1.0\n"; |
| 224 | return EXIT_FAILURE; |
| 225 | } |
| 226 | auto const host = argv[1]; |
| 227 | auto const port = argv[2]; |
| 228 | auto const target = argv[3]; |
| 229 | int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; |
| 230 | |
| 231 | // The io_context is required for all I/O |
| 232 | net::io_context ioc; |
| 233 | |
| 234 | // The SSL context is required, and holds certificates |
| 235 | ssl::context ctx{ssl::context::tlsv12_client}; |
| 236 | |
| 237 | // This holds the root certificate used for verification |
| 238 | load_root_certificates(ctx); |
| 239 | |
| 240 | // Verify the remote server's certificate |
| 241 | ctx.set_verify_mode(ssl::verify_peer); |
| 242 | |
| 243 | // Launch the asynchronous operation |
| 244 | // The session is constructed with a strand to |
| 245 | // ensure that handlers do not execute concurrently. |
| 246 | std::make_shared<session>( |
| 247 | net::make_strand(ioc), |
| 248 | ctx |
| 249 | )->run(host, port, target, version); |
| 250 | |
| 251 | // Run the I/O service. The call will return when |
| 252 | // the get operation is complete. |
| 253 | ioc.run(); |
| 254 | |
| 255 | return EXIT_SUCCESS; |
| 256 | } |
nothing calls this directly
no test coverage detected