-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathhttp_proxy_client.cpp
More file actions
71 lines (53 loc) · 1.45 KB
/
Copy pathhttp_proxy_client.cpp
File metadata and controls
71 lines (53 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// socks_client.cpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2022 Jack (jack dot wgm at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/asio/io_context.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/program_options.hpp>
#include "proxy/http_proxy_client.hpp"
#include "proxy/logging.hpp"
#include "proxy/use_awaitable.hpp"
namespace net = boost::asio;
using namespace proxy;
net::awaitable<void> start_http_proxy_client()
{
auto executor = co_await net::this_coro::executor;
tcp::socket sock(executor);
tcp::endpoint server_addr(
net::ip::address::from_string("10.0.0.1"),
443);
boost::system::error_code ec;
co_await sock.async_connect(server_addr, net_awaitable[ec]);
if (ec)
{
XLOG_WARN << "client connect to server: " << ec.message();
co_return;
}
proxy::http_proxy_client_option opt;
opt.target_host = "api.ipify.org";
opt.target_port = 443;
opt.username = "jack";
opt.password = "1111";
co_await proxy::async_http_proxy_handshake(sock, opt, net_awaitable[ec]);
if (ec)
{
XLOG_WARN << "client 1' handshake to server: " << ec.message();
co_return;
}
// Using socket 'sock' do something...
co_return;
}
int main()
{
net::io_context ioc(1);
net::co_spawn(ioc, start_http_proxy_client(), net::detached);
ioc.run();
return EXIT_SUCCESS;
}