Version command line option for HTTP client examples:

The examples HTTP clients allow an optional command line switch
to choose the HTTP-version used ("1.0" or "1.1").
This commit is contained in:
Sorin Fetche
2017-10-25 10:33:24 -07:00
committed by Vinnie Falco
parent bea7d6e019
commit f4facffae3
7 changed files with 47 additions and 28 deletions
@@ -35,17 +35,19 @@ int main(int argc, char** argv)
try
{
// Check command line arguments.
if(argc != 4)
if(argc != 4 && argc != 5)
{
std::cerr <<
"Usage: http-client-sync-ssl <host> <port> <target>\n" <<
"Usage: http-client-sync-ssl <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" <<
"Example:\n" <<
" http-client-sync-ssl www.example.com 443 /\n";
" http-client-sync-ssl www.example.com 443 /\n" <<
" http-client-sync-ssl www.example.com 443 / 1.0\n";
return EXIT_FAILURE;
}
auto const host = argv[1];
auto const port = argv[2];
auto const target = argv[3];
int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
// The io_context is required for all I/O
boost::asio::io_context ioc;
@@ -70,7 +72,7 @@ int main(int argc, char** argv)
stream.handshake(ssl::stream_base::client);
// Set up an HTTP GET request message
http::request<http::string_body> req{http::verb::get, target, 11};
http::request<http::string_body> req{http::verb::get, target, version};
req.set(http::field::host, host);
req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);