asio: Use host_service_from_uri in asio-cl2.cc
This commit is contained in:
parent
fa21b95274
commit
b24bd3d8cb
|
@ -58,21 +58,34 @@ void print_header(const request &req) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
try {
|
try {
|
||||||
|
if (argc < 2) {
|
||||||
|
std::cerr << "Usage: asio-cl URI" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
boost::asio::io_service io_service;
|
boost::asio::io_service io_service;
|
||||||
|
|
||||||
|
std::string uri = argv[1];
|
||||||
|
std::string scheme, host, service;
|
||||||
|
|
||||||
|
if (host_service_from_uri(ec, scheme, host, service, uri)) {
|
||||||
|
std::cerr << "error: bad URI: " << ec.message() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
boost::asio::ssl::context tls_ctx(boost::asio::ssl::context::sslv23);
|
boost::asio::ssl::context tls_ctx(boost::asio::ssl::context::sslv23);
|
||||||
tls_ctx.set_default_verify_paths();
|
tls_ctx.set_default_verify_paths();
|
||||||
// disabled to make development easier...
|
// disabled to make development easier...
|
||||||
// tls_ctx.set_verify_mode(boost::asio::ssl::verify_peer);
|
// tls_ctx.set_verify_mode(boost::asio::ssl::verify_peer);
|
||||||
configure_tls_context(ec, tls_ctx);
|
configure_tls_context(ec, tls_ctx);
|
||||||
|
|
||||||
session sess(io_service, tls_ctx, "localhost", "3000");
|
auto sess = scheme == "https" ? session(io_service, tls_ctx, host, service)
|
||||||
sess.on_connect([&sess](tcp::resolver::iterator endpoint_it) {
|
: session(io_service, host, service);
|
||||||
|
|
||||||
|
sess.on_connect([&sess, &uri](tcp::resolver::iterator endpoint_it) {
|
||||||
std::cerr << "connected to " << (*endpoint_it).endpoint() << std::endl;
|
std::cerr << "connected to " << (*endpoint_it).endpoint() << std::endl;
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
auto req = sess.submit(ec, "GET", "https://localhost:3000/",
|
auto req = sess.submit(ec, "GET", uri, {{"cookie", {"foo=bar", true}}});
|
||||||
{{"cookie", {"foo=bar", true}}});
|
|
||||||
if (ec) {
|
if (ec) {
|
||||||
std::cerr << "error: " << ec.message() << std::endl;
|
std::cerr << "error: " << ec.message() << std::endl;
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue