forked from boostorg/beast
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:
committed by
Vinnie Falco
parent
bea7d6e019
commit
f4facffae3
@@ -1,6 +1,7 @@
|
||||
Version 127:
|
||||
|
||||
* Add BOOST_BEAST_NO_POSIX_FADVISE
|
||||
* Version command line option for HTTP client examples
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@@ -63,10 +63,11 @@ public:
|
||||
run(
|
||||
char const* host,
|
||||
char const* port,
|
||||
char const* target)
|
||||
char const* target,
|
||||
int version)
|
||||
{
|
||||
// Set up an HTTP GET request message
|
||||
req_.version(11);
|
||||
req_.version(version);
|
||||
req_.method(http::verb::get);
|
||||
req_.target(target);
|
||||
req_.set(http::field::host, host);
|
||||
@@ -193,17 +194,19 @@ public:
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Check command line arguments.
|
||||
if(argc != 4)
|
||||
if(argc != 4 && argc != 5)
|
||||
{
|
||||
std::cerr <<
|
||||
"Usage: http-client-async-ssl <host> <port> <target>\n" <<
|
||||
"Usage: http-client-async-ssl <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" <<
|
||||
"Example:\n" <<
|
||||
" http-client-async-ssl www.example.com 443 /\n";
|
||||
" http-client-async-ssl www.example.com 443 /\n" <<
|
||||
" http-client-async-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;
|
||||
@@ -215,7 +218,7 @@ int main(int argc, char** argv)
|
||||
load_root_certificates(ctx);
|
||||
|
||||
// Launch the asynchronous operation
|
||||
std::make_shared<session>(ioc, ctx)->run(host, port, target);
|
||||
std::make_shared<session>(ioc, ctx)->run(host, port, target, version);
|
||||
|
||||
// Run the I/O service. The call will return when
|
||||
// the get operation is complete.
|
||||
|
@@ -59,10 +59,11 @@ public:
|
||||
run(
|
||||
char const* host,
|
||||
char const* port,
|
||||
char const* target)
|
||||
char const* target,
|
||||
int version)
|
||||
{
|
||||
// Set up an HTTP GET request message
|
||||
req_.version(11);
|
||||
req_.version(version);
|
||||
req_.method(http::verb::get);
|
||||
req_.target(target);
|
||||
req_.set(http::field::host, host);
|
||||
@@ -161,23 +162,25 @@ public:
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Check command line arguments.
|
||||
if(argc != 4)
|
||||
if(argc != 4 && argc != 5)
|
||||
{
|
||||
std::cerr <<
|
||||
"Usage: http-client-async <host> <port> <target>\n" <<
|
||||
"Usage: http-client-async <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" <<
|
||||
"Example:\n" <<
|
||||
" http-client-async www.example.com 80 /\n";
|
||||
" http-client-async www.example.com 80 /\n" <<
|
||||
" http-client-async www.example.com 80 / 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;
|
||||
|
||||
// Launch the asynchronous operation
|
||||
std::make_shared<session>(ioc)->run(host, port, target);
|
||||
std::make_shared<session>(ioc)->run(host, port, target, version);
|
||||
|
||||
// Run the I/O service. The call will return when
|
||||
// the get operation is complete.
|
||||
|
@@ -46,6 +46,7 @@ do_session(
|
||||
std::string const& host,
|
||||
std::string const& port,
|
||||
std::string const& target,
|
||||
int version,
|
||||
boost::asio::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
boost::asio::yield_context yield)
|
||||
@@ -72,7 +73,7 @@ do_session(
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -114,17 +115,19 @@ do_session(
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Check command line arguments.
|
||||
if(argc != 4)
|
||||
if(argc != 4 && argc != 5)
|
||||
{
|
||||
std::cerr <<
|
||||
"Usage: http-client-coro-ssl <host> <port> <target>\n" <<
|
||||
"Usage: http-client-coro-ssl <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" <<
|
||||
"Example:\n" <<
|
||||
" http-client-coro-ssl www.example.com 443 /\n";
|
||||
" http-client-coro-ssl www.example.com 443 /\n" <<
|
||||
" http-client-coro-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;
|
||||
@@ -141,6 +144,7 @@ int main(int argc, char** argv)
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
std::string(target),
|
||||
version,
|
||||
std::ref(ioc),
|
||||
std::ref(ctx),
|
||||
std::placeholders::_1));
|
||||
|
@@ -42,6 +42,7 @@ do_session(
|
||||
std::string const& host,
|
||||
std::string const& port,
|
||||
std::string const& target,
|
||||
int version,
|
||||
boost::asio::io_context& ioc,
|
||||
boost::asio::yield_context yield)
|
||||
{
|
||||
@@ -62,7 +63,7 @@ do_session(
|
||||
return fail(ec, "connect");
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -102,17 +103,19 @@ do_session(
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Check command line arguments.
|
||||
if(argc != 4)
|
||||
if(argc != 4 && argc != 5)
|
||||
{
|
||||
std::cerr <<
|
||||
"Usage: http-client-coro <host> <port> <target>\n" <<
|
||||
"Usage: http-client-coro <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" <<
|
||||
"Example:\n" <<
|
||||
" http-client-coro www.example.com 80 /\n";
|
||||
" http-client-coro www.example.com 80 /\n" <<
|
||||
" http-client-coro www.example.com 80 / 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;
|
||||
@@ -123,6 +126,7 @@ int main(int argc, char** argv)
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
std::string(target),
|
||||
version,
|
||||
std::ref(ioc),
|
||||
std::placeholders::_1));
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -33,17 +33,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 <host> <port> <target>\n" <<
|
||||
"Usage: http-client-sync <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" <<
|
||||
"Example:\n" <<
|
||||
" http-client-sync www.example.com 80 /\n";
|
||||
" http-client-sync www.example.com 80 /\n" <<
|
||||
" http-client-sync www.example.com 80 / 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;
|
||||
@@ -59,7 +61,7 @@ int main(int argc, char** argv)
|
||||
boost::asio::connect(socket, results.begin(), results.end());
|
||||
|
||||
// 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);
|
||||
|
||||
|
Reference in New Issue
Block a user